-
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.
Add some example migrations to reproduce the problem.
- Loading branch information
1 parent
2c6c7bb
commit d14ff7d
Showing
4 changed files
with
76 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"name": "01_create_tables", | ||
"operations": [ | ||
{ | ||
"create_table": { | ||
"name": "employees", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "serial", | ||
"pk": true | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "varchar(255)" | ||
}, | ||
{ | ||
"name": "department_id", | ||
"type": "integer", | ||
"nullable": true | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"create_table": { | ||
"name": "departments", | ||
"columns": [ | ||
{ | ||
"name": "id", | ||
"type": "serial", | ||
"pk": true | ||
}, | ||
{ | ||
"name": "name", | ||
"type": "varchar(255)" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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,18 @@ | ||
{ | ||
"name": "02_add_fk", | ||
"operations": [ | ||
{ | ||
"alter_column": { | ||
"table": "employees", | ||
"column": "department_id", | ||
"references": { | ||
"name": "fk_employees_department_id", | ||
"table": "departments", | ||
"column": "id" | ||
}, | ||
"up": "''", | ||
"down": "''" | ||
} | ||
} | ||
] | ||
} |
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,14 @@ | ||
{ | ||
"name": "03_set_fk_not_null", | ||
"operations": [ | ||
{ | ||
"alter_column": { | ||
"table": "employees", | ||
"column": "department_id", | ||
"nullable": false, | ||
"up": "(SELECT CASE WHEN department_id IS NULL THEN 1 ELSE department_id END)", | ||
"down": "" | ||
} | ||
} | ||
] | ||
} |
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 @@ | ||
insert into departments (name) values ('engineering'), ('marketing'); | ||
insert into employees (name, department_id) values ('alice', 1), ('bob', 2); |