From b826cad3fcd993a85caaad90dbe1ce5c356b9228 Mon Sep 17 00:00:00 2001 From: Nicholas Cristofaro Date: Thu, 4 Jan 2024 14:11:55 +0000 Subject: [PATCH] is: Add user console preferences migration --- ...0240103000001_console_preferences.down.sql | 18 +++++++++++ .../20240103000001_console_preferences.up.sql | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 pkg/identityserver/store/migrations/20240103000001_console_preferences.down.sql create mode 100644 pkg/identityserver/store/migrations/20240103000001_console_preferences.up.sql diff --git a/pkg/identityserver/store/migrations/20240103000001_console_preferences.down.sql b/pkg/identityserver/store/migrations/20240103000001_console_preferences.down.sql new file mode 100644 index 0000000000..2ba7e5d023 --- /dev/null +++ b/pkg/identityserver/store/migrations/20240103000001_console_preferences.down.sql @@ -0,0 +1,18 @@ +DROP TABLE IF EXISTS user_bookmarks CASCADE; + +--bun:split +ALTER TABLE users DROP COLUMN IF EXISTS console_preferences CASCADE; + +--bun:split +CREATE OR REPLACE VIEW user_accounts AS +SELECT + acc.id AS account_id, + acc.created_at AS account_created_at, + acc.updated_at AS account_updated_at, + acc.deleted_at AS account_deleted_at, + acc.uid AS account_uid, + usr.* +FROM + accounts acc + JOIN users usr ON usr.id = acc.account_id + AND acc.account_type = 'user'; diff --git a/pkg/identityserver/store/migrations/20240103000001_console_preferences.up.sql b/pkg/identityserver/store/migrations/20240103000001_console_preferences.up.sql new file mode 100644 index 0000000000..df4fe460ab --- /dev/null +++ b/pkg/identityserver/store/migrations/20240103000001_console_preferences.up.sql @@ -0,0 +1,30 @@ +ALTER TABLE users +ADD COLUMN IF NOT EXISTS console_preferences bytea; + +--bun:split +CREATE TABLE user_bookmarks ( + id uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + created_at timestamp with time zone NOT NULL, + updated_at timestamp with time zone NOT NULL, + + user_id character varying(36) NOT NULL, + entity_id character varying(36) NOT NULL, + entity_type character varying(32) NOT NULL +); + +CREATE UNIQUE INDEX user_bookmarks_user_id_entity_id_entity_type_idx + ON user_bookmarks (user_id, entity_id, entity_type); + +--bun:split +CREATE OR REPLACE VIEW user_accounts AS +SELECT + acc.id AS account_id, + acc.created_at AS account_created_at, + acc.updated_at AS account_updated_at, + acc.deleted_at AS account_deleted_at, + acc.uid AS account_uid, + usr.* +FROM + accounts acc + JOIN users usr ON usr.id = acc.account_id + AND acc.account_type = 'user';