-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test/e2e: add schema-mysql test (#202)
- Loading branch information
Showing
7 changed files
with
263 additions
and
50 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
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,227 @@ | ||
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp | ||
kubectl apply -f database.yaml | ||
kubectl create secret generic mysql-credentials --from-literal=url=${DB_URL} | ||
# Wait for the DB ready before creating the schema | ||
kubectl wait --for=condition=ready --timeout=60s -l app=mysql pods | ||
|
||
# Sync the $WORK directory to the controller pod | ||
kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/ | ||
env DEV_URL=mysql://root:pass@mysql.${NAMESPACE}:3307/myapp | ||
# Create a table not described in the desired schema but excluded from it. | ||
atlas schema apply --auto-approve --dev-url=${DEV_URL} --url=${DB_URL} --to=file:///tmp/${NAMESPACE}/ignore.sql | ||
|
||
# Create the configmap to store the schema.sql | ||
kubectl create configmap mysql-schema --from-file=./schema-v1 --dry-run=client -o yaml | ||
stdin stdout | ||
kubectl apply -f - | ||
|
||
# Create the schema | ||
kubectl apply -f schema.yaml | ||
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mysql | ||
|
||
# Inspect the schema to ensure it's correct | ||
atlas schema inspect -u ${DB_URL} | ||
cmp stdout schema-v1.hcl | ||
|
||
# Update the configmap with the new schema | ||
kubectl create configmap mysql-schema --from-file=./schema-v2 --dry-run=client -o yaml | ||
stdin stdout | ||
kubectl apply -f - | ||
|
||
# Ensure the controller is aware of the change | ||
kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/atlasschema-mysql | ||
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mysql | ||
|
||
# Inspect the schema to ensure it's correct | ||
atlas schema inspect -u ${DB_URL} | ||
cmp stdout schema-v2.hcl | ||
-- schema-v1.hcl -- | ||
table "ignore_me" { | ||
schema = schema.myapp | ||
column "c" { | ||
null = true | ||
type = int | ||
} | ||
} | ||
table "users" { | ||
schema = schema.myapp | ||
column "id" { | ||
null = false | ||
type = int | ||
auto_increment = true | ||
} | ||
column "name" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
column "email" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
column "short_bio" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
primary_key { | ||
columns = [column.id] | ||
} | ||
index "email" { | ||
unique = true | ||
columns = [column.email] | ||
} | ||
} | ||
schema "myapp" { | ||
charset = "utf8mb4" | ||
collate = "utf8mb4_0900_ai_ci" | ||
} | ||
-- schema-v2.hcl -- | ||
table "ignore_me" { | ||
schema = schema.myapp | ||
column "c" { | ||
null = true | ||
type = int | ||
} | ||
} | ||
table "users" { | ||
schema = schema.myapp | ||
column "id" { | ||
null = false | ||
type = int | ||
auto_increment = true | ||
} | ||
column "name" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
column "email" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
column "short_bio" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
column "phone" { | ||
null = false | ||
type = varchar(255) | ||
} | ||
primary_key { | ||
columns = [column.id] | ||
} | ||
index "email" { | ||
unique = true | ||
columns = [column.email] | ||
} | ||
} | ||
schema "myapp" { | ||
charset = "utf8mb4" | ||
collate = "utf8mb4_0900_ai_ci" | ||
} | ||
-- schema-v1/schema.sql -- | ||
create table users ( | ||
id int not null auto_increment, | ||
name varchar(255) not null, | ||
email varchar(255) unique not null, | ||
short_bio varchar(255) not null, | ||
primary key (id) | ||
); | ||
-- schema-v2/schema.sql -- | ||
create table users ( | ||
id int not null auto_increment, | ||
name varchar(255) not null, | ||
email varchar(255) unique not null, | ||
short_bio varchar(255) not null, | ||
phone varchar(255) not null, | ||
primary key (id) | ||
); | ||
-- ignore.sql -- | ||
create table myapp.ignore_me (c int); | ||
-- schema.yaml -- | ||
apiVersion: db.atlasgo.io/v1alpha1 | ||
kind: AtlasSchema | ||
metadata: | ||
name: atlasschema-mysql | ||
spec: | ||
urlFrom: | ||
secretKeyRef: | ||
key: url | ||
name: mysql-credentials | ||
policy: | ||
lint: | ||
destructive: | ||
error: true | ||
diff: | ||
skip: | ||
drop_column: true | ||
schema: | ||
configMapKeyRef: | ||
key: schema.sql | ||
name: mysql-schema | ||
exclude: | ||
- ignore_me | ||
-- database.yaml -- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: mysql | ||
spec: | ||
selector: | ||
app: mysql | ||
ports: | ||
- name: mysql | ||
port: 3306 | ||
targetPort: mysql | ||
- name: mysql-dev | ||
port: 3307 | ||
targetPort: mysql-dev | ||
type: ClusterIP | ||
--- | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: mysql | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: mysql | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: mysql | ||
spec: | ||
containers: | ||
- name: mysql | ||
image: mysql:latest | ||
env: | ||
- name: MYSQL_ROOT_PASSWORD | ||
value: pass | ||
- name: MYSQL_DATABASE | ||
value: myapp | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
readinessProbe: | ||
initialDelaySeconds: 5 | ||
periodSeconds: 2 | ||
timeoutSeconds: 1 | ||
exec: | ||
command: [ "mysql", "-ppass", "-h", "127.0.0.1", "-e", "SELECT 1" ] | ||
- name: mysql-dev | ||
image: mysql:latest | ||
env: | ||
- name: MYSQL_ROOT_PASSWORD | ||
value: pass | ||
- name: MYSQL_DATABASE | ||
value: myapp | ||
- name: MYSQL_TCP_PORT | ||
value: "3307" | ||
ports: | ||
- containerPort: 3307 | ||
name: mysql-dev | ||
readinessProbe: | ||
initialDelaySeconds: 5 | ||
periodSeconds: 2 | ||
timeoutSeconds: 1 | ||
exec: | ||
command: [ "mysql", "-ppass", "-h", "127.0.0.1", "-e", "SELECT 1" ] |
File renamed without changes.
File renamed without changes.
File renamed without changes.