summaryrefslogtreecommitdiff
path: root/migrations
diff options
context:
space:
mode:
Diffstat (limited to 'migrations')
-rw-r--r--migrations/7_migrate_bookmarx_to_role_access_model.sql24
1 files changed, 24 insertions, 0 deletions
diff --git a/migrations/7_migrate_bookmarx_to_role_access_model.sql b/migrations/7_migrate_bookmarx_to_role_access_model.sql
new file mode 100644
index 0000000..574a07c
--- /dev/null
+++ b/migrations/7_migrate_bookmarx_to_role_access_model.sql
@@ -0,0 +1,24 @@
+BEGIN TRANSACTION;
+
+ALTER TABLE post_targets DROP CONSTRAINT lazychat_targets_message_fkey;
+ALTER TABLE lazychat_references DROP CONSTRAINT lazychat_references_referee_fkey;
+
+INSERT INTO post_targets
+ SELECT bm.id, rt.role
+ FROM bookmarks bm
+ INNER JOIN role_tags rt ON tag = 'world'
+ WHERE visibility = 'public';
+INSERT INTO post_targets
+ SELECT bm.id, udt.target
+ FROM bookmarks bm
+ INNER JOIN user_default_target udt ON bm.owner = udt."user"
+ WHERE visibility = 'protected';
+
+ALTER TABLE bookmarks DROP COLUMN visibility;
+
+CREATE VIEW user_visible_bookmarks AS
+ SELECT uvp.user, uvp.message
+ FROM user_visible_posts uvp
+ INNER JOIN bookmarks bm ON bm.id = uvp.message;
+
+COMMIT;