add
This commit is contained in:
32
backend/country/sql/04_create_code_table.sql
Normal file
32
backend/country/sql/04_create_code_table.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- 切换到目标数据库
|
||||
\c postgres;
|
||||
|
||||
CREATE OR REPLACE FUNCTION update_password_modified_column()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
NEW.updated_at = CURRENT_TIMESTAMP;
|
||||
RETURN NEW;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql VOLATILE;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'code') THEN
|
||||
CREATE TABLE code (
|
||||
id UUID DEFAULT gen_random_uuid_v7() PRIMARY KEY NOT NULL,
|
||||
user_id UUID NOT NULL,
|
||||
code VARCHAR 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_code_updated_at
|
||||
BEFORE UPDATE ON "code"
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION update_password_modified_column();
|
||||
|
||||
RAISE NOTICE 'Created code table and trigger';
|
||||
ELSE
|
||||
RAISE NOTICE 'code table already exists';
|
||||
END IF;
|
||||
END $$;
|
||||
Reference in New Issue
Block a user