16 lines
757 B
SQL
16 lines
757 B
SQL
-- Every time a user's own (primary) birth data is set or changed. The
|
|||
|
|
-- backend limits changes with it: after the first save, three corrections
|
||
|
|
-- within an hour, then one per 24 hours (admins are not limited).
|
||
|
|
|
||
|
|
CREATE TABLE birth_data_changes (
|
||
|
|
id uuid PRIMARY KEY,
|
||
|
|
user_id uuid NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||
|
|
chart_id uuid REFERENCES charts (id) ON DELETE SET NULL,
|
||
|
|
created_at timestamptz NOT NULL DEFAULT now()
|
||
|
|
);
|
||
|
|
CREATE INDEX birth_data_changes_user_idx ON birth_data_changes (user_id, created_at);
|
||
|
|
|
||
|
|
-- The current primary charts count as the first save.
|
||
|
|
INSERT INTO birth_data_changes (id, user_id, chart_id, created_at)
|
||
|
|
SELECT gen_random_uuid(), owner_id, id, created_at FROM charts WHERE is_primary;
|