2025-01-27 23:07:10 +01:00
|
|
|
-- description: Renaming various complicated field names to something simpler
|
|
|
|
|
|
|
|
PRAGMA foreign_keys = ON;
|
2025-01-27 18:39:35 +01:00
|
|
|
|
|
|
|
BEGIN TRANSACTION;
|
|
|
|
|
2025-01-27 23:07:10 +01:00
|
|
|
-- Rename sets table
|
|
|
|
ALTER TABLE "bricktracker_sets" RENAME TO "bricktracker_sets_old";
|
|
|
|
|
|
|
|
-- Re-Create a Bricktable set table with the simplified name
|
|
|
|
CREATE TABLE "bricktracker_sets" (
|
|
|
|
"id" TEXT NOT NULL,
|
|
|
|
"set" TEXT NOT NULL,
|
|
|
|
PRIMARY KEY("id"),
|
|
|
|
FOREIGN KEY("set") REFERENCES "rebrickable_sets"("set")
|
2025-01-27 18:39:35 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- Insert existing sets into the new table
|
2025-01-27 23:07:10 +01:00
|
|
|
INSERT INTO "bricktracker_sets" (
|
|
|
|
"id",
|
|
|
|
"set"
|
2025-01-27 18:39:35 +01:00
|
|
|
)
|
|
|
|
SELECT
|
2025-01-27 23:07:10 +01:00
|
|
|
"bricktracker_sets_old"."id",
|
|
|
|
"bricktracker_sets_old"."rebrickable_set"
|
|
|
|
FROM "bricktracker_sets_old";
|
|
|
|
|
|
|
|
-- Rename status table
|
|
|
|
ALTER TABLE "bricktracker_set_statuses" RENAME TO "bricktracker_set_statuses_old";
|
|
|
|
|
|
|
|
-- Re-create a table for the status of each checkbox
|
|
|
|
CREATE TABLE "bricktracker_set_statuses" (
|
|
|
|
"id" TEXT NOT NULL,
|
|
|
|
{% if structure %}{{ structure }},{% endif %}
|
|
|
|
PRIMARY KEY("id"),
|
|
|
|
FOREIGN KEY("id") REFERENCES "bricktracker_sets"("id")
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Insert existing status into the new table
|
|
|
|
INSERT INTO "bricktracker_set_statuses" (
|
|
|
|
{% if targets %}{{ targets }},{% endif %}
|
|
|
|
"id"
|
|
|
|
)
|
|
|
|
SELECT
|
|
|
|
{% if sources %}{{ sources }},{% endif %}
|
|
|
|
"bricktracker_set_statuses_old"."bricktracker_set_id"
|
|
|
|
FROM "bricktracker_set_statuses_old";
|
|
|
|
|
|
|
|
-- Delete the original tables
|
|
|
|
DROP TABLE "bricktracker_set_statuses_old";
|
|
|
|
DROP TABLE "bricktracker_sets_old";
|
2025-01-27 18:39:35 +01:00
|
|
|
|
|
|
|
COMMIT;
|