2022-08-05 04:10:34 +00:00
|
|
|
CREATE TYPE member_state AS ENUM ('normal', 'pending', 'withdrawal', 'dormancy', 'blacklist', 'suspended');
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS members (
|
|
|
|
id UUID DEFAULT uuid_generate_v4(),
|
2022-08-08 00:59:34 +00:00
|
|
|
site_id UUID NOT NULL,
|
2022-08-05 04:10:34 +00:00
|
|
|
member_class_id UUID NOT NULL,
|
|
|
|
member_level_id UUID NOT NULL,
|
|
|
|
username TEXT NOT NULL,
|
|
|
|
password TEXT NOT NULL,
|
|
|
|
nickname TEXT NOT NULL,
|
|
|
|
mobile_phone_number TEXT,
|
|
|
|
state MEMBER_STATE DEFAULT 'normal',
|
|
|
|
state_changed_at BIGINT,
|
|
|
|
referrer_member_id UUID,
|
2022-08-07 10:43:16 +00:00
|
|
|
referred_count BIGINT NOT NULL DEFAULT 0,
|
2022-08-14 08:39:17 +00:00
|
|
|
last_signined_ip TEXT,
|
|
|
|
last_signined_at BIGINT,
|
2022-08-05 04:10:34 +00:00
|
|
|
created_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
|
|
|
|
updated_at BIGINT NOT NULL DEFAULT (extract(epoch from now()) * 1000),
|
|
|
|
deleted_at BIGINT,
|
|
|
|
PRIMARY KEY (id),
|
|
|
|
UNIQUE (username),
|
2022-08-08 00:59:34 +00:00
|
|
|
CONSTRAINT fk_members_site_id
|
|
|
|
FOREIGN KEY(site_id)
|
|
|
|
REFERENCES sites(id),
|
2022-08-05 04:10:34 +00:00
|
|
|
CONSTRAINT fk_members_member_class_id
|
|
|
|
FOREIGN KEY(member_class_id)
|
|
|
|
REFERENCES member_classes(id),
|
|
|
|
CONSTRAINT fk_members_member_level_id
|
|
|
|
FOREIGN KEY(member_level_id)
|
|
|
|
REFERENCES member_levels(id),
|
|
|
|
CONSTRAINT fk_members_referrer_member_id
|
|
|
|
FOREIGN KEY(referrer_member_id)
|
|
|
|
REFERENCES members(id)
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE INDEX idx_members_username ON members (username);
|
|
|
|
|
|
|
|
-- trigger (updated_at)
|
|
|
|
CREATE TRIGGER tg_members_updated_at
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON members
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE update_updated_at_column();
|
|
|
|
|
|
|
|
-- trigger (state_changed_at)
|
|
|
|
CREATE TRIGGER tg_members_state_changed_at
|
|
|
|
BEFORE UPDATE
|
|
|
|
ON members
|
|
|
|
FOR EACH ROW
|
|
|
|
EXECUTE PROCEDURE update_state_changed_at_column();
|