Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Tidy up the content moderation scripts.

Matt Roberts5d656696161e
diff --git a/migrations/202507010830_add_moderation_enabled.sql b/migrations/202507010830_add_moderation_enabled.sql
deleted file mode 100644
index 3e1306969..000000000
--- a/migrations/202507010830_add_moderation_enabled.sql
+++ /dev/null
@@ -1,5 +0,0 @@
-ALTER TABLE tenants ADD is_moderation_enabled BOOLEAN NULL;
-
-UPDATE tenants SET is_moderation_enabled = false;
-
-ALTER TABLE tenants ALTER COLUMN is_moderation_enabled SET NOT NULL;
\ No newline at end of file
diff --git a/migrations/202507010831_add_is_approved.sql b/migrations/202507010831_add_is_approved.sql
deleted file mode 100644
index 32763491b..000000000
--- a/migrations/202507010831_add_is_approved.sql
+++ /dev/null
@@ -1,9 +0,0 @@
--- Add is_approved column to posts table
-ALTER TABLE posts ADD is_approved BOOLEAN NULL;
-UPDATE posts SET is_approved = true;
-ALTER TABLE posts ALTER COLUMN is_approved SET NOT NULL;
-
--- Add is_approved column to comments table
-ALTER TABLE comments ADD is_approved BOOLEAN NULL;
-UPDATE comments SET is_approved = true;
-ALTER TABLE comments ALTER COLUMN is_approved SET NOT NULL;
\ No newline at end of file
diff --git a/migrations/202507020900_add_user_verification.sql b/migrations/202507020900_add_user_verification.sql
deleted file mode 100644
index 9815af8d6..000000000
--- a/migrations/202507020900_add_user_verification.sql
+++ /dev/null
@@ -1,6 +0,0 @@
--- Add user verification column to users table
--- This allows users to be verified for automatic approval of their content
-ALTER TABLE users ADD COLUMN is_verified boolean NOT NULL DEFAULT false;
-
--- Add index for performance
-CREATE INDEX idx_users_verification ON users(tenant_id, is_verified) WHERE is_verified = true;
\ No newline at end of file
diff --git a/migrations/202511041300_content_moderation.sql b/migrations/202511041300_content_moderation.sql
new file mode 100644
index 000000000..74b2932e5
--- /dev/null
+++ b/migrations/202511041300_content_moderation.sql
@@ -0,0 +1,57 @@
+-- Add is_moderation_enabled column to tenants table
+ALTER TABLE tenants ADD COLUMN IF NOT EXISTS is_moderation_enabled BOOLEAN NULL;
+
+UPDATE tenants SET is_moderation_enabled = false WHERE is_moderation_enabled IS NULL;
+
+DO $$
+BEGIN
+ IF EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'tenants'
+ AND column_name = 'is_moderation_enabled'
+ AND is_nullable = 'YES'
+ ) THEN
+ ALTER TABLE tenants ALTER COLUMN is_moderation_enabled SET NOT NULL;
+ END IF;
+END $$;
+
+-- Add is_approved column to posts table
+ALTER TABLE posts ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NULL;
+
+UPDATE posts SET is_approved = true WHERE is_approved IS NULL;
+
+DO $$
+BEGIN
+ IF EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'posts'
+ AND column_name = 'is_approved'
+ AND is_nullable = 'YES'
+ ) THEN
+ ALTER TABLE posts ALTER COLUMN is_approved SET NOT NULL;
+ END IF;
+END $$;
+
+-- Add is_approved column to comments table
+ALTER TABLE comments ADD COLUMN IF NOT EXISTS is_approved BOOLEAN NULL;
+
+UPDATE comments SET is_approved = true WHERE is_approved IS NULL;
+
+DO $$
+BEGIN
+ IF EXISTS (
+ SELECT 1 FROM information_schema.columns
+ WHERE table_name = 'comments'
+ AND column_name = 'is_approved'
+ AND is_nullable = 'YES'
+ ) THEN
+ ALTER TABLE comments ALTER COLUMN is_approved SET NOT NULL;
+ END IF;
+END $$;
+
+-- Add user verification column to users table
+-- This allows users to be verified for automatic approval of their content
+ALTER TABLE users ADD COLUMN IF NOT EXISTS is_verified boolean NOT NULL DEFAULT false;
+
+-- Add index for performance
+CREATE INDEX IF NOT EXISTS idx_users_verification ON users(tenant_id, is_verified) WHERE is_verified = true;
\ No newline at end of file