Skip to content

Commit c681bf3

Browse files
committed
updated local test script and fixtures for cockroach based on v21.1
1 parent a1d9566 commit c681bf3

File tree

36 files changed

+1005
-629
lines changed

36 files changed

+1005
-629
lines changed

Makefile

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,23 @@
1-
TAGS ?= "sqlite"
2-
GO_BIN ?= "go"
1+
TAGS ?= sqlite
2+
GO_BIN ?= go
33

44
install:
55
$(GO_BIN) install -tags ${TAGS} -v .
6-
make tidy
76

87
tidy:
9-
ifeq ($(GO111MODULE),on)
108
$(GO_BIN) mod tidy
11-
else
12-
echo skipping go mod tidy
13-
endif
14-
15-
deps:
16-
$(GO_BIN) get -tags ${TAGS} -t ./...
17-
make tidy
189

1910
build:
2011
$(GO_BIN) build -v .
21-
make tidy
2212

2313
test:
24-
./test.sh
25-
make tidy
26-
27-
ci-deps:
28-
$(GO_BIN) get -tags ${TAGS} -t ./...
29-
30-
ci-test:
31-
$(GO_BIN) test -tags ${TAGS} -race ./...
14+
./test.sh -cover -v
3215

3316
lint:
3417
go get github.com/golangci/golangci-lint/cmd/golangci-lint
3518
golangci-lint run --enable-all
36-
make tidy
3719

3820
update:
39-
ifeq ($(GO111MODULE),on)
4021
rm go.*
41-
$(GO_BIN) mod init
42-
$(GO_BIN) mod tidy
43-
else
44-
$(GO_BIN) get -u -tags ${TAGS}
45-
endif
46-
make test
47-
make install
48-
make tidy
49-
50-
release-test:
51-
$(GO_BIN) test -tags ${TAGS} -race ./...
52-
make tidy
53-
54-
release:
55-
$(GO_BIN) get github.com/gobuffalo/release
56-
make tidy
57-
release -y -f version.go --skip-packr
58-
make tidy
22+
$(GO_BIN) mod init github.com/gobuffalo/fizz
23+
$(GO_BIN) mod tidy --go=1.16

README.md

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
# Fizz
22

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

66
A Common DSL for Migrating Databases
77

8-
## Create a Table
8+
9+
## Supported Database Engines
10+
11+
Fizz supports minimum supported version of all supported database engines.
12+
Currently, the following database engines are officially supported. (Since
13+
Fizz is used with the migration feature of Pop, supported databases and the
14+
versions are correlated with Pop.)
15+
16+
* PostgreSQL 10
17+
* MySQL 5.7 / MariaDB 10.3
18+
* SQLite3 3.22
19+
* CockroachDB v21.1
20+
* MSSQL 2017 (not fully supported)
21+
22+
23+
## Usage
24+
25+
### Create a Table
926

1027
``` javascript
1128
create_table("users") {
@@ -28,7 +45,7 @@ create_table("todos") {
2845
}
2946
```
3047

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

