sojorn/migrations/directus/add_directus_collections.sql
Patrick Britton 0bb1dd4055 feat: organize SQL scripts into structured migration folders
- Create organized migration folder structure:
  - database/ - Core schema changes and migrations
  - tests/ - Test scripts and verification queries
  - directus/ - Directus CMS configuration scripts
  - fixes/ - Database fixes and patches
  - archive/ - Historical and deprecated scripts

- Move 60+ SQL files from root to appropriate folders
- Add comprehensive README with usage guidelines
- Consolidate old migrations_archive into new archive folder
- Maintain clear separation of concerns for different script types

Benefits:
- Cleaner project root directory
- Easier to find specific types of SQL scripts
- Better organization for maintenance and development
- Clear documentation for migration procedures
- Proper separation of production vs development scripts
2026-02-05 09:13:47 -06:00

156 lines
6.2 KiB
SQL

-- Add moderation_flags collection to Directus
INSERT INTO directus_collections (
collection,
meta,
icon,
note,
translation,
sort,
singleton,
archive_filter,
archive_app_filter,
archive_value,
unarchive_filter,
unarchive_app_filter,
unarchive_value,
item_duplication_filter,
item_duplication_app_filter,
sort_field,
accountability
) VALUES (
'moderation_flags',
'{"display_template": null}',
'flag',
'AI-powered content moderation flags',
null,
null,
false,
null,
null,
'archived',
null,
null,
null,
null,
null,
null,
'all',
null
) ON CONFLICT (collection) DO NOTHING;
-- Add user_status_history collection to Directus
INSERT INTO directus_collections (
collection,
meta,
icon,
note,
translation,
sort,
singleton,
archive_filter,
archive_app_filter,
archive_value,
unarchive_filter,
unarchive_app_filter,
unarchive_value,
item_duplication_filter,
item_duplication_app_filter,
sort_field,
accountability
) VALUES (
'user_status_history',
'{"display_template": null}',
'history',
'User status change history for audit trail',
null,
null,
false,
null,
null,
'archived',
null,
null,
null,
null,
null,
null,
'all',
null
) ON CONFLICT (collection) DO NOTHING;
-- Add fields for moderation_flags collection
INSERT INTO directus_fields (
collection,
field,
special,
options,
meta,
interface,
note,
translation,
conditions,
required,
readonly,
hidden,
default_value,
group,
width,
validation
) VALUES
-- id field
('moderation_flags', 'id', 'uuid', null, '{"hidden": true}', 'input', null, null, null, false, true, true, null, null, 'full', null),
-- post_id field
('moderation_flags', 'post_id', 'uuid', null, '{"hidden": false, "interface": "related-values", "options": {"template": "{{post_id}}"}}', 'related-values', 'Reference to the post being moderated', null, null, false, false, false, null, null, 'full', null),
-- comment_id field
('moderation_flags', 'comment_id', 'uuid', null, '{"hidden": false, "interface": "related-values", "options": {"template": "{{comment_id}}"}}', 'related-values', 'Reference to the comment being moderated', null, null, false, false, false, null, null, 'full', null),
-- flag_reason field
('moderation_flags', 'flag_reason', 'string', null, '{"hidden": false, "interface": "select", "options": {"choices": {"hate": "Hate", "greed": "Greed", "delusion": "Delusion"}}}', 'select-dropdown', 'Primary reason for flag', null, null, false, false, false, null, null, 'full', null),
-- scores field
('moderation_flags', 'scores', 'json', null, '{"hidden": false, "interface": "json"}', 'json', 'JSON object containing detailed analysis scores', null, null, false, false, false, null, null, 'full', null),
-- status field
('moderation_flags', 'status', 'string', null, '{"hidden": false, "interface": "select", "options": {"choices": {"pending": "Pending", "approved": "Approved", "rejected": "Rejected", "escalated": "Escalated"}}}', 'select-dropdown', 'Current moderation status', null, null, false, false, false, 'pending', null, 'full', null),
-- reviewed_by field
('moderation_flags', 'reviewed_by', 'uuid', null, '{"hidden": false, "interface": "related-values", "options": {"template": "{{reviewed_by}}"}}', 'related-values', 'Admin who reviewed this flag', null, null, false, false, false, null, null, 'full', null),
-- reviewed_at field
('moderation_flags', 'reviewed_at', 'timestamp', null, '{"hidden": false}', 'datetime', 'When this flag was reviewed', null, null, false, false, false, null, null, 'full', null),
-- created_at field
('moderation_flags', 'created_at', 'timestamp', null, '{"hidden": false}', 'datetime', 'When this flag was created', null, null, false, false, false, null, null, 'full', null),
-- updated_at field
('moderation_flags', 'updated_at', 'timestamp', null, '{"hidden": true}', 'datetime', null, null, null, false, false, false, null, null, 'full', null)
ON CONFLICT (collection, field) DO NOTHING;
-- Add fields for user_status_history collection
INSERT INTO directus_fields (
collection,
field,
special,
options,
meta,
interface,
note,
translation,
conditions,
required,
readonly,
hidden,
default_value,
group,
width,
validation
) VALUES
-- id field
('user_status_history', 'id', 'uuid', null, '{"hidden": true}', 'input', null, null, null, false, true, true, null, null, 'full', null),
-- user_id field
('user_status_history', 'user_id', 'uuid', null, '{"hidden": false, "interface": "related-values", "options": {"template": "{{user_id}}"}}', 'related-values', 'User whose status changed', null, null, false, false, false, null, null, 'full', null),
-- old_status field
('user_status_history', 'old_status', 'string', null, '{"hidden": false, "interface": "select", "options": {"choices": {"active": "Active", "suspended": "Suspended", "banned": "Banned"}}}', 'select-dropdown', 'Previous status before change', null, null, false, false, false, null, null, 'full', null),
-- new_status field
('user_status_history', 'new_status', 'string', null, '{"hidden": false, "interface": "select", "options": {"choices": {"active": "Active", "suspended": "Suspended", "banned": "Banned"}}}', 'select-dropdown', 'New status after change', null, null, false, false, false, null, null, 'full', null),
-- reason field
('user_status_history', 'reason', 'string', null, '{"hidden": false}', 'input', 'Reason for status change', null, null, false, false, false, null, null, 'full', null),
-- changed_by field
('user_status_history', 'changed_by', 'uuid', null, '{"hidden": false, "interface": "related-values", "options": {"template": "{{changed_by}}"}}', 'related-values', 'Admin who made the change', null, null, false, false, false, null, null, 'full', null),
-- created_at field
('user_status_history', 'created_at', 'timestamp', null, '{"hidden": false}', 'datetime', 'When the status change occurred', null, null, false, false, false, null, null, 'full', null)
ON CONFLICT (collection, field) DO NOTHING;