beteran-server-service/migrations/202207151000_member_balance/up.sql

24 lines
855 B
MySQL
Raw Normal View History

2022-09-16 16:23:37 +00:00
CREATE TABLE IF NOT EXISTS member_balances (
id UUID DEFAULT uuid_generate_v4(),
member_id UUID NOT NULL,
balance DOUBLE PRECISION NOT NULL DEFAULT 0.00,
balance_bota DOUBLE PRECISION NOT NULL DEFAULT 0.00,
balance_sum DOUBLE PRECISION NOT NULL DEFAULT 0.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_balances_member_id
FOREIGN KEY(member_id)
REFERENCES members(id)
);
CREATE INDEX idx_member_balances_member_id ON member_balances (member_id);
-- trigger (updated_at)
CREATE TRIGGER tg_member_balances_updated_at
BEFORE UPDATE
ON member_balances
FOR EACH ROW
EXECUTE PROCEDURE update_updated_at_column();