Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated module dependencies, github action for testing, and etc. #139

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
translators/cockroach* @mclark4386
# Default owner
* @gobuffalo/pop-managers
* @gobuffalo/core-managers @gobuffalo/database
7 changes: 6 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
day: "friday"
labels:
- "dependency"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
labels:
- "process"
35 changes: 20 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
ports:
- 3307:3306
# needed because the mysql container does not provide a healthcheck
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 10s --health-timeout 5s --health-retries 5
options: --health-cmd "mysqladmin ping -h localhost" --health-interval 5s --health-timeout 5s --health-retries 10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short interval --> fast pass


steps:
- uses: actions/checkout@v3
Expand All @@ -51,9 +51,9 @@ jobs:
run: |
go test -v -tags sqlite -race ./...

- name: Reset soda and run e2e
- name: Reset database and run e2e
env:
SODA_DIALECT: "sqlite"
SODA_DIALECT: "mysql"
run: |
soda drop -e $SODA_DIALECT -p ./testdata/migrations
soda create -e $SODA_DIALECT -p ./testdata/migrations
Expand All @@ -71,15 +71,15 @@ jobs:

services:
postgres:
image: postgres:14
image: postgres:10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the minimum supported version of PostgreSQL is 10 currently.

env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
- 5433:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10

steps:
- uses: actions/checkout@v3
Expand All @@ -105,9 +105,9 @@ jobs:
run: |
go test -v -tags sqlite -race ./...

- name: Reset soda and run e2e
- name: Reset database and run e2e
env:
SODA_DIALECT: "sqlite"
SODA_DIALECT: "postgres"
run: |
soda drop -e $SODA_DIALECT -p ./testdata/migrations
soda create -e $SODA_DIALECT -p ./testdata/migrations
Expand All @@ -134,14 +134,17 @@ jobs:
run: |
mkdir -p crdb
pushd crdb
wget -qO- https://binaries.cockroachdb.com/cockroach-v2.1.0.linux-amd64.tgz | tar -xz
sudo cp -i cockroach-v2.1.0.linux-amd64/cockroach /usr/local/bin/
cockroach start --insecure --background
wget -qO- https://binaries.cockroachdb.com/cockroach-v21.1.19.linux-amd64.tgz | tar -xz
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The currentl minimum supported version of Cockroach DB is v21.1.

