From 3f67f6bffd24f2fb10c58adcf6792a07cf65e11f Mon Sep 17 00:00:00 2001 From: Anders Gustafsson <34234789+anders-photowall@users.noreply.github.com> Date: Tue, 2 Jul 2024 10:41:09 +0200 Subject: [PATCH] 5659 - add paint_card_samples table --- migrations/000.487.sql | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 migrations/000.487.sql diff --git a/migrations/000.487.sql b/migrations/000.487.sql new file mode 100644 index 0000000..bffdb48 --- /dev/null +++ b/migrations/000.487.sql @@ -0,0 +1,17 @@ +-- Drop what is created below for developer convenience +DROP TABLE IF EXISTS paint_card_samples; + +-- Create paint primer table structure +-- Create paint_primer table +CREATE TABLE paint_card_samples ( + id INTEGER GENERATED ALWAYS AS IDENTITY PRIMARY KEY, + paint_id INTEGER NOT NULL REFERENCES paint(id), + stock INTEGER NOT NULL DEFAULT 0, + created timestamp with time zone NOT NULL DEFAULT now(), + updated timestamp with time zone DEFAULT NULL +); + +CREATE TRIGGER updated_timestamp BEFORE UPDATE ON paint_card_samples FOR EACH ROW EXECUTE PROCEDURE updated_timestamp(); + +-- For each paint row add a paint_card_sample row with stock 1 +INSERT INTO paint_card_samples (paint_id, stock) SELECT id, 1 FROM paint;