From e2a6cfc21c214b7f59d88cf0d022969d656a0e39 Mon Sep 17 00:00:00 2001 From: vipg Date: Fri, 14 Nov 2025 17:08:15 +0800 Subject: [PATCH] add --- .../sql/04_create_variety_table.sql | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/backend/futures_trade_record/sql/04_create_variety_table.sql b/backend/futures_trade_record/sql/04_create_variety_table.sql index 5972ba0..11cc763 100644 --- a/backend/futures_trade_record/sql/04_create_variety_table.sql +++ b/backend/futures_trade_record/sql/04_create_variety_table.sql @@ -55,4 +55,40 @@ BEGIN ELSE RAISE NOTICE 'variety_code table already exists'; END IF; + + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'variety_tick') THEN + CREATE TABLE variety_tick ( + id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL, + tick NUMERIC(12, 6), + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP + ); + CREATE TRIGGER update_variety_tick_updated_at + BEFORE UPDATE ON "variety_tick" + FOR EACH ROW + EXECUTE FUNCTION update_data_modified_column(); + + RAISE NOTICE 'created variety_tick table and trigger'; + ELSE + RAISE NOTICE 'variety_tick table already exists'; + END IF; + + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'variety_tick_price') THEN + CREATE TABLE variety_tick_price ( + id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL, + price NUMERIC(12, 6), + deleted BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP + ); + CREATE TRIGGER update_variety_tick_price_updated_at + BEFORE UPDATE ON "variety_tick_price" + FOR EACH ROW + EXECUTE FUNCTION update_data_modified_column(); + + RAISE NOTICE 'created variety_tick_price table and trigger'; + ELSE + RAISE NOTICE 'variety_tick_price table already exists'; + END IF; END $$; \ No newline at end of file