beteran-server-service/migrations/202207011110_member_bank_deposit/up.sql

36 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

2022-08-28 08:45:58 +00:00
CREATE TYPE member_bank_deposit_state AS ENUM ('application', 'pending', 'complete');
2022-08-11 16:16:56 +00:00
CREATE TABLE IF NOT EXISTS member_bank_deposits (
id UUID DEFAULT uuid_generate_v4(),
member_id UUID NOT NULL,
name TEXT NOT NULL,
2022-08-30 08:14:53 +00:00
amount DOUBLE PRECISION NOT NULL,
2022-08-11 16:16:56 +00:00
memo TEXT,
state MEMBER_BANK_DEPOSIT_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_deposits_member_id
FOREIGN KEY(member_id)
REFERENCES members(id)
);
CREATE INDEX idx_member_bank_deposits_member_id ON member_bank_deposits (member_id);
-- trigger (updated_at)
CREATE TRIGGER tg_member_bank_deposits_updated_at
BEFORE UPDATE
ON member_bank_deposits
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();
-- trigger (state_changed_at)
CREATE TRIGGER tg_member_bank_deposits_state_changed_at
BEFORE UPDATE
ON member_bank_deposits
FOR EACH ROW
EXECUTE PROCEDURE update_state_changed_at_column();