From 8f4be835329b7d2c78c8f55b8ecbf622040ccce9 Mon Sep 17 00:00:00 2001
From: Matthias Andreas Benkard <code@mail.matthias.benkard.de>
Date: Sat, 18 Aug 2012 18:19:10 +0200
Subject: Book Marx: Apply role-based access scheme.

---
 .../7_migrate_bookmarx_to_role_access_model.sql    | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 migrations/7_migrate_bookmarx_to_role_access_model.sql

(limited to 'migrations/7_migrate_bookmarx_to_role_access_model.sql')

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;
-- 
cgit v1.2.3

