BrickTracker/bricktracker/sql/migrations/0007.sql
2025-01-27 23:19:26 +01:00

30 lines
718 B
SQL

-- description: Creation of the deduplicated table of Rebrickable minifigures
BEGIN TRANSACTION;
-- Create a Rebrickable minifigures table: each unique minifigure imported from Rebrickable
CREATE TABLE "rebrickable_minifigures" (
"figure" TEXT NOT NULL,
"number" INTEGER NOT NULL,
"name" TEXT NOT NULL,
"image" TEXT,
PRIMARY KEY("figure")
);
-- Insert existing sets into the new table
INSERT INTO "rebrickable_minifigures" (
"figure",
"number",
"name",
"image"
)
SELECT
"minifigures"."fig_num",
CAST(SUBSTR("minifigures"."fig_num", 5) AS INTEGER),
"minifigures"."name",
"minifigures"."set_img_url"
FROM "minifigures"
GROUP BY
"minifigures"."fig_num";
COMMIT;