Skip to content

Commit 72a67de

Browse files
PhilippMDoernerPhilippMDoerner
PhilippMDoerner
authored andcommitted
Add migrations
1 parent 2846173 commit 72a67de

3 files changed

+37
-0
lines changed

flyway.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
flyway.url=jdbc:sqlite:./db.sqlite3
2+
flyway.locations=filesystem:./sql
3+
flyway.user=sa
4+
flyway.password=

sql/V1.6__Cascade_Delete_Markers.sql

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- Create a new table map_marker2 with the Cascade Delete
12
CREATE TABLE "map_marker2" (
23
"id" integer PRIMARY KEY AUTOINCREMENT,
34
"icon" varchar(200),
@@ -13,6 +14,8 @@ CREATE TABLE "map_marker2" (
1314
FOREIGN KEY ("location_id") REFERENCES "wikientries_location" ("id") DEFERRABLE INITIALLY DEFERRED,
1415
FOREIGN KEY ("map_id") REFERENCES "map_map" ("id") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
1516
);
17+
18+
-- Copy the data from the old map_marker table to the new map_marker2 table
1619
INSERT INTO map_marker2 (icon, longitude, latitude, map_id, location_id, type_id, creation_datetime, update_datetime, color)
1720
SELECT
1821
icon,
@@ -26,5 +29,8 @@ SELECT
2629
color
2730
FROM map_marker;
2831

32+
-- Drop the old map_marker table
2933
DROP TABLE map_marker;
34+
35+
-- Rename the new map_marker2 table to map_marker
3036
ALTER TABLE map_marker2 RENAME TO map_marker;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-- Create a temporary table to hold the data from the quoteconnection table
2+
CREATE TABLE "wikientries_quoteconnection_temp" (
3+
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
4+
"character_id" integer NOT NULL REFERENCES "wikientries_character" ("id") DEFERRABLE INITIALLY DEFERRED,
5+
"quote_id" integer NOT NULL
6+
);
7+
8+
-- Copy the data from the quoteconnection table to the temporary table
9+
INSERT INTO "wikientries_quoteconnection_temp" ("id", "character_id", "quote_id")
10+
SELECT "id", "character_id", "quote_id" FROM "wikientries_quoteconnection";
11+
12+
-- Drop the old quoteconnection table
13+
DROP TABLE "wikientries_quoteconnection";
14+
15+
-- Create the new quoteconnection table with the foreign key constraint
16+
CREATE TABLE "wikientries_quoteconnection" (
17+
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
18+
"character_id" integer NOT NULL REFERENCES "wikientries_character" ("id") DEFERRABLE INITIALLY DEFERRED,
19+
"quote_id" integer NOT NULL REFERENCES "wikientries_quote" ("id") ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
20+
);
21+
22+
-- Copy the data from the temporary table to the new quoteconnection table
23+
INSERT INTO "wikientries_quoteconnection" ("id", "character_id", "quote_id")
24+
SELECT "id", "character_id", "quote_id" FROM "wikientries_quoteconnection_temp";
25+
26+
-- Drop the temporary table
27+
DROP TABLE "wikientries_quoteconnection_temp";

0 commit comments

Comments
 (0)