2025-01-28 10:49:16 +01:00
|
|
|
-- description: Renaming various complicated field names to something simpler, and add a bunch of extra fields for later
|
2025-01-27 23:07:10 +01:00
|
|
|
|
|
|
|
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";
|
|
|
|
|
2025-01-28 10:49:16 +01:00
|
|
|
-- Create a Bricktracker set storage table for later
|
|
|
|
CREATE TABLE "bricktracker_set_storages" (
|
|
|
|
"name" TEXT NOT NULL,
|
2025-01-28 21:10:14 +01:00
|
|
|
PRIMARY KEY("name")
|
|
|
|
);
|
|
|
|
|
|
|
|
-- Create a Bricktracker set storage table for later
|
|
|
|
CREATE TABLE "bricktracker_set_purchase_locations" (
|
|
|
|
"name" TEXT NOT NULL,
|
|
|
|
PRIMARY KEY("name")
|
2025-01-28 10:49:16 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- Re-Create a Bricktracker set table with the simplified name
|
2025-01-27 23:07:10 +01:00
|
|
|
CREATE TABLE "bricktracker_sets" (
|
|
|
|
"id" TEXT NOT NULL,
|
|
|
|
"set" TEXT NOT NULL,
|
2025-01-28 10:49:16 +01:00
|
|
|
"description" TEXT,
|
|
|
|
"theme" TEXT, -- Custom theme name
|
|
|
|
"storage" TEXT, -- Storage bin location
|
|
|
|
"purchase_date" INTEGER, -- Purchase data
|
2025-01-28 21:10:14 +01:00
|
|
|
"purchase_location" TEXT, -- Purchase location
|
2025-01-28 10:49:16 +01:00
|
|
|
"purchase_price" REAL, -- Purchase price
|
2025-01-27 23:07:10 +01:00
|
|
|
PRIMARY KEY("id"),
|
2025-01-28 10:49:16 +01:00
|
|
|
FOREIGN KEY("set") REFERENCES "rebrickable_sets"("set"),
|
2025-01-28 21:10:14 +01:00
|
|
|
FOREIGN KEY("storage") REFERENCES "bricktracker_set_storages"("name"),
|
|
|
|
FOREIGN KEY("purchase_location") REFERENCES "bricktracker_set_purchase_locations"("name")
|
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;
|