diff --git a/backend/futures_trade_record/sql/03_create_record_table.sql b/backend/futures_trade_record/sql/03_create_record_table.sql deleted file mode 100644 index 683c48d..0000000 --- a/backend/futures_trade_record/sql/03_create_record_table.sql +++ /dev/null @@ -1,22 +0,0 @@ --- 切换到目标数据库 -\c postgres; - -DO $$ -BEGIN - IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'record') THEN - CREATE TABLE record ( - id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL, - 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_record_updated_at - BEFORE UPDATE ON "record" - FOR EACH ROW - EXECUTE FUNCTION update_data_modified_column(); - - RAISE NOTICE 'created record table and trigger'; - ELSE - RAISE NOTICE 'record table already exists'; - END IF; -END $$; \ No newline at end of file diff --git a/backend/futures_trade_record/sql/04_create_deal_table.sql b/backend/futures_trade_record/sql/03_create_trade_table.sql similarity index 80% rename from backend/futures_trade_record/sql/04_create_deal_table.sql rename to backend/futures_trade_record/sql/03_create_trade_table.sql index 15864ba..bc0b075 100644 --- a/backend/futures_trade_record/sql/04_create_deal_table.sql +++ b/backend/futures_trade_record/sql/03_create_trade_table.sql @@ -3,6 +3,23 @@ DO $$ BEGIN + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'record') THEN + CREATE TABLE record ( + id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL, + 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_record_updated_at + BEFORE UPDATE ON "record" + FOR EACH ROW + EXECUTE FUNCTION update_data_modified_column(); + + RAISE NOTICE 'created record table and trigger'; + ELSE + RAISE NOTICE 'record table already exists'; + END IF; + IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'deal') THEN CREATE TABLE deal ( id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL,