-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from schemahero/set-defualt
Set column default value
- Loading branch information
Showing
53 changed files
with
739 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mysql:8.0 | ||
|
||
ENV MYSQL_USER=schemahero | ||
ENV MYSQL_PASSWORD=password | ||
ENV MYSQL_DATABASE=schemahero | ||
ENV MYSQL_RANDOM_ROOT_PASSWORD=1 | ||
|
||
## Insert fixtures | ||
COPY ./fixtures.sql /docker-entrypoint-initdb.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
SHELL := /bin/bash | ||
TEST_NAME := mysql-column-set-default | ||
DATABASE_IMAGE_NAME := schemahero/database | ||
DATABASE_CONTAINER_NAME := schemahero-database | ||
DRIVER := mysql | ||
URI := schemahero:password@tcp($(DATABASE_CONTAINER_NAME):3306)/schemahero?tls=false | ||
SPEC_FILE := /specs/users.yaml | ||
|
||
.PHONY: run | ||
run: | ||
@rm -rf ./out | ||
@mkdir ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
@-docker rm -f $(TEST_NAME) > /dev/null 2>&1 ||: | ||
@-docker network rm $(TEST_NAME) > /dev/null 2>&1 ||: | ||
docker network create $(TEST_NAME) | ||
|
||
# Fixtures | ||
docker pull mysql:8.0 | ||
docker build -t $(DATABASE_IMAGE_NAME) . | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
docker run --network $(TEST_NAME) --rm -d --name $(DATABASE_CONTAINER_NAME) $(DATABASE_IMAGE_NAME) | ||
while ! docker exec -it $(DATABASE_CONTAINER_NAME) mysqladmin ping -h$(DATABASE_CONTAINER_NAME) --silent; do sleep 1; done | ||
|
||
# Test | ||
docker tag $(IMAGE) schemahero/schemahero:test | ||
docker run -v `pwd`/specs:/specs \ | ||
--network $(TEST_NAME) \ | ||
--name $(TEST_NAME) \ | ||
--rm \ | ||
schemahero/schemahero:test \ | ||
apply \ | ||
--driver $(DRIVER) \ | ||
--uri "$(URI)" \ | ||
--spec-file $(SPEC_FILE) | ||
|
||
# Verify | ||
docker run \ | ||
--rm \ | ||
--network $(TEST_NAME) \ | ||
-v `pwd`/out:/out \ | ||
-e uid=$${UID} \ | ||
schemahero/schemahero:test \ | ||
generate \ | ||
--dbname schemahero \ | ||
--namespace default \ | ||
--driver $(DRIVER) \ | ||
--output-dir /out \ | ||
--uri "$(URI)" | ||
@echo Verifying results for $(TEST_NAME) | ||
diff expect out | ||
|
||
# Cleanup | ||
@-sleep 5 | ||
rm -rf ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) | ||
@-docker network rm $(TEST_NAME) |
2 changes: 2 additions & 0 deletions
2
integration/tests/mysql/column-set-default/expect/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- ./users.yaml |
30 changes: 30 additions & 0 deletions
30
integration/tests/mysql/column-set-default/expect/users.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apiVersion: schemas.schemahero.io/v1alpha2 | ||
kind: Table | ||
metadata: | ||
name: users | ||
spec: | ||
database: schemahero | ||
name: users | ||
schema: | ||
mysql: | ||
primaryKey: | ||
- id | ||
columns: | ||
- name: id | ||
type: int | ||
constraints: | ||
notNull: true | ||
- name: email | ||
type: varchar (255) | ||
constraints: | ||
notNull: true | ||
- name: account_type | ||
type: varchar (10) | ||
constraints: | ||
notNull: true | ||
default: trial | ||
- name: num_seats | ||
type: int | ||
constraints: | ||
notNull: true | ||
default: "5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
create table users ( | ||
id integer primary key not null, | ||
email varchar(255) not null, | ||
account_type varchar(10), | ||
num_seats integer | ||
); |
23 changes: 23 additions & 0 deletions
23
integration/tests/mysql/column-set-default/specs/users.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
database: schemahero | ||
name: users | ||
requires: [] | ||
schema: | ||
mysql: | ||
primaryKey: [id] | ||
columns: | ||
- name: id | ||
type: integer | ||
- name: email | ||
type: varchar(255) | ||
constraints: | ||
notNull: true | ||
- name: account_type | ||
type: varchar(10) | ||
constraints: | ||
notNull: true | ||
default: trial | ||
- name: num_seats | ||
type: integer | ||
constraints: | ||
notNull: true | ||
default: "5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mysql:8.0 | ||
|
||
ENV MYSQL_USER=schemahero | ||
ENV MYSQL_PASSWORD=password | ||
ENV MYSQL_DATABASE=schemahero | ||
ENV MYSQL_RANDOM_ROOT_PASSWORD=1 | ||
|
||
## Insert fixtures | ||
COPY ./fixtures.sql /docker-entrypoint-initdb.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
SHELL := /bin/bash | ||
TEST_NAME := mysql-column-unset-default | ||
DATABASE_IMAGE_NAME := schemahero/database | ||
DATABASE_CONTAINER_NAME := schemahero-database | ||
DRIVER := mysql | ||
URI := schemahero:password@tcp($(DATABASE_CONTAINER_NAME):3306)/schemahero?tls=false | ||
SPEC_FILE := /specs/users.yaml | ||
|
||
.PHONY: run | ||
run: | ||
@rm -rf ./out | ||
@mkdir ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
@-docker rm -f $(TEST_NAME) > /dev/null 2>&1 ||: | ||
@-docker network rm $(TEST_NAME) > /dev/null 2>&1 ||: | ||
docker network create $(TEST_NAME) | ||
|
||
# Fixtures | ||
docker pull mysql:8.0 | ||
docker build -t $(DATABASE_IMAGE_NAME) . | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
docker run --network $(TEST_NAME) --rm -d --name $(DATABASE_CONTAINER_NAME) $(DATABASE_IMAGE_NAME) | ||
while ! docker exec -it $(DATABASE_CONTAINER_NAME) mysqladmin ping -h$(DATABASE_CONTAINER_NAME) --silent; do sleep 1; done | ||
|
||
# Test | ||
docker tag $(IMAGE) schemahero/schemahero:test | ||
docker run -v `pwd`/specs:/specs \ | ||
--network $(TEST_NAME) \ | ||
--name $(TEST_NAME) \ | ||
--rm \ | ||
schemahero/schemahero:test \ | ||
apply \ | ||
--driver $(DRIVER) \ | ||
--uri "$(URI)" \ | ||
--spec-file $(SPEC_FILE) | ||
|
||
# Verify | ||
docker run \ | ||
--rm \ | ||
--network $(TEST_NAME) \ | ||
-v `pwd`/out:/out \ | ||
-e uid=$${UID} \ | ||
schemahero/schemahero:test \ | ||
generate \ | ||
--dbname schemahero \ | ||
--namespace default \ | ||
--driver $(DRIVER) \ | ||
--output-dir /out \ | ||
--uri "$(URI)" | ||
@echo Verifying results for $(TEST_NAME) | ||
diff expect out | ||
|
||
# Cleanup | ||
@-sleep 5 | ||
rm -rf ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) | ||
@-docker network rm $(TEST_NAME) |
2 changes: 2 additions & 0 deletions
2
integration/tests/mysql/column-unset-default/expect/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- ./users.yaml |
28 changes: 28 additions & 0 deletions
28
integration/tests/mysql/column-unset-default/expect/users.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apiVersion: schemas.schemahero.io/v1alpha2 | ||
kind: Table | ||
metadata: | ||
name: users | ||
spec: | ||
database: schemahero | ||
name: users | ||
schema: | ||
mysql: | ||
primaryKey: | ||
- id | ||
columns: | ||
- name: id | ||
type: int | ||
constraints: | ||
notNull: true | ||
- name: email | ||
type: varchar (255) | ||
constraints: | ||
notNull: true | ||
- name: account_type | ||
type: varchar (10) | ||
constraints: | ||
notNull: false | ||
- name: num_seats | ||
type: int | ||
constraints: | ||
notNull: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
create table users ( | ||
id integer primary key not null, | ||
email varchar(255) not null, | ||
account_type varchar(10) not null default 'trial', | ||
num_seats integer not null default 5 | ||
); |
17 changes: 17 additions & 0 deletions
17
integration/tests/mysql/column-unset-default/specs/users.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
database: schemahero | ||
name: users | ||
requires: [] | ||
schema: | ||
mysql: | ||
primaryKey: [id] | ||
columns: | ||
- name: id | ||
type: integer | ||
- name: email | ||
type: varchar(255) | ||
constraints: | ||
notNull: true | ||
- name: account_type | ||
type: varchar(10) | ||
- name: num_seats | ||
type: integer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ spec: | |
type: varchar (10) | ||
constraints: | ||
notNull: true | ||
default: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
create table users ( | ||
id integer primary key not null, | ||
email varchar(255) not null, | ||
phone varchar(10) not null | ||
phone varchar(10) not null default '' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,4 @@ schema: | |
type: varchar(10) | ||
constraints: | ||
notNull: true | ||
default: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,3 @@ create table projects ( | |
name varchar(255) not null, | ||
icon_uri varchar(255) not null | ||
); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM postgres:10.7 | ||
|
||
ENV POSTGRES_USER=schemahero | ||
ENV POSTGRES_PASSWORD=password | ||
ENV POSTGRES_DB=schemahero | ||
|
||
## Insert fixtures | ||
COPY ./fixtures.sql /docker-entrypoint-initdb.d/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
SHELL := /bin/bash | ||
TEST_NAME := postgres-column-set-default | ||
DATABASE_IMAGE_NAME := schemahero/database | ||
DATABASE_CONTAINER_NAME := schemahero-database | ||
DRIVER := postgres | ||
URI := postgres://schemahero:password@$(DATABASE_CONTAINER_NAME):5432/schemahero?sslmode=disable | ||
SPEC_FILE := /specs/users.yaml | ||
|
||
.PHONY: run | ||
run: | ||
@rm -rf ./out | ||
@mkdir ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
@-docker rm -f $(TEST_NAME) > /dev/null 2>&1 ||: | ||
@-docker network rm $(TEST_NAME) > /dev/null 2>&1 ||: | ||
docker network create $(TEST_NAME) | ||
|
||
# Fixtures | ||
docker pull postgres:10.7 | ||
docker build -t $(DATABASE_IMAGE_NAME) . | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) > /dev/null 2>&1 ||: | ||
docker run --network $(TEST_NAME) --rm -d --name $(DATABASE_CONTAINER_NAME) $(DATABASE_IMAGE_NAME) | ||
while ! docker exec -it $(DATABASE_CONTAINER_NAME) pg_isready -h$(DATABASE_CONTAINER_NAME) --quiet; do sleep 1; done | ||
|
||
# Test | ||
docker tag $(IMAGE) schemahero/schemahero:test | ||
docker run -v `pwd`/specs:/specs \ | ||
--network $(TEST_NAME) \ | ||
--name $(TEST_NAME) \ | ||
--rm \ | ||
schemahero/schemahero:test \ | ||
apply \ | ||
--driver $(DRIVER) \ | ||
--uri "$(URI)" \ | ||
--spec-file $(SPEC_FILE) | ||
|
||
# Verify | ||
docker run \ | ||
--rm \ | ||
--network $(TEST_NAME) \ | ||
-v `pwd`/out:/out \ | ||
-e uid=$${UID} \ | ||
schemahero/schemahero:test \ | ||
generate \ | ||
--dbname schemahero \ | ||
--namespace default \ | ||
--driver $(DRIVER) \ | ||
--output-dir /out \ | ||
--uri "$(URI)" | ||
@echo Verifying results for $(TEST_NAME) | ||
diff expect out | ||
|
||
# Cleanup | ||
@-sleep 5 | ||
rm -rf ./out | ||
@-docker rm -f $(DATABASE_CONTAINER_NAME) | ||
@-docker network rm $(TEST_NAME) |
2 changes: 2 additions & 0 deletions
2
integration/tests/postgres/column-set-default/expect/kustomization.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
resources: | ||
- ./users.yaml |
Oops, something went wrong.