-
Notifications
You must be signed in to change notification settings - Fork 16
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 #106 from curiosum-dev/102-develop-make-migrations…
…-rollbackable Make migrations rollbackable
- Loading branch information
Showing
12 changed files
with
101 additions
and
43 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 was deleted.
Oops, something went wrong.
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,30 @@ | ||
defmodule Kanta.Migrations.Postgresql.V04 do | ||
@moduledoc """ | ||
Kanta PostgreSQL V4 Migrations | ||
""" | ||
|
||
use Ecto.Migration | ||
|
||
@doc """ | ||
Ensure that the `default` context exists. | ||
""" | ||
def up(_opts) do | ||
# Insert the 'default' context if it doesn't exist | ||
execute(""" | ||
INSERT INTO kanta_contexts (name, inserted_at, updated_at) | ||
VALUES ('default', NOW(), NOW()) | ||
ON CONFLICT (name) DO NOTHING; | ||
""") | ||
|
||
flush() | ||
|
||
# Update messages with null context_id to use the 'default' context's ID | ||
execute(""" | ||
UPDATE kanta_messages | ||
SET context_id = (SELECT id FROM kanta_contexts WHERE name = 'default') | ||
WHERE context_id IS NULL; | ||
""") | ||
end | ||
|
||
def down(_opts), do: nil | ||
end |
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,35 @@ | ||
defmodule Kanta.Migrations.SQLite3.V03 do | ||
@moduledoc """ | ||
Kanta SQLite3 V3 Migrations | ||
""" | ||
|
||
use Ecto.Migration | ||
|
||
@doc """ | ||
Ensure that the `default` context exists. | ||
""" | ||
def up(_opts) do | ||
# Insert the 'default' context if it doesn't exist | ||
execute(""" | ||
INSERT INTO kanta_contexts (name, inserted_at, updated_at) | ||
VALUES ('default', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) | ||
ON CONFLICT (name) DO NOTHING; | ||
""") | ||
|
||
flush() | ||
|
||
# Update messages with null context_id to use the 'default' context's ID | ||
execute(""" | ||
UPDATE kanta_messages | ||
SET context_id = ( | ||
SELECT id | ||
FROM kanta_contexts | ||
WHERE name = 'default' | ||
LIMIT 1 | ||
) | ||
WHERE context_id IS NULL; | ||
""") | ||
end | ||
|
||
def down(_opts), do: nil | ||
end |