add
This commit is contained in:
@@ -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 $$;
|
||||
@@ -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,
|
||||
Reference in New Issue
Block a user