3350
```javascript
3451
create_table("users") {
@@ -75,89 +92,89 @@ create_table("user_privileges") {
7592

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

78-
## Drop a Table
95+
### Drop a Table
7996

8097
``` javascript
8198
drop_table("table_name")
8299
```
83100

84-
## Rename a Table
101+
### Rename a Table
85102

86103
``` javascript
87104
rename_table("old_table_name", "new_table_name")
88105
```
89106

90-
## Add a Column
107+
### Add a Column
91108

92109
``` javascript
93110
add_column("table_name", "column_name", "string", {})
94111
```
95112

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

98-
## Alter a column
115+
### Alter a column
99116

100117
``` javascript
101118
change_column("table_name", "column_name", "string", {})
102119
```
103120

104-
## Rename a Column
121+
### Rename a Column
105122

106123
``` javascript
107124
rename_column("table_name", "old_column_name", "new_column_name")
108125
```
109126

110-
## Drop a Column
127+
### Drop a Column
111128

112129
``` javascript
113130
drop_column("table_name", "column_name")
114131
```
115132

116-
## Add an Index
133+
### Add an Index
117134

118135
#### Supported Options:
119136

120137
* `name` - This defaults to `table_name_column_name_idx`
121138
* `unique`
122139

123-
### Simple Index:
140+
#### Simple Index:
124141

125142
``` javascript
126143
add_index("table_name", "column_name", {})
127144
```
128145

129-
### Multi-Column Index:
146+
#### Multi-Column Index:
130147

131148
``` javascript
132149
add_index("table_name", ["column_1", "column_2"], {})
133150
```
134151

135-
### Unique Index:
152+
#### Unique Index:
136153

137154
``` javascript
138155
add_index("table_name", "column_name", {"unique": true})
139156
```
140157

141-
### Index Names:
158+
#### Index Names:
142159

143160
``` javascript
144161
add_index("table_name", "column_name", {}) # name => table_name_column_name_idx
145162
add_index("table_name", "column_name", {"name": "custom_index_name"})
146163
```
147164

148-
## Rename an Index
165+
### Rename an Index
149166

150167
``` javascript
151168
rename_index("table_name", "old_index_name", "new_index_name")
152169
```
153170

154-
## Drop an Index
171+
### Drop an Index
155172

156173
``` javascript
157174
drop_index("table_name", "index_name")
158175
```
159176

160-
## Add a Foreign Key
177+
### Add a Foreign Key
161178

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

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

179-
## Drop a Foreign Key
196+
### Drop a Foreign Key
180197

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

189206

190-
## Raw SQL
207+
### Raw SQL
191208

192209
``` javascript
193210
sql("select * from users;")
194211
```
195212

196-
## Execute an External Command
213+
### Execute an External Command
197214

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

docker-compose.yml

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,53 @@ services:
88
- MYSQL_DATABASE=pop_test
99
- MYSQL_USER=pop
1010
- MYSQL_PASSWORD=pop
11-
volumes:
12-
- ./sql:/docker-entrypoint-initdb.d
11+
#volumes:
12+
#- ./_vol/mysql:/docker-entrypoint-initdb.d
1313
ports:
14-
- "3306:3306"
14+
- "3307:3306"
15+
healthcheck:
16+
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
17+
interval: 5s
18+
timeout: 5s
19+
retries: 10
20+
start_period: 3s
21+
1522
postgres:
16-
image: postgres:9.6
23+
image: postgres:10
1724
environment:
1825
- POSTGRES_DB=pop_test
1926
- POSTGRES_PASSWORD=postgres
2027
ports:
21-
- "5432:5432"
22-
volumes:
23-
- ./sqldumps:/docker-entrypoint-initdb.d
28+
- "5433:5432"
29+
#volumes:
30+
#- ./_vol/postgres:/docker-entrypoint-initdb.d
31+
healthcheck:
32+
test: ["CMD", "pg_isready"]
33+
interval: 5s
34+
timeout: 5s
35+
retries: 10
36+
start_period: 3s
37+
2438
cockroach:
25-
image: cockroachdb/cockroach:v19.2.10
39+
image: cockroachdb/cockroach:latest-v21.1
2640
ports:
27-
- "26257:26257"
28-
- "8080:8080"
29-
volumes:
30-
- "./cockroach-data/roach1:/cockroach/cockroach-data"
31-
command: start --insecure
32-
mssqlserver:
33-
image: "microsoft/mssql-server-linux"
34-
environment:
35-
- SA_PASSWORD=Tt@12345678
36-
- MSSQLSERVER_PASSWORD=Tt@12345678
37-
- ACCEPT_EULA=Y
38-
ports:
39-
- "1433:1433"
41+
- "26258:26257"
42+
- "8081:8080"
43+
#volumes:
44+
#- ./_vol/cockroach:/cockroach/cockroach-data
45+
command: start-single-node --insecure
46+
healthcheck:
47+
test: ["CMD", "curl", "http://localhost:8080/health"]
48+
interval: 5s
49+
timeout: 5s
50+
retries: 10
51+
start_period: 3s
52+
53+
# mssqlserver:
54+
# image: "microsoft/mssql-server-linux"
55+
# environment:
56+
# - SA_PASSWORD=Tt@12345678
57+
# - MSSQLSERVER_PASSWORD=Tt@12345678
58+
# - ACCEPT_EULA=Y
59+
# ports:
60+
# - "1433:1433"

test.sh

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
11
#!/bin/bash
2+
23
set -e
3-
clear
44

5-
verbose=""
5+
# NOTE: See also docker-compose.yml and database.yml to configure database
6+
# properties.
7+
export MYSQL_PORT=3307
8+
export COCKROACH_PORT=26258
69

7-
echo $@
10+
COMPOSE=docker-compose
11+
which docker-compose || COMPOSE="docker compose"
812

9-
if [[ "$@" == "-v" ]]
10-
then
11-
verbose="-v"
12-
fi
13+
args=$@
1314

1415
function cleanup {
1516
echo "Cleanup resources..."
16-
docker-compose down
17-
find ./sql_scripts/sqlite -name *.sqlite* -delete || true
17+
$COMPOSE down
18+
docker volume prune -f
19+
find ./tmp -name *.sqlite* -delete || true
1820
}
1921
# defer cleanup, so it will be executed even after premature exit
2022
trap cleanup EXIT
2123

22-
docker-compose up -d
23-
sleep 10 # Ensure mysql is online
24-
25-
go install -tags sqlite github.com/gobuffalo/pop/v6/soda@latest
26-
2724
function test {
28-
echo "!!! Testing $1"
2925
export SODA_DIALECT=$1
26+
27+
echo ""
28+
echo "######################################################################"
29+
echo "### Running unit tests for $SODA_DIALECT"
3030
soda drop -e $SODA_DIALECT
3131
soda create -e $SODA_DIALECT
3232
soda migrate -e $SODA_DIALECT -p ./testdata/migrations
33-
go test -tags sqlite -count=1 $verbose $(go list ./... | grep -v /vendor/)
34-
echo "!!! Resetting $1"
33+
go test -tags sqlite -count=1 $args ./...
34+
35+
echo ""
36+
echo "######################################################################"
37+
echo "### Running e2e tests for $1"
3538
soda drop -e $SODA_DIALECT
3639
soda create -e $SODA_DIALECT
37-
echo "!!! Running e2e tests $1"
38-
cd testdata/e2e; go test -tags sqlite,e2e -count=1 $verbose ./...; cd ..
40+
pushd testdata/e2e; go test -tags sqlite,e2e -count=1 $args ./...; popd
3941
}
4042

43+
44+
$COMPOSE up --wait
45+
46+
go install -tags sqlite github.com/gobuffalo/pop/v6/soda@latest
47+
4148
test "sqlite"
4249
test "postgres"
4350
test "cockroach"
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
CREATE TABLE schema_migration (
1+
-- # 1 column
2+
-- # row 1
3+
-- ## 269
4+
CREATE TABLE public.schema_migration (
25
version VARCHAR(14) NOT NULL,
6+
rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
7+
CONSTRAINT "primary" PRIMARY KEY (rowid ASC),
38
UNIQUE INDEX schema_migration_version_idx (version ASC),
49
FAMILY "primary" (version, rowid)
510
);
11+
-- # 1 row

0 commit comments

Comments
 (0)