2016-11-20 20:04:52 +01:00
|
|
|
-- Tables
|
|
|
|
|
2019-12-09 16:27:01 +01:00
|
|
|
CREATE TABLE IF NOT EXISTS icon_collections (
|
2016-11-20 20:04:52 +01:00
|
|
|
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
2019-11-18 11:52:57 +01:00
|
|
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
|
|
modified_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
|
|
deleted_at timestamptz DEFAULT NULL,
|
|
|
|
|
|
|
|
name text NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS icons (
|
|
|
|
id uuid PRIMARY KEY DEFAULT uuid_generate_v4(),
|
2019-11-18 11:52:57 +01:00
|
|
|
user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
|
|
modified_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
|
|
deleted_at timestamptz DEFAULT NULL,
|
|
|
|
|
|
|
|
name text NOT NULL,
|
|
|
|
content text NOT NULL,
|
|
|
|
metadata bytea NOT NULL,
|
2019-11-18 11:52:57 +01:00
|
|
|
|
2019-12-09 16:27:01 +01:00
|
|
|
collection_id uuid REFERENCES icon_collections(id)
|
2019-11-18 11:52:57 +01:00
|
|
|
ON DELETE SET NULL
|
|
|
|
DEFAULT NULL
|
2016-11-20 20:04:52 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
-- Indexes
|
|
|
|
|
2019-12-09 16:27:01 +01:00
|
|
|
CREATE INDEX icon_colections__user_id__idx ON icon_collections (user_id);
|
|
|
|
CREATE INDEX icons__user_id__idx ON icons(user_id);
|
|
|
|
CREATE INDEX icons__collection_id__idx ON icons(collection_id);
|
2016-11-20 20:04:52 +01:00
|
|
|
|
|
|
|
-- Triggers
|
|
|
|
|
2019-12-09 16:27:01 +01:00
|
|
|
CREATE TRIGGER icon_collections__modified_at__tgr
|
|
|
|
BEFORE UPDATE ON icon_collections
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE update_modified_at();
|
2016-11-20 20:04:52 +01:00
|
|
|
|
2019-12-09 16:27:01 +01:00
|
|
|
CREATE TRIGGER icons__modified_at__tgr
|
|
|
|
BEFORE UPDATE ON icons
|
|
|
|
FOR EACH ROW EXECUTE PROCEDURE update_modified_at();
|