beteran-server-service/migrations/202207011120_member_bank_withdraw/up.sql

39 lines
1.2 KiB
MySQL
Raw Normal View History

2022-08-11 16:16:56 +00:00
CREATE TYPE member_bank_withdraw_state AS ENUM ('application', 'complete');
CREATE TABLE IF NOT EXISTS member_bank_withdraws (
id UUID DEFAULT uuid_generate_v4(),
member_id UUID NOT NULL,
bank_name TEXT NOT NULL,
name TEXT NOT NULL,
account_number TEXT NOT NULL,
amount INTEGER NOT NULL,
password TEXT NOT NULL,
memo TEXT,
state MEMBER_BANK_WITHDRAW_STATE DEFAULT 'application',
state_changed_at BIGINT,
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
PRIMARY KEY (id),
CONSTRAINT fk_member_bank_withdraws_member_id
FOREIGN KEY(member_id)
REFERENCES members(id)
);
CREATE INDEX idx_member_bank_withdraws_member_id ON member_bank_withdraws (member_id);
-- trigger (updated_at)
CREATE TRIGGER tg_member_bank_withdraws_updated_at
BEFORE UPDATE
ON member_bank_withdraws
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();
-- trigger (state_changed_at)
CREATE TRIGGER tg_member_bank_withdraws_state_changed_at
BEFORE UPDATE
ON member_bank_withdraws
FOR EACH ROW
EXECUTE PROCEDURE update_state_changed_at_column();