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

39 lines
1.3 KiB
MySQL
Raw Permalink Normal View History

2022-08-28 08:45:58 +00:00
CREATE TYPE member_bank_withdraw_state AS ENUM ('application', 'pending', 'complete');
2022-08-11 16:16:56 +00:00
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,
2022-08-30 08:14:53 +00:00
amount DOUBLE PRECISION NOT NULL,
2022-08-11 16:16:56 +00:00
password TEXT NOT NULL,
memo TEXT,
state MEMBER_BANK_WITHDRAW_STATE DEFAULT 'application',
2022-08-14 08:39:17 +00:00
state_changed_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
2022-08-11 16:16:56 +00:00
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();