mv cockroach-v21.1.19.linux-amd64/* .
ln -s `pwd`/cockroach /usr/local/bin/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recent version has two .so libraries so just make keep them in a single directory. However, the CLI should be in the PATH so just link it.

cockroach version
./cockroach start-single-node --insecure --background
popd

- name: Install and run soda
env:
SODA_DIALECT: "cockroach"
COCKROACH_PORT: 26257
run: |
go install -tags sqlite github.com/gobuffalo/pop/v6/soda@latest
soda drop -e $SODA_DIALECT -p ./testdata/migrations
Expand All @@ -151,12 +154,14 @@ jobs:
- name: Test
env:
SODA_DIALECT: "cockroach"
COCKROACH_PORT: 26257
run: |
go test -v -tags sqlite -race ./...

- name: Reset soda and run e2e
- name: Reset database and run e2e
env:
SODA_DIALECT: "sqlite"
SODA_DIALECT: "cockroach"
COCKROACH_PORT: 26257
run: |
soda drop -e $SODA_DIALECT -p ./testdata/migrations
soda create -e $SODA_DIALECT -p ./testdata/migrations
Expand Down Expand Up @@ -213,7 +218,7 @@ jobs:
go test -v -tags sqlite ./...
shell: bash

- name: Reset soda and run e2e
- name: Reset database and run e2e
if: ${{ matrix.os != 'windows-latest' }}
env:
SODA_DIALECT: "sqlite"
Expand All @@ -224,7 +229,7 @@ jobs:
go test -v -tags sqlite,e2e -race ./...
shell: bash

- name: Reset soda and run e2e without race detection
- name: Reset database and run e2e without race detection
if: ${{ matrix.os == 'windows-latest' }}
env:
SODA_DIALECT: "sqlite"
Expand Down
45 changes: 5 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,58 +1,23 @@
TAGS ?= "sqlite"
GO_BIN ?= "go"
TAGS ?= sqlite
GO_BIN ?= go

install:
$(GO_BIN) install -tags ${TAGS} -v .
make tidy

tidy:
ifeq ($(GO111MODULE),on)
$(GO_BIN) mod tidy
else
echo skipping go mod tidy
endif

deps:
$(GO_BIN) get -tags ${TAGS} -t ./...
make tidy

build:
$(GO_BIN) build -v .
make tidy

test:
./test.sh
make tidy

ci-deps:
$(GO_BIN) get -tags ${TAGS} -t ./...

ci-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
./test.sh -cover -v

lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint
golangci-lint run --enable-all
make tidy

update:
ifeq ($(GO111MODULE),on)
rm go.*
$(GO_BIN) mod init
$(GO_BIN) mod tidy
else
$(GO_BIN) get -u -tags ${TAGS}
endif
make test
make install
make tidy

release-test:
$(GO_BIN) test -tags ${TAGS} -race ./...
make tidy

release:
$(GO_BIN) get github.com/gobuffalo/release
make tidy
release -y -f version.go --skip-packr
make tidy
$(GO_BIN) mod init github.com/gobuffalo/fizz
$(GO_BIN) mod tidy --go=1.16
57 changes: 37 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# Fizz

[![Actions Status](https://github.com/gobuffalo/fizz/workflows/Tests/badge.svg)](https://github.com/gobuffalo/fizz/actions)
[![GoDoc](https://godoc.org/github.com/gobuffalo/fizz?status.svg)](https://godoc.org/github.com/gobuffalo/fizz)
[![Go Reference](https://pkg.go.dev/badge/github.com/gobuffalo/fizz.svg)](https://pkg.go.dev/github.com/gobuffalo/fizz)

A Common DSL for Migrating Databases

## Create a Table

## Supported Database Engines
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This supported version and support policy are important. The basic policy should be "supporting the minimum supported version of each engine"


Fizz supports minimum supported version of all supported database engines.
Currently, the following database engines are officially supported. (Since
Fizz is used with the migration feature of Pop, supported databases and the
versions are correlated with Pop.)

* PostgreSQL 10
* MySQL 5.7 / MariaDB 10.3
* SQLite3 3.22
* CockroachDB v21.1
* MSSQL 2017 (not fully supported)


## Usage

### Create a Table

``` javascript
create_table("users") {
Expand All @@ -28,7 +45,7 @@ create_table("todos") {
}
```

The `id` column don't have to be an integer. For instance, your can use an [`UUID`](https://github.com/gobuffalo/uuid) type instead:
The `id` column don't have to be an integer. For instance, your can use an UUID type instead:

```javascript
create_table("users") {
Expand Down Expand Up @@ -75,89 +92,89 @@ create_table("user_privileges") {

Please note that the `t.PrimaryKey` statement MUST be after the columns definitions.

## Drop a Table
### Drop a Table

``` javascript
drop_table("table_name")
```

## Rename a Table
### Rename a Table

``` javascript
rename_table("old_table_name", "new_table_name")
```

## Add a Column
### Add a Column

``` javascript
add_column("table_name", "column_name", "string", {})
```

See [above](#column-info) for more details on column types and options.

## Alter a column
### Alter a column

``` javascript
change_column("table_name", "column_name", "string", {})
```

## Rename a Column
### Rename a Column

``` javascript
rename_column("table_name", "old_column_name", "new_column_name")
```

## Drop a Column
### Drop a Column

``` javascript
drop_column("table_name", "column_name")
```

## Add an Index
### Add an Index

#### Supported Options:

* `name` - This defaults to `table_name_column_name_idx`
* `unique`

### Simple Index:
#### Simple Index:

``` javascript
add_index("table_name", "column_name", {})
```

### Multi-Column Index:
#### Multi-Column Index:

``` javascript
add_index("table_name", ["column_1", "column_2"], {})
```

### Unique Index:
#### Unique Index:

``` javascript
add_index("table_name", "column_name", {"unique": true})
```

### Index Names:
#### Index Names:

``` javascript
add_index("table_name", "column_name", {}) # name => table_name_column_name_idx
add_index("table_name", "column_name", {"name": "custom_index_name"})
```

## Rename an Index
### Rename an Index

``` javascript
rename_index("table_name", "old_index_name", "new_index_name")
```

## Drop an Index
### Drop an Index

``` javascript
drop_index("table_name", "index_name")
```

## Add a Foreign Key
### Add a Foreign Key

```javascript
add_foreign_key("table_name", "field", {"ref_table_name": ["ref_column"]}, {
Expand All @@ -176,7 +193,7 @@ add_foreign_key("table_name", "field", {"ref_table_name": ["ref_column"]}, {

**Note:** `on_update` and `on_delete` are not supported on CockroachDB yet.

## Drop a Foreign Key
### Drop a Foreign Key

```javascript
drop_foreign_key("table_name", "fk_name", {"if_exists": true})
Expand All @@ -187,13 +204,13 @@ drop_foreign_key("table_name", "fk_name", {"if_exists": true})
* `if_exists` - Adds `IF EXISTS` condition


## Raw SQL
### Raw SQL

``` javascript
sql("select * from users;")
```

## Execute an External Command
### Execute an External Command

Sometimes during a migration you need to shell out to an external command.

Expand Down
10 changes: 5 additions & 5 deletions database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ mysql:
dialect: "mysql"
database: "pop_test"
host: {{ envOr "MYSQL_HOST" "127.0.0.1" }}
port: {{ envOr "MYSQL_PORT" "3306" }}
port: {{ envOr "MYSQL_PORT" "3307" }}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to prevent port conflict with locally installed versions. it will make it developers easy to test Fizz without having to worry about their existing local version.

user: {{ envOr "MYSQL_USER" "root" }}
password: {{ envOr "MYSQL_PASSWORD" "root" }}

postgres:
url: "postgres://postgres:postgres@localhost:5432/pop_test?sslmode=disable"
url: "postgres://postgres:postgres@localhost:5433/pop_test?sslmode=disable"
pool: 25

cockroach:
# url: "cockroach://[email protected]:26257/pop_test?application_name=cockroach&sslmode=disable"
# url: "cockroach://[email protected]:26258/pop_test?application_name=cockroach&sslmode=disable"
dialect: "cockroach"
database: "pop_test"
host: {{ envOr "COCKROACH_HOST" "127.0.0.1" }}
port: {{ envOr "COCKROACH_PORT" "26257" }}
port: {{ envOr "COCKROACH_PORT" "26258" }}
user: {{ envOr "COCKROACH_USER" "root" }}
password: {{ envOr "COCKROACH_PASSWORD" "" }}
options:
Expand All @@ -31,7 +31,7 @@ sqlserver:

sqlite:
dialect: "sqlite3"
database: "./sql_scripts/sqlite/test.sqlite"
database: "./tmp/test.sqlite"
options:
mode: rwc

Loading