-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
134 additions
and
15 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,6 @@ | ||
-- 1_1.sql initialises an empty database. | ||
|
||
CREATE TABLE IF NOT EXISTS test ( | ||
id BIGSERIAL PRIMARY KEY, | ||
time TIMESTAMP WITH TIME ZONE | ||
); |
6 changes: 6 additions & 0 deletions
6
internal/db/testdata/invalidmigrations/002_add_invalid_table.up.sql
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 @@ | ||
-- 1_2.sql is a migration that adds an invalid table. | ||
|
||
CREATE TABLE IF NOT EXISTS invalid ( | ||
id BIGSERIAL PRIMARY KEY, | ||
time INVALIDTYPE | ||
); |
6 changes: 6 additions & 0 deletions
6
internal/db/testdata/invalidmigrations/003_add_another_table.up.sql
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 @@ | ||
-- 1_3.sql is a migration that adds an controller table. | ||
|
||
CREATE TABLE IF NOT EXISTS controller ( | ||
id BIGSERIAL PRIMARY KEY, | ||
name TEXT | ||
); |
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 @@ | ||
-- 1_1.sql initialises an empty database. | ||
|
||
CREATE TABLE IF NOT EXISTS test ( | ||
id BIGSERIAL PRIMARY KEY, | ||
time TIMESTAMP WITH TIME ZONE | ||
); |
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,5 @@ | ||
-- 1_2.sql is a migration that adds a valid table. | ||
|
||
CREATE TABLE IF NOT EXISTS valid ( | ||
id BIGSERIAL PRIMARY KEY | ||
); |
6 changes: 6 additions & 0 deletions
6
internal/db/testdata/validmigrations/003_add_another_table.up.sql
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 @@ | ||
-- 1_3.sql is a migration that adds an controller table. | ||
|
||
CREATE TABLE IF NOT EXISTS controller ( | ||
id BIGSERIAL PRIMARY KEY, | ||
name TEXT | ||
); |
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 @@ | ||
# Notes | ||
|
||
Migrations are applied using [golang-migrate](https://github.com/golang-migrate/migrate). | ||
Previously migrations were applied using a home-grown solution and a `versions` table. | ||
The switch to golang-migrate was done to simplify our code. | ||
|
||
To cater for existing deployments, we handle the case that the `versions` table still | ||
exists and "force" the new migration tool to align with the old. | ||
|
||
No "down" migrations are used currently. We aim to work with the philosophy that application | ||
changes should be done such that we deprecate the use of any tables/columns, deploy these changes | ||
and then later create a migration to make permanent changes to the DB. Ideally always moving | ||
migrations forwards and never backwards. | ||
|
||
By default, golang-migrate does not run migrations in a transactions. | ||
**But**, the [postgres](https://github.com/golang-migrate/migrate/blob/master/database/postgres/README.md#multi-statement-mode) driver has slightly unique behavior - "running multiple SQL statements in one Exec executes them inside a transaction". | ||
So each migration file is in fact run in a transaction when using PostgreSQL. To be more explicit, | ||
one can wrap the migration file with BEGIN/COMMIT instructions. |