28 lines
904 B
SQL
28 lines
904 B
SQL
CREATE TABLE IF NOT EXISTS member_bank_accounts (
|
|
id UUID DEFAULT uuid_generate_v4(),
|
|
member_id UUID NOT NULL,
|
|
bank_id UUID NOT NULL,
|
|
name TEXT NOT NULL,
|
|
account_number TEXT NOT NULL,
|
|
memo TEXT,
|
|
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_accounts_member_id
|
|
FOREIGN KEY(member_id)
|
|
REFERENCES members(id),
|
|
CONSTRAINT fk_member_bank_accounts_bank_id
|
|
FOREIGN KEY(bank_id)
|
|
REFERENCES banks(id)
|
|
|
|
);
|
|
|
|
CREATE INDEX idx_member_bank_accounts_member_id ON member_bank_accounts (member_id);
|
|
|
|
-- trigger (updated_at)
|
|
CREATE TRIGGER tg_member_bank_accounts_updated_at
|
|
BEFORE UPDATE
|
|
ON member_bank_accounts
|
|
FOR EACH ROW
|
|
EXECUTE PROCEDURE update_updated_at_column();
|