From b413edccaf2c487eccc8088b7051ac392a6d05d2 Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Mon, 18 May 2026 20:42:47 +0800 Subject: [PATCH] refactor(migrate): replace hand-written migrations with SQL-file macro system Replace individual Rust migration modules with a define_sql_migrations macro that reads up/down SQL files via include_str!. Consolidate all legacy single-file SQL into per-table directories and add full schema migration coverage for 90+ tables. --- libs/migrate/bootstrap.rs | 28 + libs/migrate/init.rs | 54 - libs/migrate/lib.rs | 278 ++- libs/migrate/project_message_favorite.rs | 57 - .../admin_api_token_down_01.sql | 2 + .../admin_api_token/admin_api_token_up_01.sql | 22 + .../admin_audit_log_down_01.sql | 5 + .../admin_audit_log/admin_audit_log_up_01.sql | 28 + .../admin_permission_down_01.sql | 1 + .../admin_permission_up_01.sql | 10 + .../sql/admin_role/admin_role_down_01.sql | 1 + .../sql/admin_role/admin_role_up_01.sql | 9 + .../admin_role_permission_down_01.sql | 1 + .../admin_role_permission_up_01.sql | 10 + .../sql/admin_user/admin_user_down_01.sql | 2 + .../sql/admin_user/admin_user_up_01.sql | 14 + .../admin_user_role_down_01.sql | 1 + .../admin_user_role/admin_user_role_up_01.sql | 10 + .../sql/agent_task/agent_task_down_01.sql | 8 + .../sql/agent_task/agent_task_up_01.sql | 45 + .../ai_conversation_down_01.sql | 8 + .../ai_conversation/ai_conversation_up_01.sql | 49 + .../sql/ai_message/ai_message_down_01.sql | 3 + .../sql/ai_message/ai_message_up_01.sql | 30 + .../ai_message_fork_down_01.sql | 3 + .../ai_message_fork/ai_message_fork_up_01.sql | 20 + .../migrate/sql/ai_model/ai_model_down_01.sql | 2 + libs/migrate/sql/ai_model/ai_model_up_01.sql | 19 + .../ai_model_capability_down_01.sql | 2 + .../ai_model_capability_up_01.sql | 12 + .../ai_model_parameter_profile_down_01.sql | 2 + .../ai_model_parameter_profile_up_01.sql | 16 + .../ai_model_pricing_down_01.sql | 2 + .../ai_model_pricing_up_01.sql | 13 + .../ai_model_provider_down_01.sql | 1 + .../ai_model_provider_up_01.sql | 11 + .../ai_model_version_down_01.sql | 2 + .../ai_model_version_up_01.sql | 15 + .../sql/ai_session/ai_session_down_01.sql | 2 + .../sql/ai_session/ai_session_up_01.sql | 19 + .../ai_shared_conversation_down_01.sql | 3 + .../ai_shared_conversation_up_01.sql | 21 + .../ai_subagent_session_down_01.sql | 4 + .../ai_subagent_session_up_01.sql} | 38 - .../ai_token_usage/ai_token_usage_down_01.sql | 4 + .../ai_token_usage/ai_token_usage_up_01.sql | 21 + .../sql/ai_tool_auth/ai_tool_auth_down_01.sql | 1 + .../sql/ai_tool_auth/ai_tool_auth_up_01.sql | 17 + .../sql/ai_tool_call/ai_tool_call_down_01.sql | 3 + .../sql/ai_tool_call/ai_tool_call_up_01.sql | 24 + .../sql/bootstrap/bootstrap_down_01.sql | 3 + .../migrate/sql/bootstrap/bootstrap_up_01.sql | 33 + libs/migrate/sql/init.sql | 1835 ----------------- libs/migrate/sql/issue/issue_down_01.sql | 4 + libs/migrate/sql/issue/issue_up_01.sql | 25 + .../issue_assignee/issue_assignee_down_01.sql | 1 + .../issue_assignee/issue_assignee_up_01.sql | 7 + .../issue_comment/issue_comment_down_01.sql | 2 + .../sql/issue_comment/issue_comment_up_01.sql | 13 + .../issue_comment_reaction_down_01.sql | 1 + .../issue_comment_reaction_up_01.sql | 8 + .../sql/issue_label/issue_label_down_01.sql | 1 + .../sql/issue_label/issue_label_up_01.sql | 7 + .../issue_pull_request_down_01.sql | 1 + .../issue_pull_request_up_01.sql | 8 + .../issue_reaction/issue_reaction_down_01.sql | 1 + .../issue_reaction/issue_reaction_up_01.sql | 8 + .../sql/issue_repo/issue_repo_down_01.sql | 1 + .../sql/issue_repo/issue_repo_up_01.sql | 7 + .../issue_subscriber_down_01.sql | 1 + .../issue_subscriber_up_01.sql | 8 + libs/migrate/sql/label/label_down_01.sql | 2 + libs/migrate/sql/label/label_up_01.sql | 11 + libs/migrate/sql/notify/notify_down_01.sql | 3 + libs/migrate/sql/notify/notify_up_01.sql | 20 + libs/migrate/sql/project/project_down_01.sql | 6 + libs/migrate/sql/project/project_up_01.sql | 32 + .../project_access_log_down_01.sql | 3 + .../project_access_log_up_01.sql | 17 + .../project_activity_down_01.sql | 4 + .../project_activity_up_01.sql | 25 + .../project_audit_log_down_01.sql | 3 + .../project_audit_log_up_01.sql | 18 + .../project_billing_down_01.sql | 1 + .../project_billing/project_billing_up_01.sql | 10 + .../project_billing_history_down_01.sql | 2 + .../project_billing_history_up_01.sql | 15 + .../project_board/project_board_down_01.sql | 2 + .../sql/project_board/project_board_up_01.sql | 14 + .../project_board_card_down_01.sql | 3 + .../project_board_card_up_01.sql | 26 + .../project_board_column_down_01.sql | 2 + .../project_board_column_up_01.sql | 15 + .../project_follow/project_follow_down_01.sql | 2 + .../project_follow/project_follow_up_01.sql | 12 + .../project_history_name_down_01.sql | 2 + .../project_history_name_up_01.sql | 11 + .../project_label/project_label_down_01.sql | 2 + .../sql/project_label/project_label_up_01.sql | 11 + .../sql/project_like/project_like_down_01.sql | 1 + .../sql/project_like/project_like_up_01.sql | 7 + .../project_member_invitations_down_01.sql | 2 + .../project_member_invitations_up_01.sql | 17 + .../project_member_join_answers_down_01.sql | 2 + .../project_member_join_answers_up_01.sql | 14 + .../project_member_join_request_down_01.sql | 3 + .../project_member_join_request_up_01.sql | 20 + .../project_member_join_settings_down_01.sql | 1 + .../project_member_join_settings_up_01.sql | 11 + .../project_members_down_01.sql | 2 + .../project_members/project_members_up_01.sql | 13 + .../project_message_favorite_down_01.sql | 4 + .../project_message_favorite_up_01.sql | 19 + .../project_role_priority_down_01.sql | 3 + .../project_role_priority_up_01.sql | 19 + .../project_skill/project_skill_down_01.sql | 6 + .../sql/project_skill/project_skill_up_01.sql | 35 + .../project_watch/project_watch_down_01.sql | 2 + .../sql/project_watch/project_watch_up_01.sql | 14 + .../sql/pull_request/pull_request_down_01.sql | 4 + .../sql/pull_request/pull_request_up_01.sql | 27 + .../pull_request_commit_down_01.sql | 1 + .../pull_request_commit_up_01.sql | 15 + .../pull_request_review_down_01.sql | 1 + .../pull_request_review_up_01.sql | 12 + .../pull_request_review_comment_down_01.sql | 1 + .../pull_request_review_comment_up_01.sql | 18 + .../pull_request_review_request_down_01.sql | 1 + .../pull_request_review_request_up_01.sql | 11 + libs/migrate/sql/repo/repo_down_01.sql | 3 + libs/migrate/sql/repo/repo_up_01.sql | 21 + .../sql/repo_branch/repo_branch_down_01.sql | 2 + .../sql/repo_branch/repo_branch_up_01.sql | 14 + .../repo_branch_protect_down_01.sql | 2 + .../repo_branch_protect_up_01.sql | 21 + .../repo_collaborator_down_01.sql | 1 + .../repo_collaborator_up_01.sql | 8 + .../sql/repo_commit/repo_commit_down_01.sql | 3 + .../sql/repo_commit/repo_commit_up_01.sql | 22 + .../sql/repo_fork/repo_fork_down_01.sql | 3 + .../migrate/sql/repo_fork/repo_fork_up_01.sql | 15 + .../repo_history_name_down_01.sql | 2 + .../repo_history_name_up_01.sql | 12 + .../sql/repo_hook/repo_hook_down_01.sql | 2 + .../migrate/sql/repo_hook/repo_hook_up_01.sql | 12 + .../repo_lfs_lock/repo_lfs_lock_down_01.sql | 1 + .../sql/repo_lfs_lock/repo_lfs_lock_up_01.sql | 10 + .../repo_lfs_object_down_01.sql | 2 + .../repo_lfs_object/repo_lfs_object_up_01.sql | 14 + .../sql/repo_lock/repo_lock_down_01.sql | 1 + .../migrate/sql/repo_lock/repo_lock_up_01.sql | 10 + .../sql/repo_star/repo_star_down_01.sql | 2 + .../migrate/sql/repo_star/repo_star_up_01.sql | 12 + .../migrate/sql/repo_tag/repo_tag_down_01.sql | 1 + libs/migrate/sql/repo_tag/repo_tag_up_01.sql | 13 + .../repo_upstream/repo_upstream_down_01.sql | 2 + .../sql/repo_upstream/repo_upstream_up_01.sql | 18 + .../sql/repo_watch/repo_watch_down_01.sql | 2 + .../sql/repo_watch/repo_watch_up_01.sql | 15 + .../sql/repo_webhook/repo_webhook_down_01.sql | 2 + .../sql/repo_webhook/repo_webhook_up_01.sql | 16 + libs/migrate/sql/room/room_down_01.sql | 3 + libs/migrate/sql/room/room_up_01.sql | 18 + .../sql/room_access/room_access_down_01.sql | 2 + .../sql/room_access/room_access_up_01.sql | 11 + libs/migrate/sql/room_ai/room_ai_down_01.sql | 2 + libs/migrate/sql/room_ai/room_ai_up_01.sql | 24 + .../room_attachment_down_01.sql | 4 + .../room_attachment/room_attachment_up_01.sql | 22 + .../room_category/room_category_down_01.sql | 2 + .../sql/room_category/room_category_up_01.sql | 13 + .../room_compact_summary_down_01.sql | 2 + .../room_compact_summary_up_01.sql} | 0 .../sql/room_message/room_message_down_01.sql | 6 + .../sql/room_message/room_message_up_01.sql | 36 + .../room_message_edit_history_down_01.sql | 3 + .../room_message_edit_history_up_01.sql | 20 + .../room_message_reaction_down_01.sql | 4 + .../room_message_reaction_up_01.sql | 26 + .../room_notifications_down_01.sql | 4 + .../room_notifications_up_01.sql | 29 + .../migrate/sql/room_pin/room_pin_down_01.sql | 1 + libs/migrate/sql/room_pin/room_pin_up_01.sql | 8 + .../sql/room_thread/room_thread_down_01.sql | 2 + .../sql/room_thread/room_thread_up_01.sql | 16 + .../room_user_state_down_01.sql | 2 + .../room_user_state/room_user_state_up_01.sql | 14 + libs/migrate/sql/user/user_down_01.sql | 2 + libs/migrate/sql/user/user_up_01.sql | 16 + .../migrate/sql/user_2fa/user_2fa_down_01.sql | 1 + libs/migrate/sql/user_2fa/user_2fa_up_01.sql | 11 + .../user_activity_log_down_01.sql | 3 + .../user_activity_log_up_01.sql | 17 + .../user_billing_history_down_01.sql | 3 + .../user_billing_history_up_01.sql | 17 + .../sql/user_email/user_email_down_01.sql | 2 + .../sql/user_email/user_email_up_01.sql | 10 + .../user_email_change_down_01.sql | 2 + .../user_email_change_up_01.sql | 13 + .../user_notification_down_01.sql | 1 + .../user_notification_up_01.sql | 20 + .../user_password/user_password_down_01.sql | 1 + .../sql/user_password/user_password_up_01.sql | 10 + .../user_password_reset_down_01.sql | 2 + .../user_password_reset_up_01.sql | 12 + .../user_preferences_down_01.sql | 1 + .../user_preferences_up_01.sql | 12 + .../user_relation/user_relation_down_01.sql | 3 + .../sql/user_relation/user_relation_up_01.sql | 15 + .../sql/user_ssh_key/user_ssh_key_down_01.sql | 2 + .../sql/user_ssh_key/user_ssh_key_up_01.sql | 20 + .../sql/user_token/user_token_down_01.sql | 2 + .../sql/user_token/user_token_up_01.sql | 16 + .../sql/workspace/workspace_down_01.sql | 1 + .../migrate/sql/workspace/workspace_up_01.sql | 17 + .../workspace_alert_config_down_01.sql | 2 + .../workspace_alert_config_up_01.sql | 17 + .../workspace_billing_down_01.sql | 1 + .../workspace_billing_up_01.sql | 13 + .../workspace_billing_history_down_01.sql | 3 + .../workspace_billing_history_up_01.sql | 20 + .../workspace_membership_down_01.sql | 4 + .../workspace_membership_up_01.sql | 24 + libs/migrate/user_billing_history.rs | 56 - 224 files changed, 2341 insertions(+), 2057 deletions(-) create mode 100644 libs/migrate/bootstrap.rs delete mode 100644 libs/migrate/init.rs delete mode 100644 libs/migrate/project_message_favorite.rs create mode 100644 libs/migrate/sql/admin_api_token/admin_api_token_down_01.sql create mode 100644 libs/migrate/sql/admin_api_token/admin_api_token_up_01.sql create mode 100644 libs/migrate/sql/admin_audit_log/admin_audit_log_down_01.sql create mode 100644 libs/migrate/sql/admin_audit_log/admin_audit_log_up_01.sql create mode 100644 libs/migrate/sql/admin_permission/admin_permission_down_01.sql create mode 100644 libs/migrate/sql/admin_permission/admin_permission_up_01.sql create mode 100644 libs/migrate/sql/admin_role/admin_role_down_01.sql create mode 100644 libs/migrate/sql/admin_role/admin_role_up_01.sql create mode 100644 libs/migrate/sql/admin_role_permission/admin_role_permission_down_01.sql create mode 100644 libs/migrate/sql/admin_role_permission/admin_role_permission_up_01.sql create mode 100644 libs/migrate/sql/admin_user/admin_user_down_01.sql create mode 100644 libs/migrate/sql/admin_user/admin_user_up_01.sql create mode 100644 libs/migrate/sql/admin_user_role/admin_user_role_down_01.sql create mode 100644 libs/migrate/sql/admin_user_role/admin_user_role_up_01.sql create mode 100644 libs/migrate/sql/agent_task/agent_task_down_01.sql create mode 100644 libs/migrate/sql/agent_task/agent_task_up_01.sql create mode 100644 libs/migrate/sql/ai_conversation/ai_conversation_down_01.sql create mode 100644 libs/migrate/sql/ai_conversation/ai_conversation_up_01.sql create mode 100644 libs/migrate/sql/ai_message/ai_message_down_01.sql create mode 100644 libs/migrate/sql/ai_message/ai_message_up_01.sql create mode 100644 libs/migrate/sql/ai_message_fork/ai_message_fork_down_01.sql create mode 100644 libs/migrate/sql/ai_message_fork/ai_message_fork_up_01.sql create mode 100644 libs/migrate/sql/ai_model/ai_model_down_01.sql create mode 100644 libs/migrate/sql/ai_model/ai_model_up_01.sql create mode 100644 libs/migrate/sql/ai_model_capability/ai_model_capability_down_01.sql create mode 100644 libs/migrate/sql/ai_model_capability/ai_model_capability_up_01.sql create mode 100644 libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_down_01.sql create mode 100644 libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_up_01.sql create mode 100644 libs/migrate/sql/ai_model_pricing/ai_model_pricing_down_01.sql create mode 100644 libs/migrate/sql/ai_model_pricing/ai_model_pricing_up_01.sql create mode 100644 libs/migrate/sql/ai_model_provider/ai_model_provider_down_01.sql create mode 100644 libs/migrate/sql/ai_model_provider/ai_model_provider_up_01.sql create mode 100644 libs/migrate/sql/ai_model_version/ai_model_version_down_01.sql create mode 100644 libs/migrate/sql/ai_model_version/ai_model_version_up_01.sql create mode 100644 libs/migrate/sql/ai_session/ai_session_down_01.sql create mode 100644 libs/migrate/sql/ai_session/ai_session_up_01.sql create mode 100644 libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_down_01.sql create mode 100644 libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_up_01.sql create mode 100644 libs/migrate/sql/ai_subagent_session/ai_subagent_session_down_01.sql rename libs/migrate/{ai_subagent_session.rs => sql/ai_subagent_session/ai_subagent_session_up_01.sql} (53%) create mode 100644 libs/migrate/sql/ai_token_usage/ai_token_usage_down_01.sql create mode 100644 libs/migrate/sql/ai_token_usage/ai_token_usage_up_01.sql create mode 100644 libs/migrate/sql/ai_tool_auth/ai_tool_auth_down_01.sql create mode 100644 libs/migrate/sql/ai_tool_auth/ai_tool_auth_up_01.sql create mode 100644 libs/migrate/sql/ai_tool_call/ai_tool_call_down_01.sql create mode 100644 libs/migrate/sql/ai_tool_call/ai_tool_call_up_01.sql create mode 100644 libs/migrate/sql/bootstrap/bootstrap_down_01.sql create mode 100644 libs/migrate/sql/bootstrap/bootstrap_up_01.sql delete mode 100644 libs/migrate/sql/init.sql create mode 100644 libs/migrate/sql/issue/issue_down_01.sql create mode 100644 libs/migrate/sql/issue/issue_up_01.sql create mode 100644 libs/migrate/sql/issue_assignee/issue_assignee_down_01.sql create mode 100644 libs/migrate/sql/issue_assignee/issue_assignee_up_01.sql create mode 100644 libs/migrate/sql/issue_comment/issue_comment_down_01.sql create mode 100644 libs/migrate/sql/issue_comment/issue_comment_up_01.sql create mode 100644 libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_down_01.sql create mode 100644 libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_up_01.sql create mode 100644 libs/migrate/sql/issue_label/issue_label_down_01.sql create mode 100644 libs/migrate/sql/issue_label/issue_label_up_01.sql create mode 100644 libs/migrate/sql/issue_pull_request/issue_pull_request_down_01.sql create mode 100644 libs/migrate/sql/issue_pull_request/issue_pull_request_up_01.sql create mode 100644 libs/migrate/sql/issue_reaction/issue_reaction_down_01.sql create mode 100644 libs/migrate/sql/issue_reaction/issue_reaction_up_01.sql create mode 100644 libs/migrate/sql/issue_repo/issue_repo_down_01.sql create mode 100644 libs/migrate/sql/issue_repo/issue_repo_up_01.sql create mode 100644 libs/migrate/sql/issue_subscriber/issue_subscriber_down_01.sql create mode 100644 libs/migrate/sql/issue_subscriber/issue_subscriber_up_01.sql create mode 100644 libs/migrate/sql/label/label_down_01.sql create mode 100644 libs/migrate/sql/label/label_up_01.sql create mode 100644 libs/migrate/sql/notify/notify_down_01.sql create mode 100644 libs/migrate/sql/notify/notify_up_01.sql create mode 100644 libs/migrate/sql/project/project_down_01.sql create mode 100644 libs/migrate/sql/project/project_up_01.sql create mode 100644 libs/migrate/sql/project_access_log/project_access_log_down_01.sql create mode 100644 libs/migrate/sql/project_access_log/project_access_log_up_01.sql create mode 100644 libs/migrate/sql/project_activity/project_activity_down_01.sql create mode 100644 libs/migrate/sql/project_activity/project_activity_up_01.sql create mode 100644 libs/migrate/sql/project_audit_log/project_audit_log_down_01.sql create mode 100644 libs/migrate/sql/project_audit_log/project_audit_log_up_01.sql create mode 100644 libs/migrate/sql/project_billing/project_billing_down_01.sql create mode 100644 libs/migrate/sql/project_billing/project_billing_up_01.sql create mode 100644 libs/migrate/sql/project_billing_history/project_billing_history_down_01.sql create mode 100644 libs/migrate/sql/project_billing_history/project_billing_history_up_01.sql create mode 100644 libs/migrate/sql/project_board/project_board_down_01.sql create mode 100644 libs/migrate/sql/project_board/project_board_up_01.sql create mode 100644 libs/migrate/sql/project_board_card/project_board_card_down_01.sql create mode 100644 libs/migrate/sql/project_board_card/project_board_card_up_01.sql create mode 100644 libs/migrate/sql/project_board_column/project_board_column_down_01.sql create mode 100644 libs/migrate/sql/project_board_column/project_board_column_up_01.sql create mode 100644 libs/migrate/sql/project_follow/project_follow_down_01.sql create mode 100644 libs/migrate/sql/project_follow/project_follow_up_01.sql create mode 100644 libs/migrate/sql/project_history_name/project_history_name_down_01.sql create mode 100644 libs/migrate/sql/project_history_name/project_history_name_up_01.sql create mode 100644 libs/migrate/sql/project_label/project_label_down_01.sql create mode 100644 libs/migrate/sql/project_label/project_label_up_01.sql create mode 100644 libs/migrate/sql/project_like/project_like_down_01.sql create mode 100644 libs/migrate/sql/project_like/project_like_up_01.sql create mode 100644 libs/migrate/sql/project_member_invitations/project_member_invitations_down_01.sql create mode 100644 libs/migrate/sql/project_member_invitations/project_member_invitations_up_01.sql create mode 100644 libs/migrate/sql/project_member_join_answers/project_member_join_answers_down_01.sql create mode 100644 libs/migrate/sql/project_member_join_answers/project_member_join_answers_up_01.sql create mode 100644 libs/migrate/sql/project_member_join_request/project_member_join_request_down_01.sql create mode 100644 libs/migrate/sql/project_member_join_request/project_member_join_request_up_01.sql create mode 100644 libs/migrate/sql/project_member_join_settings/project_member_join_settings_down_01.sql create mode 100644 libs/migrate/sql/project_member_join_settings/project_member_join_settings_up_01.sql create mode 100644 libs/migrate/sql/project_members/project_members_down_01.sql create mode 100644 libs/migrate/sql/project_members/project_members_up_01.sql create mode 100644 libs/migrate/sql/project_message_favorite/project_message_favorite_down_01.sql create mode 100644 libs/migrate/sql/project_message_favorite/project_message_favorite_up_01.sql create mode 100644 libs/migrate/sql/project_role_priority/project_role_priority_down_01.sql create mode 100644 libs/migrate/sql/project_role_priority/project_role_priority_up_01.sql create mode 100644 libs/migrate/sql/project_skill/project_skill_down_01.sql create mode 100644 libs/migrate/sql/project_skill/project_skill_up_01.sql create mode 100644 libs/migrate/sql/project_watch/project_watch_down_01.sql create mode 100644 libs/migrate/sql/project_watch/project_watch_up_01.sql create mode 100644 libs/migrate/sql/pull_request/pull_request_down_01.sql create mode 100644 libs/migrate/sql/pull_request/pull_request_up_01.sql create mode 100644 libs/migrate/sql/pull_request_commit/pull_request_commit_down_01.sql create mode 100644 libs/migrate/sql/pull_request_commit/pull_request_commit_up_01.sql create mode 100644 libs/migrate/sql/pull_request_review/pull_request_review_down_01.sql create mode 100644 libs/migrate/sql/pull_request_review/pull_request_review_up_01.sql create mode 100644 libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_down_01.sql create mode 100644 libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_up_01.sql create mode 100644 libs/migrate/sql/pull_request_review_request/pull_request_review_request_down_01.sql create mode 100644 libs/migrate/sql/pull_request_review_request/pull_request_review_request_up_01.sql create mode 100644 libs/migrate/sql/repo/repo_down_01.sql create mode 100644 libs/migrate/sql/repo/repo_up_01.sql create mode 100644 libs/migrate/sql/repo_branch/repo_branch_down_01.sql create mode 100644 libs/migrate/sql/repo_branch/repo_branch_up_01.sql create mode 100644 libs/migrate/sql/repo_branch_protect/repo_branch_protect_down_01.sql create mode 100644 libs/migrate/sql/repo_branch_protect/repo_branch_protect_up_01.sql create mode 100644 libs/migrate/sql/repo_collaborator/repo_collaborator_down_01.sql create mode 100644 libs/migrate/sql/repo_collaborator/repo_collaborator_up_01.sql create mode 100644 libs/migrate/sql/repo_commit/repo_commit_down_01.sql create mode 100644 libs/migrate/sql/repo_commit/repo_commit_up_01.sql create mode 100644 libs/migrate/sql/repo_fork/repo_fork_down_01.sql create mode 100644 libs/migrate/sql/repo_fork/repo_fork_up_01.sql create mode 100644 libs/migrate/sql/repo_history_name/repo_history_name_down_01.sql create mode 100644 libs/migrate/sql/repo_history_name/repo_history_name_up_01.sql create mode 100644 libs/migrate/sql/repo_hook/repo_hook_down_01.sql create mode 100644 libs/migrate/sql/repo_hook/repo_hook_up_01.sql create mode 100644 libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_down_01.sql create mode 100644 libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_up_01.sql create mode 100644 libs/migrate/sql/repo_lfs_object/repo_lfs_object_down_01.sql create mode 100644 libs/migrate/sql/repo_lfs_object/repo_lfs_object_up_01.sql create mode 100644 libs/migrate/sql/repo_lock/repo_lock_down_01.sql create mode 100644 libs/migrate/sql/repo_lock/repo_lock_up_01.sql create mode 100644 libs/migrate/sql/repo_star/repo_star_down_01.sql create mode 100644 libs/migrate/sql/repo_star/repo_star_up_01.sql create mode 100644 libs/migrate/sql/repo_tag/repo_tag_down_01.sql create mode 100644 libs/migrate/sql/repo_tag/repo_tag_up_01.sql create mode 100644 libs/migrate/sql/repo_upstream/repo_upstream_down_01.sql create mode 100644 libs/migrate/sql/repo_upstream/repo_upstream_up_01.sql create mode 100644 libs/migrate/sql/repo_watch/repo_watch_down_01.sql create mode 100644 libs/migrate/sql/repo_watch/repo_watch_up_01.sql create mode 100644 libs/migrate/sql/repo_webhook/repo_webhook_down_01.sql create mode 100644 libs/migrate/sql/repo_webhook/repo_webhook_up_01.sql create mode 100644 libs/migrate/sql/room/room_down_01.sql create mode 100644 libs/migrate/sql/room/room_up_01.sql create mode 100644 libs/migrate/sql/room_access/room_access_down_01.sql create mode 100644 libs/migrate/sql/room_access/room_access_up_01.sql create mode 100644 libs/migrate/sql/room_ai/room_ai_down_01.sql create mode 100644 libs/migrate/sql/room_ai/room_ai_up_01.sql create mode 100644 libs/migrate/sql/room_attachment/room_attachment_down_01.sql create mode 100644 libs/migrate/sql/room_attachment/room_attachment_up_01.sql create mode 100644 libs/migrate/sql/room_category/room_category_down_01.sql create mode 100644 libs/migrate/sql/room_category/room_category_up_01.sql create mode 100644 libs/migrate/sql/room_compact_summary/room_compact_summary_down_01.sql rename libs/migrate/sql/{room_compact_summary.sql => room_compact_summary/room_compact_summary_up_01.sql} (100%) create mode 100644 libs/migrate/sql/room_message/room_message_down_01.sql create mode 100644 libs/migrate/sql/room_message/room_message_up_01.sql create mode 100644 libs/migrate/sql/room_message_edit_history/room_message_edit_history_down_01.sql create mode 100644 libs/migrate/sql/room_message_edit_history/room_message_edit_history_up_01.sql create mode 100644 libs/migrate/sql/room_message_reaction/room_message_reaction_down_01.sql create mode 100644 libs/migrate/sql/room_message_reaction/room_message_reaction_up_01.sql create mode 100644 libs/migrate/sql/room_notifications/room_notifications_down_01.sql create mode 100644 libs/migrate/sql/room_notifications/room_notifications_up_01.sql create mode 100644 libs/migrate/sql/room_pin/room_pin_down_01.sql create mode 100644 libs/migrate/sql/room_pin/room_pin_up_01.sql create mode 100644 libs/migrate/sql/room_thread/room_thread_down_01.sql create mode 100644 libs/migrate/sql/room_thread/room_thread_up_01.sql create mode 100644 libs/migrate/sql/room_user_state/room_user_state_down_01.sql create mode 100644 libs/migrate/sql/room_user_state/room_user_state_up_01.sql create mode 100644 libs/migrate/sql/user/user_down_01.sql create mode 100644 libs/migrate/sql/user/user_up_01.sql create mode 100644 libs/migrate/sql/user_2fa/user_2fa_down_01.sql create mode 100644 libs/migrate/sql/user_2fa/user_2fa_up_01.sql create mode 100644 libs/migrate/sql/user_activity_log/user_activity_log_down_01.sql create mode 100644 libs/migrate/sql/user_activity_log/user_activity_log_up_01.sql create mode 100644 libs/migrate/sql/user_billing_history/user_billing_history_down_01.sql create mode 100644 libs/migrate/sql/user_billing_history/user_billing_history_up_01.sql create mode 100644 libs/migrate/sql/user_email/user_email_down_01.sql create mode 100644 libs/migrate/sql/user_email/user_email_up_01.sql create mode 100644 libs/migrate/sql/user_email_change/user_email_change_down_01.sql create mode 100644 libs/migrate/sql/user_email_change/user_email_change_up_01.sql create mode 100644 libs/migrate/sql/user_notification/user_notification_down_01.sql create mode 100644 libs/migrate/sql/user_notification/user_notification_up_01.sql create mode 100644 libs/migrate/sql/user_password/user_password_down_01.sql create mode 100644 libs/migrate/sql/user_password/user_password_up_01.sql create mode 100644 libs/migrate/sql/user_password_reset/user_password_reset_down_01.sql create mode 100644 libs/migrate/sql/user_password_reset/user_password_reset_up_01.sql create mode 100644 libs/migrate/sql/user_preferences/user_preferences_down_01.sql create mode 100644 libs/migrate/sql/user_preferences/user_preferences_up_01.sql create mode 100644 libs/migrate/sql/user_relation/user_relation_down_01.sql create mode 100644 libs/migrate/sql/user_relation/user_relation_up_01.sql create mode 100644 libs/migrate/sql/user_ssh_key/user_ssh_key_down_01.sql create mode 100644 libs/migrate/sql/user_ssh_key/user_ssh_key_up_01.sql create mode 100644 libs/migrate/sql/user_token/user_token_down_01.sql create mode 100644 libs/migrate/sql/user_token/user_token_up_01.sql create mode 100644 libs/migrate/sql/workspace/workspace_down_01.sql create mode 100644 libs/migrate/sql/workspace/workspace_up_01.sql create mode 100644 libs/migrate/sql/workspace_alert_config/workspace_alert_config_down_01.sql create mode 100644 libs/migrate/sql/workspace_alert_config/workspace_alert_config_up_01.sql create mode 100644 libs/migrate/sql/workspace_billing/workspace_billing_down_01.sql create mode 100644 libs/migrate/sql/workspace_billing/workspace_billing_up_01.sql create mode 100644 libs/migrate/sql/workspace_billing_history/workspace_billing_history_down_01.sql create mode 100644 libs/migrate/sql/workspace_billing_history/workspace_billing_history_up_01.sql create mode 100644 libs/migrate/sql/workspace_membership/workspace_membership_down_01.sql create mode 100644 libs/migrate/sql/workspace_membership/workspace_membership_up_01.sql delete mode 100644 libs/migrate/user_billing_history.rs diff --git a/libs/migrate/bootstrap.rs b/libs/migrate/bootstrap.rs new file mode 100644 index 0000000..c83a0ec --- /dev/null +++ b/libs/migrate/bootstrap.rs @@ -0,0 +1,28 @@ +use sea_orm_migration::prelude::*; + +pub struct Migration; + +impl MigrationName for Migration { + fn name(&self) -> &str { + "bootstrap" + } +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_unprepared(include_str!("sql/bootstrap/bootstrap_up_01.sql")) + .await?; + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .get_connection() + .execute_unprepared(include_str!("sql/bootstrap/bootstrap_down_01.sql")) + .await?; + Ok(()) + } +} diff --git a/libs/migrate/init.rs b/libs/migrate/init.rs deleted file mode 100644 index d3e2db6..0000000 --- a/libs/migrate/init.rs +++ /dev/null @@ -1,54 +0,0 @@ -//! SeaORM migration: create room_notifications table - -use sea_orm_migration::prelude::*; - -pub struct Migration; - -impl MigrationName for Migration { - fn name(&self) -> &str { - "init" - } -} - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - let sql = include_str!("sql/init.sql"); - super::execute_sql(manager, sql).await?; - let e = " -CREATE OR REPLACE FUNCTION room_message_tsv_trigger() -RETURNS trigger -LANGUAGE plpgsql -AS $function$ -BEGIN - NEW.content_tsv := to_tsvector('english', NEW.content); - RETURN NEW; -END; -$function$; -create or replace trigger room_message_tsv_update - before insert or update - on room_message - for each row -execute procedure room_message_tsv_trigger(); - DO -$$ - BEGIN - IF NOT EXISTS (SELECT 1 - FROM pg_type - WHERE typname = 'notification_type' - AND typtype = 'e') THEN - CREATE TYPE notification_type AS ENUM ( - 'mention', - 'invitation', - 'role_change', - 'room_created', - 'room_deleted', - 'system_announcement' - ); - END IF; - END -$$;"; - manager.get_connection().execute_unprepared(e).await?; - Ok(()) - } -} diff --git a/libs/migrate/lib.rs b/libs/migrate/lib.rs index 8ee8498..98e5343 100644 --- a/libs/migrate/lib.rs +++ b/libs/migrate/lib.rs @@ -35,23 +35,267 @@ mod tests { } } -pub struct Migrator; +macro_rules! define_sql_migrations { + ($( $module:ident => { name: $name:literal, up: $up:literal, down: $down:literal } ),+ $(,)?) => { + $( + pub mod $module { + use sea_orm_migration::prelude::*; -#[async_trait::async_trait] -impl MigratorTrait for Migrator { - fn migrations() -> Vec> { - vec![ - Box::new(init::Migration), - Box::new(room_compact_summary::Migration), - Box::new(user_billing_history::Migration), - Box::new(project_message_favorite::Migration), - Box::new(ai_subagent_session::Migration), - ] - } + pub struct Migration; + + impl MigrationName for Migration { + fn name(&self) -> &str { + $name + } + } + + #[async_trait::async_trait] + impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!($up); + super::execute_sql(manager, sql).await?; + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let sql = include_str!($down); + super::execute_sql(manager, sql).await?; + Ok(()) + } + } + } + )+ + + pub struct Migrator; + + #[async_trait::async_trait] + impl MigratorTrait for Migrator { + fn migrations() -> Vec> { + vec![ + Box::new(user::Migration), + Box::new(user_password::Migration), + Box::new(user_email::Migration), + Box::new(user_2fa::Migration), + Box::new(user_notification::Migration), + Box::new(user_preferences::Migration), + Box::new(user_password_reset::Migration), + Box::new(user_relation::Migration), + Box::new(user_ssh_key::Migration), + Box::new(user_token::Migration), + Box::new(user_activity_log::Migration), + Box::new(project_access_log::Migration), + Box::new(project_audit_log::Migration), + Box::new(project_billing::Migration), + Box::new(project_billing_history::Migration), + Box::new(project_follow::Migration), + Box::new(project_history_name::Migration), + Box::new(project_label::Migration), + Box::new(project_like::Migration), + Box::new(project_member_invitations::Migration), + Box::new(project_member_join_answers::Migration), + Box::new(project_member_join_request::Migration), + Box::new(project_member_join_settings::Migration), + Box::new(project_members::Migration), + Box::new(project_watch::Migration), + Box::new(repo::Migration), + Box::new(repo_branch::Migration), + Box::new(repo_branch_protect::Migration), + Box::new(repo_collaborator::Migration), + Box::new(repo_commit::Migration), + Box::new(repo_fork::Migration), + Box::new(repo_history_name::Migration), + Box::new(repo_hook::Migration), + Box::new(repo_lfs_lock::Migration), + Box::new(repo_lfs_object::Migration), + Box::new(repo_lock::Migration), + Box::new(repo_star::Migration), + Box::new(repo_tag::Migration), + Box::new(repo_upstream::Migration), + Box::new(repo_watch::Migration), + Box::new(repo_webhook::Migration), + Box::new(issue::Migration), + Box::new(issue_assignee::Migration), + Box::new(issue_comment::Migration), + Box::new(issue_comment_reaction::Migration), + Box::new(issue_label::Migration), + Box::new(issue_pull_request::Migration), + Box::new(issue_reaction::Migration), + Box::new(issue_repo::Migration), + Box::new(issue_subscriber::Migration), + Box::new(pull_request::Migration), + Box::new(pull_request_commit::Migration), + Box::new(pull_request_review::Migration), + Box::new(pull_request_review_comment::Migration), + Box::new(room_category::Migration), + Box::new(room::Migration), + Box::new(room_ai::Migration), + Box::new(room_message::Migration), + Box::new(room_pin::Migration), + Box::new(room_thread::Migration), + Box::new(ai_model_provider::Migration), + Box::new(ai_model::Migration), + Box::new(ai_model_version::Migration), + Box::new(ai_model_capability::Migration), + Box::new(ai_model_parameter_profile::Migration), + Box::new(ai_model_pricing::Migration), + Box::new(ai_session::Migration), + Box::new(ai_tool_call::Migration), + Box::new(ai_tool_auth::Migration), + Box::new(label::Migration), + Box::new(notify::Migration), + Box::new(room_notifications::Migration), + Box::new(user_email_change::Migration), + Box::new(project_activity::Migration), + Box::new(room_message_reaction::Migration), + Box::new(room_message_edit_history::Migration), + Box::new(project_board::Migration), + Box::new(project_board_column::Migration), + Box::new(project_board_card::Migration), + Box::new(pull_request_review_request::Migration), + Box::new(workspace::Migration), + Box::new(project::Migration), + Box::new(workspace_membership::Migration), + Box::new(workspace_billing::Migration), + Box::new(workspace_billing_history::Migration), + Box::new(project_skill::Migration), + Box::new(agent_task::Migration), + Box::new(admin_user::Migration), + Box::new(admin_role::Migration), + Box::new(admin_permission::Migration), + Box::new(admin_user_role::Migration), + Box::new(admin_role_permission::Migration), + Box::new(admin_audit_log::Migration), + Box::new(admin_api_token::Migration), + Box::new(workspace_alert_config::Migration), + Box::new(room_attachment::Migration), + Box::new(room_access::Migration), + Box::new(room_user_state::Migration), + Box::new(project_role_priority::Migration), + Box::new(ai_conversation::Migration), + Box::new(ai_message::Migration), + Box::new(ai_message_fork::Migration), + Box::new(ai_shared_conversation::Migration), + Box::new(ai_token_usage::Migration), + Box::new(room_compact_summary::Migration), + Box::new(user_billing_history::Migration), + Box::new(project_message_favorite::Migration), + Box::new(ai_subagent_session::Migration), + Box::new(bootstrap::Migration), + ] + } + } + }; } -pub mod ai_subagent_session; -pub mod init; -pub mod project_message_favorite; -pub mod room_compact_summary; -pub mod user_billing_history; +define_sql_migrations! { + user => { name: "user", up: "sql/user/user_up_01.sql", down: "sql/user/user_down_01.sql" }, + user_password => { name: "user_password", up: "sql/user_password/user_password_up_01.sql", down: "sql/user_password/user_password_down_01.sql" }, + user_email => { name: "user_email", up: "sql/user_email/user_email_up_01.sql", down: "sql/user_email/user_email_down_01.sql" }, + user_2fa => { name: "user_2fa", up: "sql/user_2fa/user_2fa_up_01.sql", down: "sql/user_2fa/user_2fa_down_01.sql" }, + user_notification => { name: "user_notification", up: "sql/user_notification/user_notification_up_01.sql", down: "sql/user_notification/user_notification_down_01.sql" }, + user_preferences => { name: "user_preferences", up: "sql/user_preferences/user_preferences_up_01.sql", down: "sql/user_preferences/user_preferences_down_01.sql" }, + user_password_reset => { name: "user_password_reset", up: "sql/user_password_reset/user_password_reset_up_01.sql", down: "sql/user_password_reset/user_password_reset_down_01.sql" }, + user_relation => { name: "user_relation", up: "sql/user_relation/user_relation_up_01.sql", down: "sql/user_relation/user_relation_down_01.sql" }, + user_ssh_key => { name: "user_ssh_key", up: "sql/user_ssh_key/user_ssh_key_up_01.sql", down: "sql/user_ssh_key/user_ssh_key_down_01.sql" }, + user_token => { name: "user_token", up: "sql/user_token/user_token_up_01.sql", down: "sql/user_token/user_token_down_01.sql" }, + user_activity_log => { name: "user_activity_log", up: "sql/user_activity_log/user_activity_log_up_01.sql", down: "sql/user_activity_log/user_activity_log_down_01.sql" }, + project_access_log => { name: "project_access_log", up: "sql/project_access_log/project_access_log_up_01.sql", down: "sql/project_access_log/project_access_log_down_01.sql" }, + project_audit_log => { name: "project_audit_log", up: "sql/project_audit_log/project_audit_log_up_01.sql", down: "sql/project_audit_log/project_audit_log_down_01.sql" }, + project_billing => { name: "project_billing", up: "sql/project_billing/project_billing_up_01.sql", down: "sql/project_billing/project_billing_down_01.sql" }, + project_billing_history => { name: "project_billing_history", up: "sql/project_billing_history/project_billing_history_up_01.sql", down: "sql/project_billing_history/project_billing_history_down_01.sql" }, + project_follow => { name: "project_follow", up: "sql/project_follow/project_follow_up_01.sql", down: "sql/project_follow/project_follow_down_01.sql" }, + project_history_name => { name: "project_history_name", up: "sql/project_history_name/project_history_name_up_01.sql", down: "sql/project_history_name/project_history_name_down_01.sql" }, + project_label => { name: "project_label", up: "sql/project_label/project_label_up_01.sql", down: "sql/project_label/project_label_down_01.sql" }, + project_like => { name: "project_like", up: "sql/project_like/project_like_up_01.sql", down: "sql/project_like/project_like_down_01.sql" }, + project_member_invitations => { name: "project_member_invitations", up: "sql/project_member_invitations/project_member_invitations_up_01.sql", down: "sql/project_member_invitations/project_member_invitations_down_01.sql" }, + project_member_join_answers => { name: "project_member_join_answers", up: "sql/project_member_join_answers/project_member_join_answers_up_01.sql", down: "sql/project_member_join_answers/project_member_join_answers_down_01.sql" }, + project_member_join_request => { name: "project_member_join_request", up: "sql/project_member_join_request/project_member_join_request_up_01.sql", down: "sql/project_member_join_request/project_member_join_request_down_01.sql" }, + project_member_join_settings => { name: "project_member_join_settings", up: "sql/project_member_join_settings/project_member_join_settings_up_01.sql", down: "sql/project_member_join_settings/project_member_join_settings_down_01.sql" }, + project_members => { name: "project_members", up: "sql/project_members/project_members_up_01.sql", down: "sql/project_members/project_members_down_01.sql" }, + project_watch => { name: "project_watch", up: "sql/project_watch/project_watch_up_01.sql", down: "sql/project_watch/project_watch_down_01.sql" }, + repo => { name: "repo", up: "sql/repo/repo_up_01.sql", down: "sql/repo/repo_down_01.sql" }, + repo_branch => { name: "repo_branch", up: "sql/repo_branch/repo_branch_up_01.sql", down: "sql/repo_branch/repo_branch_down_01.sql" }, + repo_branch_protect => { name: "repo_branch_protect", up: "sql/repo_branch_protect/repo_branch_protect_up_01.sql", down: "sql/repo_branch_protect/repo_branch_protect_down_01.sql" }, + repo_collaborator => { name: "repo_collaborator", up: "sql/repo_collaborator/repo_collaborator_up_01.sql", down: "sql/repo_collaborator/repo_collaborator_down_01.sql" }, + repo_commit => { name: "repo_commit", up: "sql/repo_commit/repo_commit_up_01.sql", down: "sql/repo_commit/repo_commit_down_01.sql" }, + repo_fork => { name: "repo_fork", up: "sql/repo_fork/repo_fork_up_01.sql", down: "sql/repo_fork/repo_fork_down_01.sql" }, + repo_history_name => { name: "repo_history_name", up: "sql/repo_history_name/repo_history_name_up_01.sql", down: "sql/repo_history_name/repo_history_name_down_01.sql" }, + repo_hook => { name: "repo_hook", up: "sql/repo_hook/repo_hook_up_01.sql", down: "sql/repo_hook/repo_hook_down_01.sql" }, + repo_lfs_lock => { name: "repo_lfs_lock", up: "sql/repo_lfs_lock/repo_lfs_lock_up_01.sql", down: "sql/repo_lfs_lock/repo_lfs_lock_down_01.sql" }, + repo_lfs_object => { name: "repo_lfs_object", up: "sql/repo_lfs_object/repo_lfs_object_up_01.sql", down: "sql/repo_lfs_object/repo_lfs_object_down_01.sql" }, + repo_lock => { name: "repo_lock", up: "sql/repo_lock/repo_lock_up_01.sql", down: "sql/repo_lock/repo_lock_down_01.sql" }, + repo_star => { name: "repo_star", up: "sql/repo_star/repo_star_up_01.sql", down: "sql/repo_star/repo_star_down_01.sql" }, + repo_tag => { name: "repo_tag", up: "sql/repo_tag/repo_tag_up_01.sql", down: "sql/repo_tag/repo_tag_down_01.sql" }, + repo_upstream => { name: "repo_upstream", up: "sql/repo_upstream/repo_upstream_up_01.sql", down: "sql/repo_upstream/repo_upstream_down_01.sql" }, + repo_watch => { name: "repo_watch", up: "sql/repo_watch/repo_watch_up_01.sql", down: "sql/repo_watch/repo_watch_down_01.sql" }, + repo_webhook => { name: "repo_webhook", up: "sql/repo_webhook/repo_webhook_up_01.sql", down: "sql/repo_webhook/repo_webhook_down_01.sql" }, + issue => { name: "issue", up: "sql/issue/issue_up_01.sql", down: "sql/issue/issue_down_01.sql" }, + issue_assignee => { name: "issue_assignee", up: "sql/issue_assignee/issue_assignee_up_01.sql", down: "sql/issue_assignee/issue_assignee_down_01.sql" }, + issue_comment => { name: "issue_comment", up: "sql/issue_comment/issue_comment_up_01.sql", down: "sql/issue_comment/issue_comment_down_01.sql" }, + issue_comment_reaction => { name: "issue_comment_reaction", up: "sql/issue_comment_reaction/issue_comment_reaction_up_01.sql", down: "sql/issue_comment_reaction/issue_comment_reaction_down_01.sql" }, + issue_label => { name: "issue_label", up: "sql/issue_label/issue_label_up_01.sql", down: "sql/issue_label/issue_label_down_01.sql" }, + issue_pull_request => { name: "issue_pull_request", up: "sql/issue_pull_request/issue_pull_request_up_01.sql", down: "sql/issue_pull_request/issue_pull_request_down_01.sql" }, + issue_reaction => { name: "issue_reaction", up: "sql/issue_reaction/issue_reaction_up_01.sql", down: "sql/issue_reaction/issue_reaction_down_01.sql" }, + issue_repo => { name: "issue_repo", up: "sql/issue_repo/issue_repo_up_01.sql", down: "sql/issue_repo/issue_repo_down_01.sql" }, + issue_subscriber => { name: "issue_subscriber", up: "sql/issue_subscriber/issue_subscriber_up_01.sql", down: "sql/issue_subscriber/issue_subscriber_down_01.sql" }, + pull_request => { name: "pull_request", up: "sql/pull_request/pull_request_up_01.sql", down: "sql/pull_request/pull_request_down_01.sql" }, + pull_request_commit => { name: "pull_request_commit", up: "sql/pull_request_commit/pull_request_commit_up_01.sql", down: "sql/pull_request_commit/pull_request_commit_down_01.sql" }, + pull_request_review => { name: "pull_request_review", up: "sql/pull_request_review/pull_request_review_up_01.sql", down: "sql/pull_request_review/pull_request_review_down_01.sql" }, + pull_request_review_comment => { name: "pull_request_review_comment", up: "sql/pull_request_review_comment/pull_request_review_comment_up_01.sql", down: "sql/pull_request_review_comment/pull_request_review_comment_down_01.sql" }, + room_category => { name: "room_category", up: "sql/room_category/room_category_up_01.sql", down: "sql/room_category/room_category_down_01.sql" }, + room => { name: "room", up: "sql/room/room_up_01.sql", down: "sql/room/room_down_01.sql" }, + room_ai => { name: "room_ai", up: "sql/room_ai/room_ai_up_01.sql", down: "sql/room_ai/room_ai_down_01.sql" }, + room_message => { name: "room_message", up: "sql/room_message/room_message_up_01.sql", down: "sql/room_message/room_message_down_01.sql" }, + room_pin => { name: "room_pin", up: "sql/room_pin/room_pin_up_01.sql", down: "sql/room_pin/room_pin_down_01.sql" }, + room_thread => { name: "room_thread", up: "sql/room_thread/room_thread_up_01.sql", down: "sql/room_thread/room_thread_down_01.sql" }, + ai_model_provider => { name: "ai_model_provider", up: "sql/ai_model_provider/ai_model_provider_up_01.sql", down: "sql/ai_model_provider/ai_model_provider_down_01.sql" }, + ai_model => { name: "ai_model", up: "sql/ai_model/ai_model_up_01.sql", down: "sql/ai_model/ai_model_down_01.sql" }, + ai_model_version => { name: "ai_model_version", up: "sql/ai_model_version/ai_model_version_up_01.sql", down: "sql/ai_model_version/ai_model_version_down_01.sql" }, + ai_model_capability => { name: "ai_model_capability", up: "sql/ai_model_capability/ai_model_capability_up_01.sql", down: "sql/ai_model_capability/ai_model_capability_down_01.sql" }, + ai_model_parameter_profile => { name: "ai_model_parameter_profile", up: "sql/ai_model_parameter_profile/ai_model_parameter_profile_up_01.sql", down: "sql/ai_model_parameter_profile/ai_model_parameter_profile_down_01.sql" }, + ai_model_pricing => { name: "ai_model_pricing", up: "sql/ai_model_pricing/ai_model_pricing_up_01.sql", down: "sql/ai_model_pricing/ai_model_pricing_down_01.sql" }, + ai_session => { name: "ai_session", up: "sql/ai_session/ai_session_up_01.sql", down: "sql/ai_session/ai_session_down_01.sql" }, + ai_tool_call => { name: "ai_tool_call", up: "sql/ai_tool_call/ai_tool_call_up_01.sql", down: "sql/ai_tool_call/ai_tool_call_down_01.sql" }, + ai_tool_auth => { name: "ai_tool_auth", up: "sql/ai_tool_auth/ai_tool_auth_up_01.sql", down: "sql/ai_tool_auth/ai_tool_auth_down_01.sql" }, + label => { name: "label", up: "sql/label/label_up_01.sql", down: "sql/label/label_down_01.sql" }, + notify => { name: "notify", up: "sql/notify/notify_up_01.sql", down: "sql/notify/notify_down_01.sql" }, + room_notifications => { name: "room_notifications", up: "sql/room_notifications/room_notifications_up_01.sql", down: "sql/room_notifications/room_notifications_down_01.sql" }, + user_email_change => { name: "user_email_change", up: "sql/user_email_change/user_email_change_up_01.sql", down: "sql/user_email_change/user_email_change_down_01.sql" }, + project_activity => { name: "project_activity", up: "sql/project_activity/project_activity_up_01.sql", down: "sql/project_activity/project_activity_down_01.sql" }, + room_message_reaction => { name: "room_message_reaction", up: "sql/room_message_reaction/room_message_reaction_up_01.sql", down: "sql/room_message_reaction/room_message_reaction_down_01.sql" }, + room_message_edit_history => { name: "room_message_edit_history", up: "sql/room_message_edit_history/room_message_edit_history_up_01.sql", down: "sql/room_message_edit_history/room_message_edit_history_down_01.sql" }, + project_board => { name: "project_board", up: "sql/project_board/project_board_up_01.sql", down: "sql/project_board/project_board_down_01.sql" }, + project_board_column => { name: "project_board_column", up: "sql/project_board_column/project_board_column_up_01.sql", down: "sql/project_board_column/project_board_column_down_01.sql" }, + project_board_card => { name: "project_board_card", up: "sql/project_board_card/project_board_card_up_01.sql", down: "sql/project_board_card/project_board_card_down_01.sql" }, + pull_request_review_request => { name: "pull_request_review_request", up: "sql/pull_request_review_request/pull_request_review_request_up_01.sql", down: "sql/pull_request_review_request/pull_request_review_request_down_01.sql" }, + workspace => { name: "workspace", up: "sql/workspace/workspace_up_01.sql", down: "sql/workspace/workspace_down_01.sql" }, + project => { name: "project", up: "sql/project/project_up_01.sql", down: "sql/project/project_down_01.sql" }, + workspace_membership => { name: "workspace_membership", up: "sql/workspace_membership/workspace_membership_up_01.sql", down: "sql/workspace_membership/workspace_membership_down_01.sql" }, + workspace_billing => { name: "workspace_billing", up: "sql/workspace_billing/workspace_billing_up_01.sql", down: "sql/workspace_billing/workspace_billing_down_01.sql" }, + workspace_billing_history => { name: "workspace_billing_history", up: "sql/workspace_billing_history/workspace_billing_history_up_01.sql", down: "sql/workspace_billing_history/workspace_billing_history_down_01.sql" }, + project_skill => { name: "project_skill", up: "sql/project_skill/project_skill_up_01.sql", down: "sql/project_skill/project_skill_down_01.sql" }, + agent_task => { name: "agent_task", up: "sql/agent_task/agent_task_up_01.sql", down: "sql/agent_task/agent_task_down_01.sql" }, + admin_user => { name: "admin_user", up: "sql/admin_user/admin_user_up_01.sql", down: "sql/admin_user/admin_user_down_01.sql" }, + admin_role => { name: "admin_role", up: "sql/admin_role/admin_role_up_01.sql", down: "sql/admin_role/admin_role_down_01.sql" }, + admin_permission => { name: "admin_permission", up: "sql/admin_permission/admin_permission_up_01.sql", down: "sql/admin_permission/admin_permission_down_01.sql" }, + admin_user_role => { name: "admin_user_role", up: "sql/admin_user_role/admin_user_role_up_01.sql", down: "sql/admin_user_role/admin_user_role_down_01.sql" }, + admin_role_permission => { name: "admin_role_permission", up: "sql/admin_role_permission/admin_role_permission_up_01.sql", down: "sql/admin_role_permission/admin_role_permission_down_01.sql" }, + admin_audit_log => { name: "admin_audit_log", up: "sql/admin_audit_log/admin_audit_log_up_01.sql", down: "sql/admin_audit_log/admin_audit_log_down_01.sql" }, + admin_api_token => { name: "admin_api_token", up: "sql/admin_api_token/admin_api_token_up_01.sql", down: "sql/admin_api_token/admin_api_token_down_01.sql" }, + workspace_alert_config => { name: "workspace_alert_config", up: "sql/workspace_alert_config/workspace_alert_config_up_01.sql", down: "sql/workspace_alert_config/workspace_alert_config_down_01.sql" }, + room_attachment => { name: "room_attachment", up: "sql/room_attachment/room_attachment_up_01.sql", down: "sql/room_attachment/room_attachment_down_01.sql" }, + room_access => { name: "room_access", up: "sql/room_access/room_access_up_01.sql", down: "sql/room_access/room_access_down_01.sql" }, + room_user_state => { name: "room_user_state", up: "sql/room_user_state/room_user_state_up_01.sql", down: "sql/room_user_state/room_user_state_down_01.sql" }, + project_role_priority => { name: "project_role_priority", up: "sql/project_role_priority/project_role_priority_up_01.sql", down: "sql/project_role_priority/project_role_priority_down_01.sql" }, + ai_conversation => { name: "ai_conversation", up: "sql/ai_conversation/ai_conversation_up_01.sql", down: "sql/ai_conversation/ai_conversation_down_01.sql" }, + ai_message => { name: "ai_message", up: "sql/ai_message/ai_message_up_01.sql", down: "sql/ai_message/ai_message_down_01.sql" }, + ai_message_fork => { name: "ai_message_fork", up: "sql/ai_message_fork/ai_message_fork_up_01.sql", down: "sql/ai_message_fork/ai_message_fork_down_01.sql" }, + ai_shared_conversation => { name: "ai_shared_conversation", up: "sql/ai_shared_conversation/ai_shared_conversation_up_01.sql", down: "sql/ai_shared_conversation/ai_shared_conversation_down_01.sql" }, + ai_token_usage => { name: "ai_token_usage", up: "sql/ai_token_usage/ai_token_usage_up_01.sql", down: "sql/ai_token_usage/ai_token_usage_down_01.sql" }, + room_compact_summary => { name: "room_compact_summary", up: "sql/room_compact_summary/room_compact_summary_up_01.sql", down: "sql/room_compact_summary/room_compact_summary_down_01.sql" }, + user_billing_history => { name: "user_billing_history", up: "sql/user_billing_history/user_billing_history_up_01.sql", down: "sql/user_billing_history/user_billing_history_down_01.sql" }, + project_message_favorite => { name: "project_message_favorite", up: "sql/project_message_favorite/project_message_favorite_up_01.sql", down: "sql/project_message_favorite/project_message_favorite_down_01.sql" }, + ai_subagent_session => { name: "ai_subagent_session", up: "sql/ai_subagent_session/ai_subagent_session_up_01.sql", down: "sql/ai_subagent_session/ai_subagent_session_down_01.sql" }, +} + +pub mod bootstrap; diff --git a/libs/migrate/project_message_favorite.rs b/libs/migrate/project_message_favorite.rs deleted file mode 100644 index 1d81e45..0000000 --- a/libs/migrate/project_message_favorite.rs +++ /dev/null @@ -1,57 +0,0 @@ -use sea_orm_migration::prelude::*; - -pub struct Migration; - -impl MigrationName for Migration { - fn name(&self) -> &str { - "project_message_favorite" - } -} - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" -create table if not exists project_message_favorite -( - uid uuid not null - primary key, - project uuid not null, - room uuid not null, - message uuid not null, - user_uuid uuid not null, - created_at timestamp with time zone not null -); - -create unique index if not exists idx_project_message_favorite_user_message - on project_message_favorite (user_uuid, message); - -create index if not exists idx_project_message_favorite_project_user - on project_message_favorite (project, user_uuid, created_at desc); - -create index if not exists idx_project_message_favorite_room - on project_message_favorite (room); -"#, - ) - .await?; - Ok(()) - } - - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" -drop index if exists idx_project_message_favorite_room; -drop index if exists idx_project_message_favorite_project_user; -drop index if exists idx_project_message_favorite_user_message; -drop table if exists project_message_favorite; -"#, - ) - .await?; - Ok(()) - } -} diff --git a/libs/migrate/sql/admin_api_token/admin_api_token_down_01.sql b/libs/migrate/sql/admin_api_token/admin_api_token_down_01.sql new file mode 100644 index 0000000..2e52e2c --- /dev/null +++ b/libs/migrate/sql/admin_api_token/admin_api_token_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_admin_api_token_hash; +DROP TABLE IF EXISTS admin_api_token; diff --git a/libs/migrate/sql/admin_api_token/admin_api_token_up_01.sql b/libs/migrate/sql/admin_api_token/admin_api_token_up_01.sql new file mode 100644 index 0000000..3c8507b --- /dev/null +++ b/libs/migrate/sql/admin_api_token/admin_api_token_up_01.sql @@ -0,0 +1,22 @@ +create table if not exists admin_api_token +( + id serial + primary key, + name varchar(255) not null, + token_hash varchar(64) not null + unique, + token_prefix varchar(32) not null, + permissions text[] default '{}'::text[] not null, + created_by integer not null + references admin_user + on delete set null, + created_at timestamp with time zone default now() not null, + last_used_at timestamp with time zone, + expires_at timestamp with time zone, + is_active boolean default true not null +); + +comment on table admin_api_token is 'Admin API Token for programmatic access'; + +create index if not exists idx_admin_api_token_hash + on admin_api_token (token_hash); diff --git a/libs/migrate/sql/admin_audit_log/admin_audit_log_down_01.sql b/libs/migrate/sql/admin_audit_log/admin_audit_log_down_01.sql new file mode 100644 index 0000000..935b134 --- /dev/null +++ b/libs/migrate/sql/admin_audit_log/admin_audit_log_down_01.sql @@ -0,0 +1,5 @@ +DROP INDEX IF EXISTS idx_admin_audit_log_resource; +DROP INDEX IF EXISTS idx_admin_audit_log_action; +DROP INDEX IF EXISTS idx_admin_audit_log_created_at; +DROP INDEX IF EXISTS idx_admin_audit_log_user_id; +DROP TABLE IF EXISTS admin_audit_log; diff --git a/libs/migrate/sql/admin_audit_log/admin_audit_log_up_01.sql b/libs/migrate/sql/admin_audit_log/admin_audit_log_up_01.sql new file mode 100644 index 0000000..4bdf8cf --- /dev/null +++ b/libs/migrate/sql/admin_audit_log/admin_audit_log_up_01.sql @@ -0,0 +1,28 @@ +create table if not exists admin_audit_log +( + id bigserial + primary key, + user_id integer not null, + username varchar(255) not null, + action varchar(50) not null, + resource varchar(255) not null, + resource_id varchar(255), + request_params jsonb, + ip_address varchar(255), + user_agent text, + result varchar(20) default 'success'::character varying not null, + error_message text, + created_at timestamp with time zone default now() not null +); + +create index if not exists idx_admin_audit_log_user_id + on admin_audit_log (user_id); + +create index if not exists idx_admin_audit_log_created_at + on admin_audit_log (created_at desc); + +create index if not exists idx_admin_audit_log_action + on admin_audit_log (action); + +create index if not exists idx_admin_audit_log_resource + on admin_audit_log (resource); diff --git a/libs/migrate/sql/admin_permission/admin_permission_down_01.sql b/libs/migrate/sql/admin_permission/admin_permission_down_01.sql new file mode 100644 index 0000000..05f26b4 --- /dev/null +++ b/libs/migrate/sql/admin_permission/admin_permission_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS admin_permission; diff --git a/libs/migrate/sql/admin_permission/admin_permission_up_01.sql b/libs/migrate/sql/admin_permission/admin_permission_up_01.sql new file mode 100644 index 0000000..5aee6c1 --- /dev/null +++ b/libs/migrate/sql/admin_permission/admin_permission_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists admin_permission +( + id serial + primary key, + name varchar(255) not null, + code varchar(255) not null + unique, + description text, + created_at timestamp with time zone default now() not null +); diff --git a/libs/migrate/sql/admin_role/admin_role_down_01.sql b/libs/migrate/sql/admin_role/admin_role_down_01.sql new file mode 100644 index 0000000..866a0ab --- /dev/null +++ b/libs/migrate/sql/admin_role/admin_role_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS admin_role; diff --git a/libs/migrate/sql/admin_role/admin_role_up_01.sql b/libs/migrate/sql/admin_role/admin_role_up_01.sql new file mode 100644 index 0000000..e397d75 --- /dev/null +++ b/libs/migrate/sql/admin_role/admin_role_up_01.sql @@ -0,0 +1,9 @@ +create table if not exists admin_role +( + id serial + primary key, + name varchar(255) not null + unique, + description text, + created_at timestamp with time zone default now() not null +); diff --git a/libs/migrate/sql/admin_role_permission/admin_role_permission_down_01.sql b/libs/migrate/sql/admin_role_permission/admin_role_permission_down_01.sql new file mode 100644 index 0000000..1561786 --- /dev/null +++ b/libs/migrate/sql/admin_role_permission/admin_role_permission_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS admin_role_permission; diff --git a/libs/migrate/sql/admin_role_permission/admin_role_permission_up_01.sql b/libs/migrate/sql/admin_role_permission/admin_role_permission_up_01.sql new file mode 100644 index 0000000..cf3910e --- /dev/null +++ b/libs/migrate/sql/admin_role_permission/admin_role_permission_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists admin_role_permission +( + role_id integer not null + references admin_role + on delete cascade, + permission_id integer not null + references admin_permission + on delete cascade, + primary key (role_id, permission_id) +); diff --git a/libs/migrate/sql/admin_user/admin_user_down_01.sql b/libs/migrate/sql/admin_user/admin_user_down_01.sql new file mode 100644 index 0000000..84d36bb --- /dev/null +++ b/libs/migrate/sql/admin_user/admin_user_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_admin_user_username; +DROP TABLE IF EXISTS admin_user; diff --git a/libs/migrate/sql/admin_user/admin_user_up_01.sql b/libs/migrate/sql/admin_user/admin_user_up_01.sql new file mode 100644 index 0000000..1aae385 --- /dev/null +++ b/libs/migrate/sql/admin_user/admin_user_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists admin_user +( + id serial + primary key, + username varchar(255) not null + unique, + password_hash varchar(255) not null, + is_active boolean default true not null, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null +); + +create index if not exists idx_admin_user_username + on admin_user (username); diff --git a/libs/migrate/sql/admin_user_role/admin_user_role_down_01.sql b/libs/migrate/sql/admin_user_role/admin_user_role_down_01.sql new file mode 100644 index 0000000..2086b16 --- /dev/null +++ b/libs/migrate/sql/admin_user_role/admin_user_role_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS admin_user_role; diff --git a/libs/migrate/sql/admin_user_role/admin_user_role_up_01.sql b/libs/migrate/sql/admin_user_role/admin_user_role_up_01.sql new file mode 100644 index 0000000..69a9cdb --- /dev/null +++ b/libs/migrate/sql/admin_user_role/admin_user_role_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists admin_user_role +( + user_id integer not null + references admin_user + on delete cascade, + role_id integer not null + references admin_role + on delete cascade, + primary key (user_id, role_id) +); diff --git a/libs/migrate/sql/agent_task/agent_task_down_01.sql b/libs/migrate/sql/agent_task/agent_task_down_01.sql new file mode 100644 index 0000000..ce375d3 --- /dev/null +++ b/libs/migrate/sql/agent_task/agent_task_down_01.sql @@ -0,0 +1,8 @@ +DROP INDEX IF EXISTS idx_agent_task_retry_count; +DROP INDEX IF EXISTS idx_agent_task_issue; +DROP INDEX IF EXISTS idx_agent_task_created_at; +DROP INDEX IF EXISTS idx_agent_task_created_by; +DROP INDEX IF EXISTS idx_agent_task_status; +DROP INDEX IF EXISTS idx_agent_task_parent; +DROP INDEX IF EXISTS idx_agent_task_project; +DROP TABLE IF EXISTS agent_task; diff --git a/libs/migrate/sql/agent_task/agent_task_up_01.sql b/libs/migrate/sql/agent_task/agent_task_up_01.sql new file mode 100644 index 0000000..0408a45 --- /dev/null +++ b/libs/migrate/sql/agent_task/agent_task_up_01.sql @@ -0,0 +1,45 @@ +create table if not exists agent_task +( + id bigserial + primary key, + project_uuid uuid not null, + parent_id bigint + constraint fk_agent_task_parent + references agent_task + on delete set null, + agent_type varchar(20) default 'react'::character varying not null, + status varchar(20) default 'pending'::character varying not null, + title varchar(255), + input text not null, + output text, + error text, + created_by uuid, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null, + started_at timestamp with time zone, + done_at timestamp with time zone, + progress varchar(255), + issue_id uuid, + retry_count integer default 0 +); + +create index if not exists idx_agent_task_project + on agent_task (project_uuid); + +create index if not exists idx_agent_task_parent + on agent_task (parent_id); + +create index if not exists idx_agent_task_status + on agent_task (status); + +create index if not exists idx_agent_task_created_by + on agent_task (created_by); + +create index if not exists idx_agent_task_created_at + on agent_task (created_at); + +create index if not exists idx_agent_task_issue + on agent_task (issue_id); + +create index if not exists idx_agent_task_retry_count + on agent_task (retry_count); diff --git a/libs/migrate/sql/ai_conversation/ai_conversation_down_01.sql b/libs/migrate/sql/ai_conversation/ai_conversation_down_01.sql new file mode 100644 index 0000000..25ff6f5 --- /dev/null +++ b/libs/migrate/sql/ai_conversation/ai_conversation_down_01.sql @@ -0,0 +1,8 @@ +DROP INDEX IF EXISTS idx_ai_conv_project_uid; +DROP INDEX IF EXISTS idx_ai_conv_access_vis; +DROP INDEX IF EXISTS idx_ai_conv_project_created; +DROP INDEX IF EXISTS idx_ai_conv_user_created; +DROP INDEX IF EXISTS idx_ai_conv_scope; +DROP INDEX IF EXISTS idx_ai_conv_project_id; +DROP INDEX IF EXISTS idx_ai_conv_user_id; +DROP TABLE IF EXISTS ai_conversation; diff --git a/libs/migrate/sql/ai_conversation/ai_conversation_up_01.sql b/libs/migrate/sql/ai_conversation/ai_conversation_up_01.sql new file mode 100644 index 0000000..d21c8af --- /dev/null +++ b/libs/migrate/sql/ai_conversation/ai_conversation_up_01.sql @@ -0,0 +1,49 @@ +create table if not exists ai_conversation +( + id uuid default gen_random_uuid() not null + primary key, + user_id uuid not null, + project_id uuid + constraint fk_ai_conv_project + references project + on delete cascade, + scope varchar(16) not null, + title varchar(512), + model varchar(128) default 'gpt-4'::character varying not null, + model_config jsonb, + status varchar(32) default 'active'::character varying not null, + root_message_id uuid, + fork_count integer default 0 not null, + is_shared boolean default false not null, + message_count integer default 0 not null, + token_usage_total integer, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null, + access_visibility varchar(32) default 'owner'::character varying not null, + can_ask varchar(32) default 'owner'::character varying not null, + project_uid integer, + model_uid uuid, + model_name varchar(256) +); + +create index if not exists idx_ai_conv_user_id + on ai_conversation (user_id); + +create index if not exists idx_ai_conv_project_id + on ai_conversation (project_id); + +create index if not exists idx_ai_conv_scope + on ai_conversation (scope); + +create index if not exists idx_ai_conv_user_created + on ai_conversation (user_id asc, created_at desc); + +create index if not exists idx_ai_conv_project_created + on ai_conversation (project_id asc, created_at desc); + +create index if not exists idx_ai_conv_access_vis + on ai_conversation (access_visibility); + +create index if not exists idx_ai_conv_project_uid + on ai_conversation (project_id, project_uid) + where (project_uid IS NOT NULL); diff --git a/libs/migrate/sql/ai_message/ai_message_down_01.sql b/libs/migrate/sql/ai_message/ai_message_down_01.sql new file mode 100644 index 0000000..f770d24 --- /dev/null +++ b/libs/migrate/sql/ai_message/ai_message_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_ai_msg_parent; +DROP INDEX IF EXISTS idx_ai_msg_conv; +DROP TABLE IF EXISTS ai_message; diff --git a/libs/migrate/sql/ai_message/ai_message_up_01.sql b/libs/migrate/sql/ai_message/ai_message_up_01.sql new file mode 100644 index 0000000..c0d88cf --- /dev/null +++ b/libs/migrate/sql/ai_message/ai_message_up_01.sql @@ -0,0 +1,30 @@ +create table if not exists ai_message +( + id uuid default gen_random_uuid() not null + primary key, + conversation_id uuid not null + constraint fk_ai_msg_conv + references ai_conversation + on delete cascade, + parent_message_id uuid + constraint fk_ai_msg_parent + references ai_message + on delete set null, + role varchar(16) not null, + content jsonb not null, + model varchar(128), + is_fork_origin boolean default false not null, + stop_reason varchar(32), + input_tokens integer, + output_tokens integer, + latency_ms integer, + metadata jsonb, + room_id uuid, + created_at timestamp with time zone default now() not null +); + +create index if not exists idx_ai_msg_conv + on ai_message (conversation_id, created_at); + +create index if not exists idx_ai_msg_parent + on ai_message (parent_message_id); diff --git a/libs/migrate/sql/ai_message_fork/ai_message_fork_down_01.sql b/libs/migrate/sql/ai_message_fork/ai_message_fork_down_01.sql new file mode 100644 index 0000000..3df2611 --- /dev/null +++ b/libs/migrate/sql/ai_message_fork/ai_message_fork_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_ai_fork_fork; +DROP INDEX IF EXISTS idx_ai_fork_source; +DROP TABLE IF EXISTS ai_message_fork; diff --git a/libs/migrate/sql/ai_message_fork/ai_message_fork_up_01.sql b/libs/migrate/sql/ai_message_fork/ai_message_fork_up_01.sql new file mode 100644 index 0000000..b7db7b6 --- /dev/null +++ b/libs/migrate/sql/ai_message_fork/ai_message_fork_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists ai_message_fork +( + id uuid default gen_random_uuid() not null + primary key, + source_message_id uuid not null + constraint fk_ai_fork_source + references ai_message + on delete cascade, + fork_message_id uuid not null + constraint fk_ai_fork_fork + references ai_message + on delete cascade, + created_at timestamp with time zone default now() not null +); + +create index if not exists idx_ai_fork_source + on ai_message_fork (source_message_id); + +create index if not exists idx_ai_fork_fork + on ai_message_fork (fork_message_id); diff --git a/libs/migrate/sql/ai_model/ai_model_down_01.sql b/libs/migrate/sql/ai_model/ai_model_down_01.sql new file mode 100644 index 0000000..e172e66 --- /dev/null +++ b/libs/migrate/sql/ai_model/ai_model_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_model_provider_id; +DROP TABLE IF EXISTS ai_model; diff --git a/libs/migrate/sql/ai_model/ai_model_up_01.sql b/libs/migrate/sql/ai_model/ai_model_up_01.sql new file mode 100644 index 0000000..4a85064 --- /dev/null +++ b/libs/migrate/sql/ai_model/ai_model_up_01.sql @@ -0,0 +1,19 @@ +create table if not exists ai_model +( + id uuid not null + primary key, + provider_id uuid not null, + name varchar(255) not null, + modality varchar(255) not null, + capability varchar(255) not null, + context_length bigint not null, + max_output_tokens bigint, + training_cutoff timestamp with time zone, + is_open_source boolean default false not null, + status varchar(255) not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_ai_model_provider_id + on ai_model (provider_id); diff --git a/libs/migrate/sql/ai_model_capability/ai_model_capability_down_01.sql b/libs/migrate/sql/ai_model_capability/ai_model_capability_down_01.sql new file mode 100644 index 0000000..d895ce0 --- /dev/null +++ b/libs/migrate/sql/ai_model_capability/ai_model_capability_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_model_capability_model_version_id; +DROP TABLE IF EXISTS ai_model_capability; diff --git a/libs/migrate/sql/ai_model_capability/ai_model_capability_up_01.sql b/libs/migrate/sql/ai_model_capability/ai_model_capability_up_01.sql new file mode 100644 index 0000000..ee38ef0 --- /dev/null +++ b/libs/migrate/sql/ai_model_capability/ai_model_capability_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists ai_model_capability +( + id bigserial + primary key, + model_version_id uuid not null, + capability varchar(255) not null, + is_supported boolean default false not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_ai_model_capability_model_version_id + on ai_model_capability (model_version_id); diff --git a/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_down_01.sql b/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_down_01.sql new file mode 100644 index 0000000..2dd6a94 --- /dev/null +++ b/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_model_parameter_profile_model_version_id; +DROP TABLE IF EXISTS ai_model_parameter_profile; diff --git a/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_up_01.sql b/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_up_01.sql new file mode 100644 index 0000000..5a229e1 --- /dev/null +++ b/libs/migrate/sql/ai_model_parameter_profile/ai_model_parameter_profile_up_01.sql @@ -0,0 +1,16 @@ +create table if not exists ai_model_parameter_profile +( + id bigserial + primary key, + model_version_id uuid not null + unique, + temperature_min double precision not null, + temperature_max double precision not null, + top_p_min double precision not null, + top_p_max double precision not null, + frequency_penalty_supported boolean default false not null, + presence_penalty_supported boolean default false not null +); + +create unique index if not exists idx_ai_model_parameter_profile_model_version_id + on ai_model_parameter_profile (model_version_id); diff --git a/libs/migrate/sql/ai_model_pricing/ai_model_pricing_down_01.sql b/libs/migrate/sql/ai_model_pricing/ai_model_pricing_down_01.sql new file mode 100644 index 0000000..8f79e00 --- /dev/null +++ b/libs/migrate/sql/ai_model_pricing/ai_model_pricing_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_model_pricing_model_version_id; +DROP TABLE IF EXISTS ai_model_pricing; diff --git a/libs/migrate/sql/ai_model_pricing/ai_model_pricing_up_01.sql b/libs/migrate/sql/ai_model_pricing/ai_model_pricing_up_01.sql new file mode 100644 index 0000000..5f54c92 --- /dev/null +++ b/libs/migrate/sql/ai_model_pricing/ai_model_pricing_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists ai_model_pricing +( + id bigserial + primary key, + model_version_id uuid not null, + input_price_per_1k_tokens varchar(255) not null, + output_price_per_1k_tokens varchar(255) not null, + currency varchar(255) not null, + effective_from timestamp with time zone not null +); + +create index if not exists idx_ai_model_pricing_model_version_id + on ai_model_pricing (model_version_id); diff --git a/libs/migrate/sql/ai_model_provider/ai_model_provider_down_01.sql b/libs/migrate/sql/ai_model_provider/ai_model_provider_down_01.sql new file mode 100644 index 0000000..6af389d --- /dev/null +++ b/libs/migrate/sql/ai_model_provider/ai_model_provider_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS ai_model_provider; diff --git a/libs/migrate/sql/ai_model_provider/ai_model_provider_up_01.sql b/libs/migrate/sql/ai_model_provider/ai_model_provider_up_01.sql new file mode 100644 index 0000000..53941ae --- /dev/null +++ b/libs/migrate/sql/ai_model_provider/ai_model_provider_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists ai_model_provider +( + id uuid not null + primary key, + name varchar(255) not null, + display_name varchar(255) not null, + website varchar(255), + status varchar(255) not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/ai_model_version/ai_model_version_down_01.sql b/libs/migrate/sql/ai_model_version/ai_model_version_down_01.sql new file mode 100644 index 0000000..1e1ce7a --- /dev/null +++ b/libs/migrate/sql/ai_model_version/ai_model_version_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_model_version_model_id; +DROP TABLE IF EXISTS ai_model_version; diff --git a/libs/migrate/sql/ai_model_version/ai_model_version_up_01.sql b/libs/migrate/sql/ai_model_version/ai_model_version_up_01.sql new file mode 100644 index 0000000..2f772f2 --- /dev/null +++ b/libs/migrate/sql/ai_model_version/ai_model_version_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists ai_model_version +( + id uuid not null + primary key, + model_id uuid not null, + version varchar(255) not null, + release_date timestamp with time zone, + change_log text, + is_default boolean default false not null, + status varchar(255) not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_ai_model_version_model_id + on ai_model_version (model_id); diff --git a/libs/migrate/sql/ai_session/ai_session_down_01.sql b/libs/migrate/sql/ai_session/ai_session_down_01.sql new file mode 100644 index 0000000..2578f8a --- /dev/null +++ b/libs/migrate/sql/ai_session/ai_session_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_ai_session_room; +DROP TABLE IF EXISTS ai_session; diff --git a/libs/migrate/sql/ai_session/ai_session_up_01.sql b/libs/migrate/sql/ai_session/ai_session_up_01.sql new file mode 100644 index 0000000..0605131 --- /dev/null +++ b/libs/migrate/sql/ai_session/ai_session_up_01.sql @@ -0,0 +1,19 @@ +create table if not exists ai_session +( + id uuid not null + primary key, + room uuid not null, + model uuid not null, + version uuid not null, + token_input bigint default 0 not null, + token_output bigint default 0 not null, + latency_ms bigint, + cost double precision, + currency varchar(255), + error_message text, + error_code varchar(255), + created_at timestamp with time zone not null +); + +create index if not exists idx_ai_session_room + on ai_session (room); diff --git a/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_down_01.sql b/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_down_01.sql new file mode 100644 index 0000000..bc4d65e --- /dev/null +++ b/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_ai_share_token; +DROP INDEX IF EXISTS idx_ai_share_conv; +DROP TABLE IF EXISTS ai_shared_conversation; diff --git a/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_up_01.sql b/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_up_01.sql new file mode 100644 index 0000000..6a7e486 --- /dev/null +++ b/libs/migrate/sql/ai_shared_conversation/ai_shared_conversation_up_01.sql @@ -0,0 +1,21 @@ +create table if not exists ai_shared_conversation +( + id uuid default gen_random_uuid() not null + primary key, + conversation_id uuid not null + constraint fk_ai_share_conv + references ai_conversation + on delete cascade, + share_token varchar(128) not null + unique, + created_by uuid not null, + view_count integer default 0 not null, + created_at timestamp with time zone default now() not null, + expires_at timestamp with time zone +); + +create index if not exists idx_ai_share_conv + on ai_shared_conversation (conversation_id); + +create index if not exists idx_ai_share_token + on ai_shared_conversation (share_token); diff --git a/libs/migrate/sql/ai_subagent_session/ai_subagent_session_down_01.sql b/libs/migrate/sql/ai_subagent_session/ai_subagent_session_down_01.sql new file mode 100644 index 0000000..1da651c --- /dev/null +++ b/libs/migrate/sql/ai_subagent_session/ai_subagent_session_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_ai_subagent_session_message; +DROP INDEX IF EXISTS idx_ai_subagent_session_children; +DROP INDEX IF EXISTS idx_ai_subagent_session_conv; +DROP TABLE IF EXISTS ai_subagent_session; diff --git a/libs/migrate/ai_subagent_session.rs b/libs/migrate/sql/ai_subagent_session/ai_subagent_session_up_01.sql similarity index 53% rename from libs/migrate/ai_subagent_session.rs rename to libs/migrate/sql/ai_subagent_session/ai_subagent_session_up_01.sql index c44fb8a..9fd6b6b 100644 --- a/libs/migrate/ai_subagent_session.rs +++ b/libs/migrate/sql/ai_subagent_session/ai_subagent_session_up_01.sql @@ -1,20 +1,3 @@ -use sea_orm_migration::prelude::*; - -pub struct Migration; - -impl MigrationName for Migration { - fn name(&self) -> &str { - "ai_subagent_session" - } -} - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" create table if not exists ai_subagent_session ( id uuid not null primary key, @@ -40,24 +23,3 @@ create index if not exists idx_ai_subagent_session_children create index if not exists idx_ai_subagent_session_message on ai_subagent_session (message_id); -"#, - ) - .await?; - Ok(()) - } - - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" -drop index if exists idx_ai_subagent_session_message; -drop index if exists idx_ai_subagent_session_children; -drop index if exists idx_ai_subagent_session_conv; -drop table if exists ai_subagent_session; -"#, - ) - .await?; - Ok(()) - } -} \ No newline at end of file diff --git a/libs/migrate/sql/ai_token_usage/ai_token_usage_down_01.sql b/libs/migrate/sql/ai_token_usage/ai_token_usage_down_01.sql new file mode 100644 index 0000000..4583024 --- /dev/null +++ b/libs/migrate/sql/ai_token_usage/ai_token_usage_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_ai_token_recorded; +DROP INDEX IF EXISTS idx_ai_token_conv; +DROP INDEX IF EXISTS idx_ai_token_user; +DROP TABLE IF EXISTS ai_token_usage; diff --git a/libs/migrate/sql/ai_token_usage/ai_token_usage_up_01.sql b/libs/migrate/sql/ai_token_usage/ai_token_usage_up_01.sql new file mode 100644 index 0000000..c6e20b4 --- /dev/null +++ b/libs/migrate/sql/ai_token_usage/ai_token_usage_up_01.sql @@ -0,0 +1,21 @@ +create table if not exists ai_token_usage +( + id uuid default gen_random_uuid() not null + primary key, + user_id uuid not null, + conversation_id uuid, + model varchar(128) not null, + input_tokens integer not null, + output_tokens integer not null, + cost_usd numeric(10, 6), + recorded_at timestamp with time zone default now() not null +); + +create index if not exists idx_ai_token_user + on ai_token_usage (user_id); + +create index if not exists idx_ai_token_conv + on ai_token_usage (conversation_id); + +create index if not exists idx_ai_token_recorded + on ai_token_usage (recorded_at); diff --git a/libs/migrate/sql/ai_tool_auth/ai_tool_auth_down_01.sql b/libs/migrate/sql/ai_tool_auth/ai_tool_auth_down_01.sql new file mode 100644 index 0000000..94b4d05 --- /dev/null +++ b/libs/migrate/sql/ai_tool_auth/ai_tool_auth_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS ai_tool_auth; diff --git a/libs/migrate/sql/ai_tool_auth/ai_tool_auth_up_01.sql b/libs/migrate/sql/ai_tool_auth/ai_tool_auth_up_01.sql new file mode 100644 index 0000000..33abfd8 --- /dev/null +++ b/libs/migrate/sql/ai_tool_auth/ai_tool_auth_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists ai_tool_auth +( + session uuid not null, + tool_call_id varchar(255) not null, + method varchar(255) not null, + arguments text not null, + decision boolean default false not null, + reason varchar(255) not null, + decision_by uuid not null, + decision_comment text, + logs jsonb not null, + expires_at timestamp with time zone, + authorized_at timestamp with time zone, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + primary key (session, tool_call_id) +); diff --git a/libs/migrate/sql/ai_tool_call/ai_tool_call_down_01.sql b/libs/migrate/sql/ai_tool_call/ai_tool_call_down_01.sql new file mode 100644 index 0000000..4e2546b --- /dev/null +++ b/libs/migrate/sql/ai_tool_call/ai_tool_call_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_ai_tool_call_status; +DROP INDEX IF EXISTS idx_ai_tool_call_session; +DROP TABLE IF EXISTS ai_tool_call; diff --git a/libs/migrate/sql/ai_tool_call/ai_tool_call_up_01.sql b/libs/migrate/sql/ai_tool_call/ai_tool_call_up_01.sql new file mode 100644 index 0000000..3ae60f8 --- /dev/null +++ b/libs/migrate/sql/ai_tool_call/ai_tool_call_up_01.sql @@ -0,0 +1,24 @@ +create table if not exists ai_tool_call +( + tool_call_id varchar(255) not null, + session uuid not null, + tool_name varchar(255) not null, + caller uuid not null, + arguments jsonb not null, + result jsonb not null, + status varchar(255) not null, + execution_time_ms bigint, + error_message text, + error_stack text, + retry_count integer default 0 not null, + created_at timestamp with time zone not null, + completed_at timestamp with time zone, + updated_at timestamp with time zone not null, + primary key (tool_call_id, session) +); + +create index if not exists idx_ai_tool_call_session + on ai_tool_call (session); + +create index if not exists idx_ai_tool_call_status + on ai_tool_call (status); diff --git a/libs/migrate/sql/bootstrap/bootstrap_down_01.sql b/libs/migrate/sql/bootstrap/bootstrap_down_01.sql new file mode 100644 index 0000000..3a78dd0 --- /dev/null +++ b/libs/migrate/sql/bootstrap/bootstrap_down_01.sql @@ -0,0 +1,3 @@ +DROP TRIGGER IF EXISTS room_message_tsv_update ON room_message; +DROP FUNCTION IF EXISTS room_message_tsv_trigger(); +DROP TYPE IF EXISTS notification_type; diff --git a/libs/migrate/sql/bootstrap/bootstrap_up_01.sql b/libs/migrate/sql/bootstrap/bootstrap_up_01.sql new file mode 100644 index 0000000..75a3396 --- /dev/null +++ b/libs/migrate/sql/bootstrap/bootstrap_up_01.sql @@ -0,0 +1,33 @@ +CREATE OR REPLACE FUNCTION room_message_tsv_trigger() +RETURNS trigger +LANGUAGE plpgsql +AS $function$ +BEGIN + NEW.content_tsv := to_tsvector('english', NEW.content); + RETURN NEW; +END; +$function$; +CREATE OR REPLACE TRIGGER room_message_tsv_update + BEFORE INSERT OR UPDATE + ON room_message + FOR EACH ROW +EXECUTE PROCEDURE room_message_tsv_trigger(); + +DO +$$ + BEGIN + IF NOT EXISTS (SELECT 1 + FROM pg_type + WHERE typname = 'notification_type' + AND typtype = 'e') THEN + CREATE TYPE notification_type AS ENUM ( + 'mention', + 'invitation', + 'role_change', + 'room_created', + 'room_deleted', + 'system_announcement' + ); + END IF; + END +$$; diff --git a/libs/migrate/sql/init.sql b/libs/migrate/sql/init.sql deleted file mode 100644 index 56ed125..0000000 --- a/libs/migrate/sql/init.sql +++ /dev/null @@ -1,1835 +0,0 @@ -create table if not exists "user" -( - uid uuid not null - primary key, - username varchar(255) not null, - display_name varchar(255), - avatar_url varchar(255), - website_url varchar(255), - organization varchar(255), - last_sign_in_at timestamp with time zone, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_user_username - on "user" (username); - -create table if not exists user_password -( - "user" uuid not null - primary key, - password_hash varchar(255) not null, - password_salt varchar(255), - is_active boolean default true not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists user_email -( - "user" uuid not null - primary key, - email varchar(255) not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_email_email - on user_email (email); - -create table if not exists user_2fa -( - "user" uuid not null - primary key, - method varchar(255) not null, - secret varchar(255), - backup_codes jsonb not null, - is_enabled boolean default false not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists user_notification -( - "user" uuid not null - primary key, - email_enabled boolean default false not null, - in_app_enabled boolean default true not null, - push_enabled boolean default false not null, - digest_mode varchar(255) not null, - dnd_enabled boolean default false not null, - dnd_start_minute integer, - dnd_end_minute integer, - marketing_enabled boolean default true not null, - security_enabled boolean default true not null, - product_enabled boolean default true not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - push_subscription_endpoint text, - push_subscription_keys_p256dh text, - push_subscription_keys_auth text -); - -create table if not exists user_preferences -( - "user" uuid not null - primary key, - language varchar(255) not null, - theme varchar(255) not null, - timezone varchar(255) not null, - email_notifications boolean default true not null, - in_app_notifications boolean default true not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists user_password_reset -( - token varchar(255) not null - primary key, - user_uid uuid not null, - expires_at timestamp with time zone not null, - used boolean default false not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_password_reset_user_uid - on user_password_reset (user_uid); - -create table if not exists user_relation -( - id bigserial - primary key, - "user" uuid not null, - target uuid not null, - relation_type varchar(255) not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_relation_user - on user_relation ("user"); - -create index if not exists idx_user_relation_target - on user_relation (target); - -create table if not exists user_ssh_key -( - id bigserial - primary key, - "user" uuid not null, - title varchar(255) not null, - public_key text not null, - fingerprint varchar(255) not null, - key_type varchar(255) not null, - key_bits integer, - is_verified boolean default false not null, - last_used_at timestamp with time zone, - expires_at timestamp with time zone, - is_revoked boolean default false not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_user_ssh_key_user - on user_ssh_key ("user"); - -create table if not exists user_token -( - id bigserial - primary key, - "user" uuid not null, - name varchar(255) not null, - token_hash varchar(255) not null, - scopes jsonb not null, - expires_at timestamp with time zone, - is_revoked boolean default false not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_user_token_user - on user_token ("user"); - -create table if not exists user_activity_log -( - id bigserial - primary key, - user_uid uuid, - action varchar(255) not null, - ip_address varchar(255), - user_agent varchar(255), - details jsonb not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_activity_log_user_uid - on user_activity_log (user_uid); - -create index if not exists idx_user_activity_log_created_at - on user_activity_log (created_at); - -create table if not exists project_access_log -( - id bigserial - primary key, - project uuid not null, - actor_uid uuid, - action varchar(255) not null, - ip_address varchar(255), - user_agent varchar(255), - created_at timestamp with time zone not null -); - -create index if not exists idx_project_access_log_project - on project_access_log (project); - -create index if not exists idx_project_access_log_created_at - on project_access_log (created_at); - -create table if not exists project_audit_log -( - id bigserial - primary key, - project uuid not null, - actor uuid not null, - action text not null, - details jsonb, - ip_address varchar(255), - user_agent varchar(255), - created_at timestamp with time zone not null -); - -create index if not exists idx_project_audit_log_project - on project_audit_log (project); - -create index if not exists idx_project_audit_log_created_at - on project_audit_log (created_at); - -create table if not exists project_billing -( - project_uuid uuid not null - primary key, - balance numeric default 0.0 not null, - currency text not null, - user_uuid uuid, - updated_at timestamp with time zone not null, - created_at timestamp with time zone not null -); - -create table if not exists project_billing_history -( - uid uuid not null - primary key, - project uuid not null, - "user" uuid, - amount numeric not null, - currency text not null, - reason text not null, - extra jsonb, - created_at timestamp with time zone not null -); - -create index if not exists idx_project_billing_history_project - on project_billing_history (project); - -create table if not exists project_follow -( - id bigserial - primary key, - project uuid not null, - "user" uuid not null, - created_at timestamp with time zone not null, - unique (project, "user") -); - -create unique index if not exists idx_project_follow_project_user - on project_follow (project, "user"); - -create table if not exists project_history_name -( - id bigserial - primary key, - project_uid uuid not null, - history_name varchar(255) not null, - changed_at timestamp with time zone not null -); - -create index if not exists idx_project_history_name_project_uid - on project_history_name (project_uid); - -create table if not exists project_label -( - id bigserial - primary key, - project_uuid uuid not null, - label_id bigint not null, - relation_at timestamp with time zone not null -); - -create index if not exists idx_project_label_project - on project_label (project_uuid); - -create table if not exists project_like -( - project uuid not null, - "user" uuid not null, - created_at timestamp with time zone not null, - primary key (project, "user") -); - -create table if not exists project_member_invitations -( - id bigserial - primary key, - project uuid not null, - "user" uuid not null, - invited_by uuid not null, - scope varchar(255) not null, - accepted boolean default false not null, - accepted_at timestamp with time zone, - rejected boolean default false not null, - rejected_at timestamp with time zone, - created_at timestamp with time zone not null -); - -create index if not exists idx_project_member_invitations_project_user - on project_member_invitations (project, "user"); - -create table if not exists project_member_join_answers -( - id bigserial - primary key, - project uuid not null, - "user" uuid not null, - request_id bigint not null, - question varchar(255) not null, - answer varchar(255) not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_project_member_join_answers_request_id - on project_member_join_answers (request_id); - -create table if not exists project_member_join_request -( - id bigserial - primary key, - project uuid not null, - "user" uuid not null, - status varchar(255) not null, - message text, - processed_by uuid, - processed_at timestamp with time zone, - reject_reason text, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_project_member_join_request_project_user - on project_member_join_request (project, "user"); - -create index if not exists idx_project_member_join_request_status - on project_member_join_request (status); - -create table if not exists project_member_join_settings -( - id bigserial - primary key, - project uuid not null, - require_approval boolean default false not null, - require_questions boolean default false not null, - questions jsonb not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists project_members -( - id bigserial - primary key, - project_uuid uuid not null, - user_uuid uuid not null, - scope varchar(255) not null, - joined_at timestamp with time zone not null, - unique (project_uuid, user_uuid) -); - -create unique index if not exists idx_project_members_project_user - on project_members (project_uuid, user_uuid); - -create table if not exists project_watch -( - id bigserial - primary key, - project uuid not null, - "user" uuid not null, - notifications_enabled boolean default true not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - unique (project, "user") -); - -create unique index if not exists idx_project_watch_project_user - on project_watch (project, "user"); - -create table if not exists repo -( - id uuid not null - primary key, - repo_name varchar(255) not null, - project uuid not null, - description text, - default_branch varchar(255) not null, - is_private boolean default false not null, - storage_path varchar(255) not null, - created_by uuid not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - ai_code_review_enabled boolean default false not null -); - -create index if not exists idx_repo_project - on repo (project); - -create index if not exists idx_repo_repo_name - on repo (repo_name); - -create table if not exists repo_branch -( - repo uuid not null, - name varchar(255) not null, - oid varchar(255) not null, - upstream varchar(255), - head boolean default false not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - primary key (repo, name) -); - -create index if not exists idx_repo_branch_repo - on repo_branch (repo); - -create table if not exists repo_branch_protect -( - id bigserial - primary key, - repo_uuid uuid not null, - branch varchar(255) not null, - forbid_push boolean default false not null, - forbid_pull boolean default false not null, - forbid_merge boolean default false not null, - forbid_deletion boolean default false not null, - forbid_force_push boolean default false not null, - forbid_tag_push boolean default false not null, - required_approvals integer default 0 not null, - dismiss_stale_reviews boolean default false not null, - require_linear_history boolean default false not null, - allow_fork_syncing boolean default true not null, - unique (repo_uuid, branch) -); - -create unique index if not exists idx_repo_branch_protect_repo_branch - on repo_branch_protect (repo_uuid, branch); - -create table if not exists repo_collaborator -( - repo uuid not null, - "user" uuid not null, - scope varchar(255) not null, - created_at timestamp with time zone not null, - primary key (repo, "user") -); - -create table if not exists repo_commit -( - id bigserial - primary key, - repo uuid not null, - oid varchar(255) not null, - author_name varchar(255) not null, - author_email varchar(255) not null, - author uuid, - commiter_name varchar(255) not null, - commiter_email varchar(255) not null, - commiter uuid, - message text not null, - parent jsonb not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_repo_commit_repo - on repo_commit (repo); - -create index if not exists idx_repo_commit_oid - on repo_commit (oid); - -create table if not exists repo_fork -( - id bigserial - primary key, - parent_repo uuid not null, - forked_repo uuid not null, - forked_by uuid not null, - forked_at timestamp with time zone not null -); - -create index if not exists idx_repo_fork_parent_repo - on repo_fork (parent_repo); - -create unique index if not exists idx_repo_fork_forked_repo - on repo_fork (forked_repo); - -create table if not exists repo_history_name -( - id bigserial - primary key, - repo_uuid uuid not null, - project_uid uuid not null, - name varchar(255) not null, - change_at timestamp with time zone not null -); - -create index if not exists idx_repo_history_name_repo - on repo_history_name (repo_uuid); - -create table if not exists repo_hook -( - id bigserial - primary key, - repo_uuid uuid not null, - event jsonb not null, - script text not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_repo_hook_repo - on repo_hook (repo_uuid); - -create table if not exists repo_lfs_lock -( - repo_uuid uuid not null, - path varchar(255) not null, - lock_type varchar(255) not null, - locked_by uuid not null, - locked_at timestamp with time zone not null, - unlocked_at timestamp with time zone, - primary key (repo_uuid, path) -); - -create table if not exists repo_lfs_object -( - id bigserial - primary key, - oid varchar(255) not null, - repo_uuid uuid not null, - size bigint not null, - storage_path varchar(255) not null, - uploaded_by uuid, - uploaded_at timestamp with time zone not null -); - -create index if not exists idx_repo_lfs_object_repo_oid - on repo_lfs_object (repo_uuid, oid); - -create table if not exists repo_lock -( - repo_uuid uuid not null, - path varchar(255) not null, - lock_type varchar(255) not null, - locked_by uuid not null, - acquired_at timestamp with time zone not null, - released_at timestamp with time zone, - primary key (repo_uuid, path) -); - -create table if not exists repo_star -( - id bigserial - primary key, - repo_uuid uuid not null, - user_uuid uuid not null, - created_at timestamp with time zone not null, - unique (repo_uuid, user_uuid) -); - -create unique index if not exists idx_repo_star_repo_user - on repo_star (repo_uuid, user_uuid); - -create table if not exists repo_tag -( - repo_uuid uuid not null, - name varchar(255) not null, - oid varchar(255) not null, - color varchar(255), - description text, - created_at timestamp with time zone not null, - tagger_name varchar(255) not null, - tagger_email varchar(255) not null, - tagger_uuid uuid, - primary key (repo_uuid, name) -); - -create table if not exists repo_upstream -( - id bigserial - primary key, - repo_uuid uuid not null - unique, - source_url varchar(255) not null, - direction varchar(255) not null, - schedule_cron varchar(255), - last_run_at timestamp with time zone, - next_run_at timestamp with time zone, - status varchar(255) not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create unique index if not exists idx_repo_upstream_repo - on repo_upstream (repo_uuid); - -create table if not exists repo_watch -( - id bigserial - primary key, - user_uuid uuid not null, - repo_uuid uuid not null, - show_dashboard boolean default false not null, - notify_email boolean default false not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - unique (user_uuid, repo_uuid) -); - -create unique index if not exists idx_repo_watch_user_repo - on repo_watch (user_uuid, repo_uuid); - -create table if not exists repo_webhook -( - id bigserial - primary key, - repo_uuid uuid not null, - event jsonb not null, - url varchar(255), - access_key varchar(255), - secret_key varchar(255), - created_at timestamp with time zone not null, - last_delivered_at timestamp with time zone, - touch_count bigint default 0 not null -); - -create index if not exists idx_repo_webhook_repo - on repo_webhook (repo_uuid); - -create table if not exists issue -( - id uuid not null - primary key, - project uuid not null, - number bigint not null, - title varchar(255) not null, - body text, - state varchar(255) not null, - author uuid not null, - milestone varchar(255), - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - closed_at timestamp with time zone, - created_by_ai boolean default false not null -); - -create index if not exists idx_issue_project - on issue (project); - -create index if not exists idx_issue_author - on issue (author); - -create index if not exists idx_issue_state - on issue (state); - -create table if not exists issue_assignee -( - issue uuid not null, - "user" uuid not null, - assigned_at timestamp with time zone not null, - primary key (issue, "user") -); - -create table if not exists issue_comment -( - id bigserial - primary key, - issue uuid not null, - author uuid not null, - body text not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_issue_comment_issue - on issue_comment (issue); - -create table if not exists issue_comment_reaction -( - comment_id bigint not null, - user_uuid uuid not null, - reaction varchar(255) not null, - created_at timestamp with time zone not null, - primary key (comment_id, user_uuid, reaction) -); - -create table if not exists issue_label -( - issue uuid not null, - label bigint not null, - relation_at timestamp with time zone not null, - primary key (issue, label) -); - -create table if not exists issue_pull_request -( - issue uuid not null, - repo uuid not null, - number bigint not null, - relation_at timestamp with time zone not null, - primary key (issue, repo, number) -); - -create table if not exists issue_reaction -( - issue_uuid uuid not null, - user_uuid uuid not null, - reaction varchar(255) not null, - created_at timestamp with time zone not null, - primary key (issue_uuid, user_uuid, reaction) -); - -create table if not exists issue_repo -( - issue uuid not null, - repo uuid not null, - relation_at timestamp with time zone not null, - primary key (issue, repo) -); - -create table if not exists issue_subscriber -( - issue uuid not null, - "user" uuid not null, - subscribed boolean default true not null, - created_at timestamp with time zone not null, - primary key (issue, "user") -); - -create table if not exists pull_request -( - repo uuid not null, - number bigint not null, - issue uuid not null, - title varchar(255) not null, - body text, - author uuid not null, - base varchar(255) not null, - head varchar(255) not null, - status varchar(255) not null, - merged_by uuid, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - merged_at timestamp with time zone, - created_by_ai boolean default false not null, - primary key (repo, number) -); - -create index if not exists idx_pull_request_repo - on pull_request (repo); - -create index if not exists idx_pull_request_author - on pull_request (author); - -create index if not exists idx_pull_request_status - on pull_request (status); - -create table if not exists pull_request_commit -( - repo uuid not null, - number bigint not null, - commit varchar(255) not null, - message text not null, - author_name varchar(255) not null, - author_email varchar(255) not null, - authored_at timestamp with time zone not null, - committer_name varchar(255) not null, - committer_email varchar(255) not null, - committed_at timestamp with time zone not null, - created_at timestamp with time zone not null, - primary key (repo, number, commit) -); - -create table if not exists pull_request_review -( - repo uuid not null, - number bigint not null, - reviewer uuid not null, - state varchar(255) not null, - body text, - submitted_at timestamp with time zone, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - primary key (repo, number, reviewer) -); - -create table if not exists pull_request_review_comment -( - repo uuid not null, - number bigint not null, - id bigint not null, - review uuid, - path text, - side varchar(255), - line bigint, - old_line bigint, - body text not null, - author uuid not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - resolved boolean default false not null, - in_reply_to bigint, - primary key (repo, number, id) -); - -create table if not exists room_category -( - id uuid not null - primary key, - project_uuid uuid not null, - name varchar(255) not null, - position integer not null, - created_by uuid not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_room_category_project - on room_category (project_uuid); - -create table if not exists room -( - id uuid not null - primary key, - project uuid not null, - room_name varchar(255) not null, - public boolean default false not null, - category uuid, - created_by uuid not null, - created_at timestamp with time zone not null, - last_msg_at timestamp with time zone not null -); - -create index if not exists idx_room_project - on room (project); - -create index if not exists idx_room_category - on room (category); - -create table if not exists room_ai -( - room uuid not null, - model uuid not null, - version uuid, - call_count bigint default 0 not null, - last_call_at timestamp with time zone, - history_limit bigint, - system_prompt text, - temperature double precision, - max_tokens bigint, - use_exact boolean default false not null, - think boolean default false not null, - min_score real, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - stream boolean default true not null, - agent_type varchar(50), - primary key (room, model) -); - -create index if not exists idx_room_ai_agent_type - on room_ai (agent_type) - where (agent_type IS NOT NULL); - -create table if not exists room_message -( - id uuid not null - primary key, - seq bigint not null, - room uuid not null, - sender_type varchar(255) not null, - sender_id uuid, - thread uuid, - content text not null, - content_type varchar(255) not null, - edited_at timestamp with time zone, - send_at timestamp with time zone not null, - revoked timestamp with time zone, - revoked_by uuid, - in_reply_to uuid, - content_tsv tsvector, - model_id uuid, - thinking_content text -); - -create index if not exists idx_room_message_room_seq - on room_message (room, seq); - -create index if not exists idx_room_message_thread - on room_message (thread); - -create index if not exists idx_room_message_send_at - on room_message (send_at); - -create index if not exists idx_room_message_content_tsv - on room_message using gin (content_tsv); - -create index if not exists idx_room_message_model_id - on room_message (model_id) - where (model_id IS NOT NULL); - - - -create table if not exists room_pin -( - room uuid not null, - message uuid not null, - pinned_by uuid not null, - pinned_at timestamp with time zone not null, - primary key (room, message) -); - -create table if not exists room_thread -( - id uuid not null - primary key, - room uuid not null, - parent bigint not null, - created_by uuid not null, - participants jsonb not null, - last_message_at timestamp with time zone not null, - last_message_preview text, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_room_thread_room - on room_thread (room); - -create table if not exists ai_model_provider -( - id uuid not null - primary key, - name varchar(255) not null, - display_name varchar(255) not null, - website varchar(255), - status varchar(255) not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists ai_model -( - id uuid not null - primary key, - provider_id uuid not null, - name varchar(255) not null, - modality varchar(255) not null, - capability varchar(255) not null, - context_length bigint not null, - max_output_tokens bigint, - training_cutoff timestamp with time zone, - is_open_source boolean default false not null, - status varchar(255) not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create index if not exists idx_ai_model_provider_id - on ai_model (provider_id); - -create table if not exists ai_model_version -( - id uuid not null - primary key, - model_id uuid not null, - version varchar(255) not null, - release_date timestamp with time zone, - change_log text, - is_default boolean default false not null, - status varchar(255) not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_ai_model_version_model_id - on ai_model_version (model_id); - -create table if not exists ai_model_capability -( - id bigserial - primary key, - model_version_id uuid not null, - capability varchar(255) not null, - is_supported boolean default false not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_ai_model_capability_model_version_id - on ai_model_capability (model_version_id); - -create table if not exists ai_model_parameter_profile -( - id bigserial - primary key, - model_version_id uuid not null - unique, - temperature_min double precision not null, - temperature_max double precision not null, - top_p_min double precision not null, - top_p_max double precision not null, - frequency_penalty_supported boolean default false not null, - presence_penalty_supported boolean default false not null -); - -create unique index if not exists idx_ai_model_parameter_profile_model_version_id - on ai_model_parameter_profile (model_version_id); - -create table if not exists ai_model_pricing -( - id bigserial - primary key, - model_version_id uuid not null, - input_price_per_1k_tokens varchar(255) not null, - output_price_per_1k_tokens varchar(255) not null, - currency varchar(255) not null, - effective_from timestamp with time zone not null -); - -create index if not exists idx_ai_model_pricing_model_version_id - on ai_model_pricing (model_version_id); - -create table if not exists ai_session -( - id uuid not null - primary key, - room uuid not null, - model uuid not null, - version uuid not null, - token_input bigint default 0 not null, - token_output bigint default 0 not null, - latency_ms bigint, - cost double precision, - currency varchar(255), - error_message text, - error_code varchar(255), - created_at timestamp with time zone not null -); - -create index if not exists idx_ai_session_room - on ai_session (room); - -create table if not exists ai_tool_call -( - tool_call_id varchar(255) not null, - session uuid not null, - tool_name varchar(255) not null, - caller uuid not null, - arguments jsonb not null, - result jsonb not null, - status varchar(255) not null, - execution_time_ms bigint, - error_message text, - error_stack text, - retry_count integer default 0 not null, - created_at timestamp with time zone not null, - completed_at timestamp with time zone, - updated_at timestamp with time zone not null, - primary key (tool_call_id, session) -); - -create index if not exists idx_ai_tool_call_session - on ai_tool_call (session); - -create index if not exists idx_ai_tool_call_status - on ai_tool_call (status); - -create table if not exists ai_tool_auth -( - session uuid not null, - tool_call_id varchar(255) not null, - method varchar(255) not null, - arguments text not null, - decision boolean default false not null, - reason varchar(255) not null, - decision_by uuid not null, - decision_comment text, - logs jsonb not null, - expires_at timestamp with time zone, - authorized_at timestamp with time zone, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - primary key (session, tool_call_id) -); - -create table if not exists label -( - id bigserial - primary key, - project_uuid uuid not null, - name varchar(255) not null, - color varchar(255) not null -); - -create index if not exists idx_label_project - on label (project_uuid); - -create table if not exists notify -( - id bigserial - primary key, - user_uuid uuid not null, - title varchar(255) not null, - description text, - content text not null, - url varchar(255), - kind integer not null, - read_at timestamp with time zone, - deleted_at timestamp with time zone, - created_at timestamp with time zone not null -); - -create index if not exists idx_notify_user - on notify (user_uuid); - -create index if not exists idx_notify_created_at - on notify (created_at); - -create table if not exists room_notifications -( - id uuid not null - primary key, - room uuid, - project uuid, - user_id uuid, - notification_type varchar(255) not null, - related_message_id uuid, - related_user_id uuid, - related_room_id uuid, - title varchar(255) not null, - content text, - metadata jsonb, - is_read boolean default false not null, - is_archived boolean default false not null, - created_at timestamp with time zone not null, - read_at timestamp with time zone, - expires_at timestamp with time zone -); - -create index if not exists idx_room_notifications_user_id_is_read - on room_notifications (user_id, is_read); - -create index if not exists idx_room_notifications_user_id_created_at - on room_notifications (user_id, created_at); - -create index if not exists idx_room_notifications_expires_at - on room_notifications (expires_at); - -create table if not exists user_email_change -( - token varchar(255) not null - primary key, - user_uid uuid not null, - new_email varchar(255) not null, - expires_at timestamp with time zone not null, - used boolean default false not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_email_change_user_uid - on user_email_change (user_uid); - -create table if not exists project_activity -( - id bigserial - primary key, - project uuid not null, - repo uuid, - actor uuid not null, - event_type varchar(50) not null, - event_id uuid, - event_sub_id bigint, - title varchar(500) not null, - content text, - metadata jsonb, - is_private boolean default false not null, - created_at timestamp with time zone not null -); - -create index if not exists idx_project_activity_project - on project_activity (project); - -create index if not exists idx_project_activity_created_at - on project_activity (created_at desc); - -create index if not exists idx_project_activity_event_type - on project_activity (event_type); - -create table if not exists room_message_reaction -( - id uuid not null - primary key, - room uuid not null - references room - on delete cascade, - message uuid not null - references room_message - on delete cascade, - "user" uuid not null - references "user" - on delete cascade, - emoji varchar(50) not null, - created_at timestamp with time zone default now() not null, - unique (message, "user", emoji) -); - -create index if not exists idx_room_message_reaction_message - on room_message_reaction (message); - -create index if not exists idx_room_message_reaction_user - on room_message_reaction ("user"); - -create index if not exists idx_room_message_reaction_room - on room_message_reaction (room); - -create table if not exists room_message_edit_history -( - id uuid not null - primary key, - message uuid not null - references room_message - on delete cascade, - "user" uuid not null - references "user" - on delete cascade, - old_content text not null, - new_content text not null, - edited_at timestamp with time zone default now() not null -); - -create index if not exists idx_room_message_edit_history_message - on room_message_edit_history (message); - -create index if not exists idx_room_message_edit_history_user - on room_message_edit_history ("user"); - -create table if not exists project_board -( - id uuid default gen_random_uuid() not null - primary key, - project_uuid uuid not null, - name varchar(255) not null, - description text, - created_by uuid not null, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null -); - -create index if not exists idx_project_board_project - on project_board (project_uuid); - -create table if not exists project_board_column -( - id uuid default gen_random_uuid() not null - primary key, - board_uuid uuid not null - references project_board - on delete cascade, - name varchar(255) not null, - position integer default 0 not null, - wip_limit integer, - color varchar(20) -); - -create index if not exists idx_project_board_column_board - on project_board_column (board_uuid); - -create table if not exists project_board_card -( - id uuid default gen_random_uuid() not null - primary key, - column_uuid uuid not null - references project_board_column - on delete cascade, - issue_id bigint, - project uuid, - title varchar(500) not null, - description text, - position integer default 0 not null, - assignee_id uuid, - due_date timestamp with time zone, - priority varchar(10), - created_by uuid not null, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null -); - -create index if not exists idx_project_board_card_column - on project_board_card (column_uuid); - -create index if not exists idx_project_board_card_issue - on project_board_card (issue_id) - where (issue_id IS NOT NULL); - -create table if not exists pull_request_review_request -( - repo uuid not null, - number bigint not null, - reviewer uuid not null, - requested_by uuid not null, - requested_at timestamp with time zone default now() not null, - dismissed_at timestamp with time zone, - dismissed_by uuid, - primary key (repo, number, reviewer) -); - -create table if not exists workspace -( - id uuid not null - primary key, - slug varchar(255) not null, - name varchar(255) not null, - description text, - avatar_url varchar(255), - plan varchar(50) default 'free'::character varying not null, - billing_email varchar(255), - stripe_customer_id varchar(255), - stripe_subscription_id varchar(255), - plan_expires_at timestamp with time zone, - deleted_at timestamp with time zone, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null -); - -create table if not exists project -( - id uuid not null - primary key, - name varchar(255) not null, - display_name varchar(255) not null, - avatar_url varchar(255), - description text, - is_public boolean default false not null, - created_by uuid not null, - created_at timestamp with time zone not null, - updated_at timestamp with time zone not null, - workspace_id uuid - references workspace - on delete set null -); - -create index if not exists idx_project_name - on project (name); - -create index if not exists idx_project_created_by - on project (created_by); - -create index if not exists idx_project_workspace_id - on project (workspace_id) - where (workspace_id IS NOT NULL); - -create unique index if not exists idx_workspace_slug - on workspace (slug); - -create index if not exists idx_workspace_deleted_at - on workspace (deleted_at); - -create table if not exists workspace_membership -( - id bigserial - primary key, - workspace_id uuid not null, - user_id uuid not null, - role varchar(50) default 'member'::character varying not null, - status varchar(50) default 'active'::character varying not null, - invited_by uuid, - joined_at timestamp with time zone not null, - invite_token varchar(255), - invite_expires_at timestamp with time zone, - unique (workspace_id, user_id) -); - -create unique index if not exists idx_workspace_membership_ws_user - on workspace_membership (workspace_id, user_id); - -create index if not exists idx_workspace_membership_user - on workspace_membership (user_id); - -create index if not exists idx_workspace_membership_invite_token - on workspace_membership (invite_token) - where (invite_token IS NOT NULL); - -create table if not exists workspace_billing -( - workspace_id uuid not null - primary key - references workspace - on delete cascade, - balance numeric(20, 4) default 0 not null, - currency varchar(10) default 'USD'::character varying not null, - monthly_quota numeric(20, 4) default 0 not null, - total_spent numeric(20, 4) default 0 not null, - updated_at timestamp with time zone not null, - created_at timestamp with time zone not null -); - -create table if not exists workspace_billing_history -( - uid uuid not null - primary key, - workspace_id uuid not null - references workspace - on delete cascade, - user_id uuid, - amount numeric(20, 4) not null, - currency varchar(10) default 'USD'::character varying not null, - reason varchar(100) not null, - extra jsonb, - created_at timestamp with time zone not null -); - -create index if not exists idx_wsbh_workspace_id - on workspace_billing_history (workspace_id); - -create index if not exists idx_wsbh_created_at - on workspace_billing_history (created_at desc); - -create table if not exists project_skill -( - id bigserial - primary key, - project_uuid uuid not null, - slug varchar(255) not null, - name varchar(255) not null, - description text, - source varchar(20) default 'manual'::character varying not null, - repo_id uuid, - content text default ''::text not null, - metadata jsonb default '{}'::jsonb not null, - enabled boolean default true not null, - created_by uuid, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null, - commit_sha varchar(40), - blob_hash varchar(40), - unique (project_uuid, slug) -); - -create index if not exists idx_project_skill_project - on project_skill (project_uuid); - -create index if not exists idx_project_skill_slug - on project_skill (slug); - -create index if not exists idx_project_skill_source - on project_skill (source); - -create index if not exists idx_project_skill_commit_sha - on project_skill (commit_sha); - -create index if not exists idx_project_skill_blob_hash - on project_skill (blob_hash); - -create table if not exists agent_task -( - id bigserial - primary key, - project_uuid uuid not null, - parent_id bigint - constraint fk_agent_task_parent - references agent_task - on delete set null, - agent_type varchar(20) default 'react'::character varying not null, - status varchar(20) default 'pending'::character varying not null, - title varchar(255), - input text not null, - output text, - error text, - created_by uuid, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null, - started_at timestamp with time zone, - done_at timestamp with time zone, - progress varchar(255), - issue_id uuid, - retry_count integer default 0 -); - -create index if not exists idx_agent_task_project - on agent_task (project_uuid); - -create index if not exists idx_agent_task_parent - on agent_task (parent_id); - -create index if not exists idx_agent_task_status - on agent_task (status); - -create index if not exists idx_agent_task_created_by - on agent_task (created_by); - -create index if not exists idx_agent_task_created_at - on agent_task (created_at); - -create index if not exists idx_agent_task_issue - on agent_task (issue_id); - -create index if not exists idx_agent_task_retry_count - on agent_task (retry_count); - -create table if not exists admin_user -( - id serial - primary key, - username varchar(255) not null - unique, - password_hash varchar(255) not null, - is_active boolean default true not null, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null -); - -create index if not exists idx_admin_user_username - on admin_user (username); - -create table if not exists admin_role -( - id serial - primary key, - name varchar(255) not null - unique, - description text, - created_at timestamp with time zone default now() not null -); - -create table if not exists admin_permission -( - id serial - primary key, - name varchar(255) not null, - code varchar(255) not null - unique, - description text, - created_at timestamp with time zone default now() not null -); - -create table if not exists admin_user_role -( - user_id integer not null - references admin_user - on delete cascade, - role_id integer not null - references admin_role - on delete cascade, - primary key (user_id, role_id) -); - -create table if not exists admin_role_permission -( - role_id integer not null - references admin_role - on delete cascade, - permission_id integer not null - references admin_permission - on delete cascade, - primary key (role_id, permission_id) -); - -create table if not exists admin_audit_log -( - id bigserial - primary key, - user_id integer not null, - username varchar(255) not null, - action varchar(50) not null, - resource varchar(255) not null, - resource_id varchar(255), - request_params jsonb, - ip_address varchar(255), - user_agent text, - result varchar(20) default 'success'::character varying not null, - error_message text, - created_at timestamp with time zone default now() not null -); - -create index if not exists idx_admin_audit_log_user_id - on admin_audit_log (user_id); - -create index if not exists idx_admin_audit_log_created_at - on admin_audit_log (created_at desc); - -create index if not exists idx_admin_audit_log_action - on admin_audit_log (action); - -create index if not exists idx_admin_audit_log_resource - on admin_audit_log (resource); - -create table if not exists admin_api_token -( - id serial - primary key, - name varchar(255) not null, - token_hash varchar(64) not null - unique, - token_prefix varchar(32) not null, - permissions text[] default '{}'::text[] not null, - created_by integer not null - references admin_user - on delete set null, - created_at timestamp with time zone default now() not null, - last_used_at timestamp with time zone, - expires_at timestamp with time zone, - is_active boolean default true not null -); - -comment on table admin_api_token is 'Admin API Token for programmatic access'; - -create index if not exists idx_admin_api_token_hash - on admin_api_token (token_hash); - -create table if not exists workspace_alert_config -( - id serial - primary key, - workspace_id uuid not null, - alert_type varchar(32) not null, - threshold numeric(10, 4) not null, - email_enabled boolean default true, - enabled boolean default true, - created_by integer, - created_at timestamp with time zone default now(), - updated_at timestamp with time zone default now(), - unique (workspace_id, alert_type) -); - -create index if not exists idx_alert_config_workspace - on workspace_alert_config (workspace_id); - -create table if not exists room_attachment -( - id uuid not null - primary key, - room uuid not null, - message uuid not null, - uploader uuid not null, - file_name varchar(255) not null, - file_size bigint not null, - content_type varchar(100) not null, - s3_key varchar(500) not null, - created_at timestamp with time zone default now() not null -); - -create index if not exists idx_room_attachment_room - on room_attachment (room); - -create index if not exists idx_room_attachment_message - on room_attachment (message); - -create index if not exists idx_room_attachment_uploader - on room_attachment (uploader); - -create table if not exists room_access -( - room uuid not null, - "user" uuid not null, - granted_by uuid not null, - granted_at timestamp with time zone default now() not null, - primary key (room, "user") -); - -create index if not exists idx_room_access_user - on room_access ("user"); - -create table if not exists room_user_state -( - room uuid not null, - "user" uuid not null, - last_read_seq bigint, - do_not_disturb boolean default false not null, - dnd_start_hour smallint, - dnd_end_hour smallint, - joined_at timestamp with time zone, - primary key (room, "user") -); - -create index if not exists idx_room_user_state_user - on room_user_state ("user"); - -create table if not exists project_role_priority -( - id bigserial - primary key, - project_uuid uuid not null, - role_key varchar(64) not null, - display_name varchar(128) not null, - priority integer default 0 not null, - color varchar(32), - created_at timestamp with time zone default now(), - updated_at timestamp with time zone default now(), - unique (project_uuid, role_key) -); - -create index if not exists idx_project_role_priority_project - on project_role_priority (project_uuid); - -create index if not exists idx_project_role_priority_priority - on project_role_priority (project_uuid, priority); - -create table if not exists ai_conversation -( - id uuid default gen_random_uuid() not null - primary key, - user_id uuid not null, - project_id uuid - constraint fk_ai_conv_project - references project - on delete cascade, - scope varchar(16) not null, - title varchar(512), - model varchar(128) default 'gpt-4'::character varying not null, - model_config jsonb, - status varchar(32) default 'active'::character varying not null, - root_message_id uuid, - fork_count integer default 0 not null, - is_shared boolean default false not null, - message_count integer default 0 not null, - token_usage_total integer, - created_at timestamp with time zone default now() not null, - updated_at timestamp with time zone default now() not null, - access_visibility varchar(32) default 'owner'::character varying not null, - can_ask varchar(32) default 'owner'::character varying not null, - project_uid integer, - model_uid uuid, - model_name varchar(256) -); - -create index if not exists idx_ai_conv_user_id - on ai_conversation (user_id); - -create index if not exists idx_ai_conv_project_id - on ai_conversation (project_id); - -create index if not exists idx_ai_conv_scope - on ai_conversation (scope); - -create index if not exists idx_ai_conv_user_created - on ai_conversation (user_id asc, created_at desc); - -create index if not exists idx_ai_conv_project_created - on ai_conversation (project_id asc, created_at desc); - -create index if not exists idx_ai_conv_access_vis - on ai_conversation (access_visibility); - -create index if not exists idx_ai_conv_project_uid - on ai_conversation (project_id, project_uid) - where (project_uid IS NOT NULL); - -create table if not exists ai_message -( - id uuid default gen_random_uuid() not null - primary key, - conversation_id uuid not null - constraint fk_ai_msg_conv - references ai_conversation - on delete cascade, - parent_message_id uuid - constraint fk_ai_msg_parent - references ai_message - on delete set null, - role varchar(16) not null, - content jsonb not null, - model varchar(128), - is_fork_origin boolean default false not null, - stop_reason varchar(32), - input_tokens integer, - output_tokens integer, - latency_ms integer, - metadata jsonb, - room_id uuid, - created_at timestamp with time zone default now() not null -); - -create index if not exists idx_ai_msg_conv - on ai_message (conversation_id, created_at); - -create index if not exists idx_ai_msg_parent - on ai_message (parent_message_id); - -create table if not exists ai_message_fork -( - id uuid default gen_random_uuid() not null - primary key, - source_message_id uuid not null - constraint fk_ai_fork_source - references ai_message - on delete cascade, - fork_message_id uuid not null - constraint fk_ai_fork_fork - references ai_message - on delete cascade, - created_at timestamp with time zone default now() not null -); - -create index if not exists idx_ai_fork_source - on ai_message_fork (source_message_id); - -create index if not exists idx_ai_fork_fork - on ai_message_fork (fork_message_id); - -create table if not exists ai_shared_conversation -( - id uuid default gen_random_uuid() not null - primary key, - conversation_id uuid not null - constraint fk_ai_share_conv - references ai_conversation - on delete cascade, - share_token varchar(128) not null - unique, - created_by uuid not null, - view_count integer default 0 not null, - created_at timestamp with time zone default now() not null, - expires_at timestamp with time zone -); - -create index if not exists idx_ai_share_conv - on ai_shared_conversation (conversation_id); - -create index if not exists idx_ai_share_token - on ai_shared_conversation (share_token); - -create table if not exists ai_token_usage -( - id uuid default gen_random_uuid() not null - primary key, - user_id uuid not null, - conversation_id uuid, - model varchar(128) not null, - input_tokens integer not null, - output_tokens integer not null, - cost_usd numeric(10, 6), - recorded_at timestamp with time zone default now() not null -); - -create index if not exists idx_ai_token_user - on ai_token_usage (user_id); - -create index if not exists idx_ai_token_conv - on ai_token_usage (conversation_id); - -create index if not exists idx_ai_token_recorded - on ai_token_usage (recorded_at); - diff --git a/libs/migrate/sql/issue/issue_down_01.sql b/libs/migrate/sql/issue/issue_down_01.sql new file mode 100644 index 0000000..85f98e9 --- /dev/null +++ b/libs/migrate/sql/issue/issue_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_issue_state; +DROP INDEX IF EXISTS idx_issue_author; +DROP INDEX IF EXISTS idx_issue_project; +DROP TABLE IF EXISTS issue; diff --git a/libs/migrate/sql/issue/issue_up_01.sql b/libs/migrate/sql/issue/issue_up_01.sql new file mode 100644 index 0000000..05d433b --- /dev/null +++ b/libs/migrate/sql/issue/issue_up_01.sql @@ -0,0 +1,25 @@ +create table if not exists issue +( + id uuid not null + primary key, + project uuid not null, + number bigint not null, + title varchar(255) not null, + body text, + state varchar(255) not null, + author uuid not null, + milestone varchar(255), + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + closed_at timestamp with time zone, + created_by_ai boolean default false not null +); + +create index if not exists idx_issue_project + on issue (project); + +create index if not exists idx_issue_author + on issue (author); + +create index if not exists idx_issue_state + on issue (state); diff --git a/libs/migrate/sql/issue_assignee/issue_assignee_down_01.sql b/libs/migrate/sql/issue_assignee/issue_assignee_down_01.sql new file mode 100644 index 0000000..9fae8c2 --- /dev/null +++ b/libs/migrate/sql/issue_assignee/issue_assignee_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_assignee; diff --git a/libs/migrate/sql/issue_assignee/issue_assignee_up_01.sql b/libs/migrate/sql/issue_assignee/issue_assignee_up_01.sql new file mode 100644 index 0000000..8549f09 --- /dev/null +++ b/libs/migrate/sql/issue_assignee/issue_assignee_up_01.sql @@ -0,0 +1,7 @@ +create table if not exists issue_assignee +( + issue uuid not null, + "user" uuid not null, + assigned_at timestamp with time zone not null, + primary key (issue, "user") +); diff --git a/libs/migrate/sql/issue_comment/issue_comment_down_01.sql b/libs/migrate/sql/issue_comment/issue_comment_down_01.sql new file mode 100644 index 0000000..622c11f --- /dev/null +++ b/libs/migrate/sql/issue_comment/issue_comment_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_issue_comment_issue; +DROP TABLE IF EXISTS issue_comment; diff --git a/libs/migrate/sql/issue_comment/issue_comment_up_01.sql b/libs/migrate/sql/issue_comment/issue_comment_up_01.sql new file mode 100644 index 0000000..d936c14 --- /dev/null +++ b/libs/migrate/sql/issue_comment/issue_comment_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists issue_comment +( + id bigserial + primary key, + issue uuid not null, + author uuid not null, + body text not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_issue_comment_issue + on issue_comment (issue); diff --git a/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_down_01.sql b/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_down_01.sql new file mode 100644 index 0000000..d3d0187 --- /dev/null +++ b/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_comment_reaction; diff --git a/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_up_01.sql b/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_up_01.sql new file mode 100644 index 0000000..0b720cf --- /dev/null +++ b/libs/migrate/sql/issue_comment_reaction/issue_comment_reaction_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists issue_comment_reaction +( + comment_id bigint not null, + user_uuid uuid not null, + reaction varchar(255) not null, + created_at timestamp with time zone not null, + primary key (comment_id, user_uuid, reaction) +); diff --git a/libs/migrate/sql/issue_label/issue_label_down_01.sql b/libs/migrate/sql/issue_label/issue_label_down_01.sql new file mode 100644 index 0000000..2ae8000 --- /dev/null +++ b/libs/migrate/sql/issue_label/issue_label_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_label; diff --git a/libs/migrate/sql/issue_label/issue_label_up_01.sql b/libs/migrate/sql/issue_label/issue_label_up_01.sql new file mode 100644 index 0000000..22c14a5 --- /dev/null +++ b/libs/migrate/sql/issue_label/issue_label_up_01.sql @@ -0,0 +1,7 @@ +create table if not exists issue_label +( + issue uuid not null, + label bigint not null, + relation_at timestamp with time zone not null, + primary key (issue, label) +); diff --git a/libs/migrate/sql/issue_pull_request/issue_pull_request_down_01.sql b/libs/migrate/sql/issue_pull_request/issue_pull_request_down_01.sql new file mode 100644 index 0000000..79082e5 --- /dev/null +++ b/libs/migrate/sql/issue_pull_request/issue_pull_request_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_pull_request; diff --git a/libs/migrate/sql/issue_pull_request/issue_pull_request_up_01.sql b/libs/migrate/sql/issue_pull_request/issue_pull_request_up_01.sql new file mode 100644 index 0000000..05d4946 --- /dev/null +++ b/libs/migrate/sql/issue_pull_request/issue_pull_request_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists issue_pull_request +( + issue uuid not null, + repo uuid not null, + number bigint not null, + relation_at timestamp with time zone not null, + primary key (issue, repo, number) +); diff --git a/libs/migrate/sql/issue_reaction/issue_reaction_down_01.sql b/libs/migrate/sql/issue_reaction/issue_reaction_down_01.sql new file mode 100644 index 0000000..f6193d1 --- /dev/null +++ b/libs/migrate/sql/issue_reaction/issue_reaction_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_reaction; diff --git a/libs/migrate/sql/issue_reaction/issue_reaction_up_01.sql b/libs/migrate/sql/issue_reaction/issue_reaction_up_01.sql new file mode 100644 index 0000000..b19a67e --- /dev/null +++ b/libs/migrate/sql/issue_reaction/issue_reaction_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists issue_reaction +( + issue_uuid uuid not null, + user_uuid uuid not null, + reaction varchar(255) not null, + created_at timestamp with time zone not null, + primary key (issue_uuid, user_uuid, reaction) +); diff --git a/libs/migrate/sql/issue_repo/issue_repo_down_01.sql b/libs/migrate/sql/issue_repo/issue_repo_down_01.sql new file mode 100644 index 0000000..4641432 --- /dev/null +++ b/libs/migrate/sql/issue_repo/issue_repo_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_repo; diff --git a/libs/migrate/sql/issue_repo/issue_repo_up_01.sql b/libs/migrate/sql/issue_repo/issue_repo_up_01.sql new file mode 100644 index 0000000..cf3e024 --- /dev/null +++ b/libs/migrate/sql/issue_repo/issue_repo_up_01.sql @@ -0,0 +1,7 @@ +create table if not exists issue_repo +( + issue uuid not null, + repo uuid not null, + relation_at timestamp with time zone not null, + primary key (issue, repo) +); diff --git a/libs/migrate/sql/issue_subscriber/issue_subscriber_down_01.sql b/libs/migrate/sql/issue_subscriber/issue_subscriber_down_01.sql new file mode 100644 index 0000000..84d835b --- /dev/null +++ b/libs/migrate/sql/issue_subscriber/issue_subscriber_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS issue_subscriber; diff --git a/libs/migrate/sql/issue_subscriber/issue_subscriber_up_01.sql b/libs/migrate/sql/issue_subscriber/issue_subscriber_up_01.sql new file mode 100644 index 0000000..168b7a0 --- /dev/null +++ b/libs/migrate/sql/issue_subscriber/issue_subscriber_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists issue_subscriber +( + issue uuid not null, + "user" uuid not null, + subscribed boolean default true not null, + created_at timestamp with time zone not null, + primary key (issue, "user") +); diff --git a/libs/migrate/sql/label/label_down_01.sql b/libs/migrate/sql/label/label_down_01.sql new file mode 100644 index 0000000..58b4e40 --- /dev/null +++ b/libs/migrate/sql/label/label_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_label_project; +DROP TABLE IF EXISTS label; diff --git a/libs/migrate/sql/label/label_up_01.sql b/libs/migrate/sql/label/label_up_01.sql new file mode 100644 index 0000000..f012c9a --- /dev/null +++ b/libs/migrate/sql/label/label_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists label +( + id bigserial + primary key, + project_uuid uuid not null, + name varchar(255) not null, + color varchar(255) not null +); + +create index if not exists idx_label_project + on label (project_uuid); diff --git a/libs/migrate/sql/notify/notify_down_01.sql b/libs/migrate/sql/notify/notify_down_01.sql new file mode 100644 index 0000000..6337ffc --- /dev/null +++ b/libs/migrate/sql/notify/notify_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_notify_created_at; +DROP INDEX IF EXISTS idx_notify_user; +DROP TABLE IF EXISTS notify; diff --git a/libs/migrate/sql/notify/notify_up_01.sql b/libs/migrate/sql/notify/notify_up_01.sql new file mode 100644 index 0000000..3690c62 --- /dev/null +++ b/libs/migrate/sql/notify/notify_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists notify +( + id bigserial + primary key, + user_uuid uuid not null, + title varchar(255) not null, + description text, + content text not null, + url varchar(255), + kind integer not null, + read_at timestamp with time zone, + deleted_at timestamp with time zone, + created_at timestamp with time zone not null +); + +create index if not exists idx_notify_user + on notify (user_uuid); + +create index if not exists idx_notify_created_at + on notify (created_at); diff --git a/libs/migrate/sql/project/project_down_01.sql b/libs/migrate/sql/project/project_down_01.sql new file mode 100644 index 0000000..e9e350e --- /dev/null +++ b/libs/migrate/sql/project/project_down_01.sql @@ -0,0 +1,6 @@ +DROP INDEX IF EXISTS idx_workspace_deleted_at; +DROP INDEX IF EXISTS idx_workspace_slug; +DROP INDEX IF EXISTS idx_project_workspace_id; +DROP INDEX IF EXISTS idx_project_created_by; +DROP INDEX IF EXISTS idx_project_name; +DROP TABLE IF EXISTS project; diff --git a/libs/migrate/sql/project/project_up_01.sql b/libs/migrate/sql/project/project_up_01.sql new file mode 100644 index 0000000..80aeb86 --- /dev/null +++ b/libs/migrate/sql/project/project_up_01.sql @@ -0,0 +1,32 @@ +create table if not exists project +( + id uuid not null + primary key, + name varchar(255) not null, + display_name varchar(255) not null, + avatar_url varchar(255), + description text, + is_public boolean default false not null, + created_by uuid not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + workspace_id uuid + references workspace + on delete set null +); + +create index if not exists idx_project_name + on project (name); + +create index if not exists idx_project_created_by + on project (created_by); + +create index if not exists idx_project_workspace_id + on project (workspace_id) + where (workspace_id IS NOT NULL); + +create unique index if not exists idx_workspace_slug + on workspace (slug); + +create index if not exists idx_workspace_deleted_at + on workspace (deleted_at); diff --git a/libs/migrate/sql/project_access_log/project_access_log_down_01.sql b/libs/migrate/sql/project_access_log/project_access_log_down_01.sql new file mode 100644 index 0000000..efc098f --- /dev/null +++ b/libs/migrate/sql/project_access_log/project_access_log_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_project_access_log_created_at; +DROP INDEX IF EXISTS idx_project_access_log_project; +DROP TABLE IF EXISTS project_access_log; diff --git a/libs/migrate/sql/project_access_log/project_access_log_up_01.sql b/libs/migrate/sql/project_access_log/project_access_log_up_01.sql new file mode 100644 index 0000000..e97c3ee --- /dev/null +++ b/libs/migrate/sql/project_access_log/project_access_log_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists project_access_log +( + id bigserial + primary key, + project uuid not null, + actor_uid uuid, + action varchar(255) not null, + ip_address varchar(255), + user_agent varchar(255), + created_at timestamp with time zone not null +); + +create index if not exists idx_project_access_log_project + on project_access_log (project); + +create index if not exists idx_project_access_log_created_at + on project_access_log (created_at); diff --git a/libs/migrate/sql/project_activity/project_activity_down_01.sql b/libs/migrate/sql/project_activity/project_activity_down_01.sql new file mode 100644 index 0000000..3135f5a --- /dev/null +++ b/libs/migrate/sql/project_activity/project_activity_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_project_activity_event_type; +DROP INDEX IF EXISTS idx_project_activity_created_at; +DROP INDEX IF EXISTS idx_project_activity_project; +DROP TABLE IF EXISTS project_activity; diff --git a/libs/migrate/sql/project_activity/project_activity_up_01.sql b/libs/migrate/sql/project_activity/project_activity_up_01.sql new file mode 100644 index 0000000..4af3537 --- /dev/null +++ b/libs/migrate/sql/project_activity/project_activity_up_01.sql @@ -0,0 +1,25 @@ +create table if not exists project_activity +( + id bigserial + primary key, + project uuid not null, + repo uuid, + actor uuid not null, + event_type varchar(50) not null, + event_id uuid, + event_sub_id bigint, + title varchar(500) not null, + content text, + metadata jsonb, + is_private boolean default false not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_project_activity_project + on project_activity (project); + +create index if not exists idx_project_activity_created_at + on project_activity (created_at desc); + +create index if not exists idx_project_activity_event_type + on project_activity (event_type); diff --git a/libs/migrate/sql/project_audit_log/project_audit_log_down_01.sql b/libs/migrate/sql/project_audit_log/project_audit_log_down_01.sql new file mode 100644 index 0000000..a98adb5 --- /dev/null +++ b/libs/migrate/sql/project_audit_log/project_audit_log_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_project_audit_log_created_at; +DROP INDEX IF EXISTS idx_project_audit_log_project; +DROP TABLE IF EXISTS project_audit_log; diff --git a/libs/migrate/sql/project_audit_log/project_audit_log_up_01.sql b/libs/migrate/sql/project_audit_log/project_audit_log_up_01.sql new file mode 100644 index 0000000..d6d0977 --- /dev/null +++ b/libs/migrate/sql/project_audit_log/project_audit_log_up_01.sql @@ -0,0 +1,18 @@ +create table if not exists project_audit_log +( + id bigserial + primary key, + project uuid not null, + actor uuid not null, + action text not null, + details jsonb, + ip_address varchar(255), + user_agent varchar(255), + created_at timestamp with time zone not null +); + +create index if not exists idx_project_audit_log_project + on project_audit_log (project); + +create index if not exists idx_project_audit_log_created_at + on project_audit_log (created_at); diff --git a/libs/migrate/sql/project_billing/project_billing_down_01.sql b/libs/migrate/sql/project_billing/project_billing_down_01.sql new file mode 100644 index 0000000..f31bcff --- /dev/null +++ b/libs/migrate/sql/project_billing/project_billing_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS project_billing; diff --git a/libs/migrate/sql/project_billing/project_billing_up_01.sql b/libs/migrate/sql/project_billing/project_billing_up_01.sql new file mode 100644 index 0000000..4e75b19 --- /dev/null +++ b/libs/migrate/sql/project_billing/project_billing_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists project_billing +( + project_uuid uuid not null + primary key, + balance numeric default 0.0 not null, + currency text not null, + user_uuid uuid, + updated_at timestamp with time zone not null, + created_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/project_billing_history/project_billing_history_down_01.sql b/libs/migrate/sql/project_billing_history/project_billing_history_down_01.sql new file mode 100644 index 0000000..b6fc8d7 --- /dev/null +++ b/libs/migrate/sql/project_billing_history/project_billing_history_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_billing_history_project; +DROP TABLE IF EXISTS project_billing_history; diff --git a/libs/migrate/sql/project_billing_history/project_billing_history_up_01.sql b/libs/migrate/sql/project_billing_history/project_billing_history_up_01.sql new file mode 100644 index 0000000..2cb02a1 --- /dev/null +++ b/libs/migrate/sql/project_billing_history/project_billing_history_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists project_billing_history +( + uid uuid not null + primary key, + project uuid not null, + "user" uuid, + amount numeric not null, + currency text not null, + reason text not null, + extra jsonb, + created_at timestamp with time zone not null +); + +create index if not exists idx_project_billing_history_project + on project_billing_history (project); diff --git a/libs/migrate/sql/project_board/project_board_down_01.sql b/libs/migrate/sql/project_board/project_board_down_01.sql new file mode 100644 index 0000000..286ae7f --- /dev/null +++ b/libs/migrate/sql/project_board/project_board_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_board_project; +DROP TABLE IF EXISTS project_board; diff --git a/libs/migrate/sql/project_board/project_board_up_01.sql b/libs/migrate/sql/project_board/project_board_up_01.sql new file mode 100644 index 0000000..9091ffe --- /dev/null +++ b/libs/migrate/sql/project_board/project_board_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists project_board +( + id uuid default gen_random_uuid() not null + primary key, + project_uuid uuid not null, + name varchar(255) not null, + description text, + created_by uuid not null, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null +); + +create index if not exists idx_project_board_project + on project_board (project_uuid); diff --git a/libs/migrate/sql/project_board_card/project_board_card_down_01.sql b/libs/migrate/sql/project_board_card/project_board_card_down_01.sql new file mode 100644 index 0000000..81b3411 --- /dev/null +++ b/libs/migrate/sql/project_board_card/project_board_card_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_project_board_card_issue; +DROP INDEX IF EXISTS idx_project_board_card_column; +DROP TABLE IF EXISTS project_board_card; diff --git a/libs/migrate/sql/project_board_card/project_board_card_up_01.sql b/libs/migrate/sql/project_board_card/project_board_card_up_01.sql new file mode 100644 index 0000000..61e7bfd --- /dev/null +++ b/libs/migrate/sql/project_board_card/project_board_card_up_01.sql @@ -0,0 +1,26 @@ +create table if not exists project_board_card +( + id uuid default gen_random_uuid() not null + primary key, + column_uuid uuid not null + references project_board_column + on delete cascade, + issue_id bigint, + project uuid, + title varchar(500) not null, + description text, + position integer default 0 not null, + assignee_id uuid, + due_date timestamp with time zone, + priority varchar(10), + created_by uuid not null, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null +); + +create index if not exists idx_project_board_card_column + on project_board_card (column_uuid); + +create index if not exists idx_project_board_card_issue + on project_board_card (issue_id) + where (issue_id IS NOT NULL); diff --git a/libs/migrate/sql/project_board_column/project_board_column_down_01.sql b/libs/migrate/sql/project_board_column/project_board_column_down_01.sql new file mode 100644 index 0000000..2d89265 --- /dev/null +++ b/libs/migrate/sql/project_board_column/project_board_column_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_board_column_board; +DROP TABLE IF EXISTS project_board_column; diff --git a/libs/migrate/sql/project_board_column/project_board_column_up_01.sql b/libs/migrate/sql/project_board_column/project_board_column_up_01.sql new file mode 100644 index 0000000..819ec3b --- /dev/null +++ b/libs/migrate/sql/project_board_column/project_board_column_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists project_board_column +( + id uuid default gen_random_uuid() not null + primary key, + board_uuid uuid not null + references project_board + on delete cascade, + name varchar(255) not null, + position integer default 0 not null, + wip_limit integer, + color varchar(20) +); + +create index if not exists idx_project_board_column_board + on project_board_column (board_uuid); diff --git a/libs/migrate/sql/project_follow/project_follow_down_01.sql b/libs/migrate/sql/project_follow/project_follow_down_01.sql new file mode 100644 index 0000000..7eb9a24 --- /dev/null +++ b/libs/migrate/sql/project_follow/project_follow_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_follow_project_user; +DROP TABLE IF EXISTS project_follow; diff --git a/libs/migrate/sql/project_follow/project_follow_up_01.sql b/libs/migrate/sql/project_follow/project_follow_up_01.sql new file mode 100644 index 0000000..2915f81 --- /dev/null +++ b/libs/migrate/sql/project_follow/project_follow_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists project_follow +( + id bigserial + primary key, + project uuid not null, + "user" uuid not null, + created_at timestamp with time zone not null, + unique (project, "user") +); + +create unique index if not exists idx_project_follow_project_user + on project_follow (project, "user"); diff --git a/libs/migrate/sql/project_history_name/project_history_name_down_01.sql b/libs/migrate/sql/project_history_name/project_history_name_down_01.sql new file mode 100644 index 0000000..a79f469 --- /dev/null +++ b/libs/migrate/sql/project_history_name/project_history_name_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_history_name_project_uid; +DROP TABLE IF EXISTS project_history_name; diff --git a/libs/migrate/sql/project_history_name/project_history_name_up_01.sql b/libs/migrate/sql/project_history_name/project_history_name_up_01.sql new file mode 100644 index 0000000..6883e68 --- /dev/null +++ b/libs/migrate/sql/project_history_name/project_history_name_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists project_history_name +( + id bigserial + primary key, + project_uid uuid not null, + history_name varchar(255) not null, + changed_at timestamp with time zone not null +); + +create index if not exists idx_project_history_name_project_uid + on project_history_name (project_uid); diff --git a/libs/migrate/sql/project_label/project_label_down_01.sql b/libs/migrate/sql/project_label/project_label_down_01.sql new file mode 100644 index 0000000..20ce5c0 --- /dev/null +++ b/libs/migrate/sql/project_label/project_label_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_label_project; +DROP TABLE IF EXISTS project_label; diff --git a/libs/migrate/sql/project_label/project_label_up_01.sql b/libs/migrate/sql/project_label/project_label_up_01.sql new file mode 100644 index 0000000..7813669 --- /dev/null +++ b/libs/migrate/sql/project_label/project_label_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists project_label +( + id bigserial + primary key, + project_uuid uuid not null, + label_id bigint not null, + relation_at timestamp with time zone not null +); + +create index if not exists idx_project_label_project + on project_label (project_uuid); diff --git a/libs/migrate/sql/project_like/project_like_down_01.sql b/libs/migrate/sql/project_like/project_like_down_01.sql new file mode 100644 index 0000000..565a95c --- /dev/null +++ b/libs/migrate/sql/project_like/project_like_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS project_like; diff --git a/libs/migrate/sql/project_like/project_like_up_01.sql b/libs/migrate/sql/project_like/project_like_up_01.sql new file mode 100644 index 0000000..e6faf33 --- /dev/null +++ b/libs/migrate/sql/project_like/project_like_up_01.sql @@ -0,0 +1,7 @@ +create table if not exists project_like +( + project uuid not null, + "user" uuid not null, + created_at timestamp with time zone not null, + primary key (project, "user") +); diff --git a/libs/migrate/sql/project_member_invitations/project_member_invitations_down_01.sql b/libs/migrate/sql/project_member_invitations/project_member_invitations_down_01.sql new file mode 100644 index 0000000..499ab95 --- /dev/null +++ b/libs/migrate/sql/project_member_invitations/project_member_invitations_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_member_invitations_project_user; +DROP TABLE IF EXISTS project_member_invitations; diff --git a/libs/migrate/sql/project_member_invitations/project_member_invitations_up_01.sql b/libs/migrate/sql/project_member_invitations/project_member_invitations_up_01.sql new file mode 100644 index 0000000..22af1bd --- /dev/null +++ b/libs/migrate/sql/project_member_invitations/project_member_invitations_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists project_member_invitations +( + id bigserial + primary key, + project uuid not null, + "user" uuid not null, + invited_by uuid not null, + scope varchar(255) not null, + accepted boolean default false not null, + accepted_at timestamp with time zone, + rejected boolean default false not null, + rejected_at timestamp with time zone, + created_at timestamp with time zone not null +); + +create index if not exists idx_project_member_invitations_project_user + on project_member_invitations (project, "user"); diff --git a/libs/migrate/sql/project_member_join_answers/project_member_join_answers_down_01.sql b/libs/migrate/sql/project_member_join_answers/project_member_join_answers_down_01.sql new file mode 100644 index 0000000..b7b9519 --- /dev/null +++ b/libs/migrate/sql/project_member_join_answers/project_member_join_answers_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_member_join_answers_request_id; +DROP TABLE IF EXISTS project_member_join_answers; diff --git a/libs/migrate/sql/project_member_join_answers/project_member_join_answers_up_01.sql b/libs/migrate/sql/project_member_join_answers/project_member_join_answers_up_01.sql new file mode 100644 index 0000000..6308816 --- /dev/null +++ b/libs/migrate/sql/project_member_join_answers/project_member_join_answers_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists project_member_join_answers +( + id bigserial + primary key, + project uuid not null, + "user" uuid not null, + request_id bigint not null, + question varchar(255) not null, + answer varchar(255) not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_project_member_join_answers_request_id + on project_member_join_answers (request_id); diff --git a/libs/migrate/sql/project_member_join_request/project_member_join_request_down_01.sql b/libs/migrate/sql/project_member_join_request/project_member_join_request_down_01.sql new file mode 100644 index 0000000..cf6216b --- /dev/null +++ b/libs/migrate/sql/project_member_join_request/project_member_join_request_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_project_member_join_request_status; +DROP INDEX IF EXISTS idx_project_member_join_request_project_user; +DROP TABLE IF EXISTS project_member_join_request; diff --git a/libs/migrate/sql/project_member_join_request/project_member_join_request_up_01.sql b/libs/migrate/sql/project_member_join_request/project_member_join_request_up_01.sql new file mode 100644 index 0000000..c5c7495 --- /dev/null +++ b/libs/migrate/sql/project_member_join_request/project_member_join_request_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists project_member_join_request +( + id bigserial + primary key, + project uuid not null, + "user" uuid not null, + status varchar(255) not null, + message text, + processed_by uuid, + processed_at timestamp with time zone, + reject_reason text, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_project_member_join_request_project_user + on project_member_join_request (project, "user"); + +create index if not exists idx_project_member_join_request_status + on project_member_join_request (status); diff --git a/libs/migrate/sql/project_member_join_settings/project_member_join_settings_down_01.sql b/libs/migrate/sql/project_member_join_settings/project_member_join_settings_down_01.sql new file mode 100644 index 0000000..a116934 --- /dev/null +++ b/libs/migrate/sql/project_member_join_settings/project_member_join_settings_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS project_member_join_settings; diff --git a/libs/migrate/sql/project_member_join_settings/project_member_join_settings_up_01.sql b/libs/migrate/sql/project_member_join_settings/project_member_join_settings_up_01.sql new file mode 100644 index 0000000..f2d72a2 --- /dev/null +++ b/libs/migrate/sql/project_member_join_settings/project_member_join_settings_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists project_member_join_settings +( + id bigserial + primary key, + project uuid not null, + require_approval boolean default false not null, + require_questions boolean default false not null, + questions jsonb not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/project_members/project_members_down_01.sql b/libs/migrate/sql/project_members/project_members_down_01.sql new file mode 100644 index 0000000..409ee63 --- /dev/null +++ b/libs/migrate/sql/project_members/project_members_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_members_project_user; +DROP TABLE IF EXISTS project_members; diff --git a/libs/migrate/sql/project_members/project_members_up_01.sql b/libs/migrate/sql/project_members/project_members_up_01.sql new file mode 100644 index 0000000..5b7855c --- /dev/null +++ b/libs/migrate/sql/project_members/project_members_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists project_members +( + id bigserial + primary key, + project_uuid uuid not null, + user_uuid uuid not null, + scope varchar(255) not null, + joined_at timestamp with time zone not null, + unique (project_uuid, user_uuid) +); + +create unique index if not exists idx_project_members_project_user + on project_members (project_uuid, user_uuid); diff --git a/libs/migrate/sql/project_message_favorite/project_message_favorite_down_01.sql b/libs/migrate/sql/project_message_favorite/project_message_favorite_down_01.sql new file mode 100644 index 0000000..2f75fcc --- /dev/null +++ b/libs/migrate/sql/project_message_favorite/project_message_favorite_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_project_message_favorite_room; +DROP INDEX IF EXISTS idx_project_message_favorite_project_user; +DROP INDEX IF EXISTS idx_project_message_favorite_user_message; +DROP TABLE IF EXISTS project_message_favorite; diff --git a/libs/migrate/sql/project_message_favorite/project_message_favorite_up_01.sql b/libs/migrate/sql/project_message_favorite/project_message_favorite_up_01.sql new file mode 100644 index 0000000..29b45a8 --- /dev/null +++ b/libs/migrate/sql/project_message_favorite/project_message_favorite_up_01.sql @@ -0,0 +1,19 @@ +create table if not exists project_message_favorite +( + uid uuid not null + primary key, + project uuid not null, + room uuid not null, + message uuid not null, + user_uuid uuid not null, + created_at timestamp with time zone not null +); + +create unique index if not exists idx_project_message_favorite_user_message + on project_message_favorite (user_uuid, message); + +create index if not exists idx_project_message_favorite_project_user + on project_message_favorite (project, user_uuid, created_at desc); + +create index if not exists idx_project_message_favorite_room + on project_message_favorite (room); diff --git a/libs/migrate/sql/project_role_priority/project_role_priority_down_01.sql b/libs/migrate/sql/project_role_priority/project_role_priority_down_01.sql new file mode 100644 index 0000000..50bedd0 --- /dev/null +++ b/libs/migrate/sql/project_role_priority/project_role_priority_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_project_role_priority_priority; +DROP INDEX IF EXISTS idx_project_role_priority_project; +DROP TABLE IF EXISTS project_role_priority; diff --git a/libs/migrate/sql/project_role_priority/project_role_priority_up_01.sql b/libs/migrate/sql/project_role_priority/project_role_priority_up_01.sql new file mode 100644 index 0000000..131fd7c --- /dev/null +++ b/libs/migrate/sql/project_role_priority/project_role_priority_up_01.sql @@ -0,0 +1,19 @@ +create table if not exists project_role_priority +( + id bigserial + primary key, + project_uuid uuid not null, + role_key varchar(64) not null, + display_name varchar(128) not null, + priority integer default 0 not null, + color varchar(32), + created_at timestamp with time zone default now(), + updated_at timestamp with time zone default now(), + unique (project_uuid, role_key) +); + +create index if not exists idx_project_role_priority_project + on project_role_priority (project_uuid); + +create index if not exists idx_project_role_priority_priority + on project_role_priority (project_uuid, priority); diff --git a/libs/migrate/sql/project_skill/project_skill_down_01.sql b/libs/migrate/sql/project_skill/project_skill_down_01.sql new file mode 100644 index 0000000..8c01613 --- /dev/null +++ b/libs/migrate/sql/project_skill/project_skill_down_01.sql @@ -0,0 +1,6 @@ +DROP INDEX IF EXISTS idx_project_skill_blob_hash; +DROP INDEX IF EXISTS idx_project_skill_commit_sha; +DROP INDEX IF EXISTS idx_project_skill_source; +DROP INDEX IF EXISTS idx_project_skill_slug; +DROP INDEX IF EXISTS idx_project_skill_project; +DROP TABLE IF EXISTS project_skill; diff --git a/libs/migrate/sql/project_skill/project_skill_up_01.sql b/libs/migrate/sql/project_skill/project_skill_up_01.sql new file mode 100644 index 0000000..0642c6b --- /dev/null +++ b/libs/migrate/sql/project_skill/project_skill_up_01.sql @@ -0,0 +1,35 @@ +create table if not exists project_skill +( + id bigserial + primary key, + project_uuid uuid not null, + slug varchar(255) not null, + name varchar(255) not null, + description text, + source varchar(20) default 'manual'::character varying not null, + repo_id uuid, + content text default ''::text not null, + metadata jsonb default '{}'::jsonb not null, + enabled boolean default true not null, + created_by uuid, + created_at timestamp with time zone default now() not null, + updated_at timestamp with time zone default now() not null, + commit_sha varchar(40), + blob_hash varchar(40), + unique (project_uuid, slug) +); + +create index if not exists idx_project_skill_project + on project_skill (project_uuid); + +create index if not exists idx_project_skill_slug + on project_skill (slug); + +create index if not exists idx_project_skill_source + on project_skill (source); + +create index if not exists idx_project_skill_commit_sha + on project_skill (commit_sha); + +create index if not exists idx_project_skill_blob_hash + on project_skill (blob_hash); diff --git a/libs/migrate/sql/project_watch/project_watch_down_01.sql b/libs/migrate/sql/project_watch/project_watch_down_01.sql new file mode 100644 index 0000000..0f0b198 --- /dev/null +++ b/libs/migrate/sql/project_watch/project_watch_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_project_watch_project_user; +DROP TABLE IF EXISTS project_watch; diff --git a/libs/migrate/sql/project_watch/project_watch_up_01.sql b/libs/migrate/sql/project_watch/project_watch_up_01.sql new file mode 100644 index 0000000..2330c80 --- /dev/null +++ b/libs/migrate/sql/project_watch/project_watch_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists project_watch +( + id bigserial + primary key, + project uuid not null, + "user" uuid not null, + notifications_enabled boolean default true not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + unique (project, "user") +); + +create unique index if not exists idx_project_watch_project_user + on project_watch (project, "user"); diff --git a/libs/migrate/sql/pull_request/pull_request_down_01.sql b/libs/migrate/sql/pull_request/pull_request_down_01.sql new file mode 100644 index 0000000..c064916 --- /dev/null +++ b/libs/migrate/sql/pull_request/pull_request_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_pull_request_status; +DROP INDEX IF EXISTS idx_pull_request_author; +DROP INDEX IF EXISTS idx_pull_request_repo; +DROP TABLE IF EXISTS pull_request; diff --git a/libs/migrate/sql/pull_request/pull_request_up_01.sql b/libs/migrate/sql/pull_request/pull_request_up_01.sql new file mode 100644 index 0000000..fd78d1f --- /dev/null +++ b/libs/migrate/sql/pull_request/pull_request_up_01.sql @@ -0,0 +1,27 @@ +create table if not exists pull_request +( + repo uuid not null, + number bigint not null, + issue uuid not null, + title varchar(255) not null, + body text, + author uuid not null, + base varchar(255) not null, + head varchar(255) not null, + status varchar(255) not null, + merged_by uuid, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + merged_at timestamp with time zone, + created_by_ai boolean default false not null, + primary key (repo, number) +); + +create index if not exists idx_pull_request_repo + on pull_request (repo); + +create index if not exists idx_pull_request_author + on pull_request (author); + +create index if not exists idx_pull_request_status + on pull_request (status); diff --git a/libs/migrate/sql/pull_request_commit/pull_request_commit_down_01.sql b/libs/migrate/sql/pull_request_commit/pull_request_commit_down_01.sql new file mode 100644 index 0000000..c98c3b5 --- /dev/null +++ b/libs/migrate/sql/pull_request_commit/pull_request_commit_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS pull_request_commit; diff --git a/libs/migrate/sql/pull_request_commit/pull_request_commit_up_01.sql b/libs/migrate/sql/pull_request_commit/pull_request_commit_up_01.sql new file mode 100644 index 0000000..3848b05 --- /dev/null +++ b/libs/migrate/sql/pull_request_commit/pull_request_commit_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists pull_request_commit +( + repo uuid not null, + number bigint not null, + commit varchar(255) not null, + message text not null, + author_name varchar(255) not null, + author_email varchar(255) not null, + authored_at timestamp with time zone not null, + committer_name varchar(255) not null, + committer_email varchar(255) not null, + committed_at timestamp with time zone not null, + created_at timestamp with time zone not null, + primary key (repo, number, commit) +); diff --git a/libs/migrate/sql/pull_request_review/pull_request_review_down_01.sql b/libs/migrate/sql/pull_request_review/pull_request_review_down_01.sql new file mode 100644 index 0000000..abc5156 --- /dev/null +++ b/libs/migrate/sql/pull_request_review/pull_request_review_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS pull_request_review; diff --git a/libs/migrate/sql/pull_request_review/pull_request_review_up_01.sql b/libs/migrate/sql/pull_request_review/pull_request_review_up_01.sql new file mode 100644 index 0000000..2607b57 --- /dev/null +++ b/libs/migrate/sql/pull_request_review/pull_request_review_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists pull_request_review +( + repo uuid not null, + number bigint not null, + reviewer uuid not null, + state varchar(255) not null, + body text, + submitted_at timestamp with time zone, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + primary key (repo, number, reviewer) +); diff --git a/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_down_01.sql b/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_down_01.sql new file mode 100644 index 0000000..6148d86 --- /dev/null +++ b/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS pull_request_review_comment; diff --git a/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_up_01.sql b/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_up_01.sql new file mode 100644 index 0000000..471a92b --- /dev/null +++ b/libs/migrate/sql/pull_request_review_comment/pull_request_review_comment_up_01.sql @@ -0,0 +1,18 @@ +create table if not exists pull_request_review_comment +( + repo uuid not null, + number bigint not null, + id bigint not null, + review uuid, + path text, + side varchar(255), + line bigint, + old_line bigint, + body text not null, + author uuid not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + resolved boolean default false not null, + in_reply_to bigint, + primary key (repo, number, id) +); diff --git a/libs/migrate/sql/pull_request_review_request/pull_request_review_request_down_01.sql b/libs/migrate/sql/pull_request_review_request/pull_request_review_request_down_01.sql new file mode 100644 index 0000000..e9b8808 --- /dev/null +++ b/libs/migrate/sql/pull_request_review_request/pull_request_review_request_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS pull_request_review_request; diff --git a/libs/migrate/sql/pull_request_review_request/pull_request_review_request_up_01.sql b/libs/migrate/sql/pull_request_review_request/pull_request_review_request_up_01.sql new file mode 100644 index 0000000..ecb1bc1 --- /dev/null +++ b/libs/migrate/sql/pull_request_review_request/pull_request_review_request_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists pull_request_review_request +( + repo uuid not null, + number bigint not null, + reviewer uuid not null, + requested_by uuid not null, + requested_at timestamp with time zone default now() not null, + dismissed_at timestamp with time zone, + dismissed_by uuid, + primary key (repo, number, reviewer) +); diff --git a/libs/migrate/sql/repo/repo_down_01.sql b/libs/migrate/sql/repo/repo_down_01.sql new file mode 100644 index 0000000..528631d --- /dev/null +++ b/libs/migrate/sql/repo/repo_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_repo_repo_name; +DROP INDEX IF EXISTS idx_repo_project; +DROP TABLE IF EXISTS repo; diff --git a/libs/migrate/sql/repo/repo_up_01.sql b/libs/migrate/sql/repo/repo_up_01.sql new file mode 100644 index 0000000..c1a16a6 --- /dev/null +++ b/libs/migrate/sql/repo/repo_up_01.sql @@ -0,0 +1,21 @@ +create table if not exists repo +( + id uuid not null + primary key, + repo_name varchar(255) not null, + project uuid not null, + description text, + default_branch varchar(255) not null, + is_private boolean default false not null, + storage_path varchar(255) not null, + created_by uuid not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + ai_code_review_enabled boolean default false not null +); + +create index if not exists idx_repo_project + on repo (project); + +create index if not exists idx_repo_repo_name + on repo (repo_name); diff --git a/libs/migrate/sql/repo_branch/repo_branch_down_01.sql b/libs/migrate/sql/repo_branch/repo_branch_down_01.sql new file mode 100644 index 0000000..fee65ce --- /dev/null +++ b/libs/migrate/sql/repo_branch/repo_branch_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_branch_repo; +DROP TABLE IF EXISTS repo_branch; diff --git a/libs/migrate/sql/repo_branch/repo_branch_up_01.sql b/libs/migrate/sql/repo_branch/repo_branch_up_01.sql new file mode 100644 index 0000000..977fe4d --- /dev/null +++ b/libs/migrate/sql/repo_branch/repo_branch_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists repo_branch +( + repo uuid not null, + name varchar(255) not null, + oid varchar(255) not null, + upstream varchar(255), + head boolean default false not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + primary key (repo, name) +); + +create index if not exists idx_repo_branch_repo + on repo_branch (repo); diff --git a/libs/migrate/sql/repo_branch_protect/repo_branch_protect_down_01.sql b/libs/migrate/sql/repo_branch_protect/repo_branch_protect_down_01.sql new file mode 100644 index 0000000..0d6a065 --- /dev/null +++ b/libs/migrate/sql/repo_branch_protect/repo_branch_protect_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_branch_protect_repo_branch; +DROP TABLE IF EXISTS repo_branch_protect; diff --git a/libs/migrate/sql/repo_branch_protect/repo_branch_protect_up_01.sql b/libs/migrate/sql/repo_branch_protect/repo_branch_protect_up_01.sql new file mode 100644 index 0000000..b68eaeb --- /dev/null +++ b/libs/migrate/sql/repo_branch_protect/repo_branch_protect_up_01.sql @@ -0,0 +1,21 @@ +create table if not exists repo_branch_protect +( + id bigserial + primary key, + repo_uuid uuid not null, + branch varchar(255) not null, + forbid_push boolean default false not null, + forbid_pull boolean default false not null, + forbid_merge boolean default false not null, + forbid_deletion boolean default false not null, + forbid_force_push boolean default false not null, + forbid_tag_push boolean default false not null, + required_approvals integer default 0 not null, + dismiss_stale_reviews boolean default false not null, + require_linear_history boolean default false not null, + allow_fork_syncing boolean default true not null, + unique (repo_uuid, branch) +); + +create unique index if not exists idx_repo_branch_protect_repo_branch + on repo_branch_protect (repo_uuid, branch); diff --git a/libs/migrate/sql/repo_collaborator/repo_collaborator_down_01.sql b/libs/migrate/sql/repo_collaborator/repo_collaborator_down_01.sql new file mode 100644 index 0000000..00f557d --- /dev/null +++ b/libs/migrate/sql/repo_collaborator/repo_collaborator_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS repo_collaborator; diff --git a/libs/migrate/sql/repo_collaborator/repo_collaborator_up_01.sql b/libs/migrate/sql/repo_collaborator/repo_collaborator_up_01.sql new file mode 100644 index 0000000..e8c8293 --- /dev/null +++ b/libs/migrate/sql/repo_collaborator/repo_collaborator_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists repo_collaborator +( + repo uuid not null, + "user" uuid not null, + scope varchar(255) not null, + created_at timestamp with time zone not null, + primary key (repo, "user") +); diff --git a/libs/migrate/sql/repo_commit/repo_commit_down_01.sql b/libs/migrate/sql/repo_commit/repo_commit_down_01.sql new file mode 100644 index 0000000..d6bfd58 --- /dev/null +++ b/libs/migrate/sql/repo_commit/repo_commit_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_repo_commit_oid; +DROP INDEX IF EXISTS idx_repo_commit_repo; +DROP TABLE IF EXISTS repo_commit; diff --git a/libs/migrate/sql/repo_commit/repo_commit_up_01.sql b/libs/migrate/sql/repo_commit/repo_commit_up_01.sql new file mode 100644 index 0000000..fe18008 --- /dev/null +++ b/libs/migrate/sql/repo_commit/repo_commit_up_01.sql @@ -0,0 +1,22 @@ +create table if not exists repo_commit +( + id bigserial + primary key, + repo uuid not null, + oid varchar(255) not null, + author_name varchar(255) not null, + author_email varchar(255) not null, + author uuid, + commiter_name varchar(255) not null, + commiter_email varchar(255) not null, + commiter uuid, + message text not null, + parent jsonb not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_repo_commit_repo + on repo_commit (repo); + +create index if not exists idx_repo_commit_oid + on repo_commit (oid); diff --git a/libs/migrate/sql/repo_fork/repo_fork_down_01.sql b/libs/migrate/sql/repo_fork/repo_fork_down_01.sql new file mode 100644 index 0000000..ac88101 --- /dev/null +++ b/libs/migrate/sql/repo_fork/repo_fork_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_repo_fork_forked_repo; +DROP INDEX IF EXISTS idx_repo_fork_parent_repo; +DROP TABLE IF EXISTS repo_fork; diff --git a/libs/migrate/sql/repo_fork/repo_fork_up_01.sql b/libs/migrate/sql/repo_fork/repo_fork_up_01.sql new file mode 100644 index 0000000..2a3b2ef --- /dev/null +++ b/libs/migrate/sql/repo_fork/repo_fork_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists repo_fork +( + id bigserial + primary key, + parent_repo uuid not null, + forked_repo uuid not null, + forked_by uuid not null, + forked_at timestamp with time zone not null +); + +create index if not exists idx_repo_fork_parent_repo + on repo_fork (parent_repo); + +create unique index if not exists idx_repo_fork_forked_repo + on repo_fork (forked_repo); diff --git a/libs/migrate/sql/repo_history_name/repo_history_name_down_01.sql b/libs/migrate/sql/repo_history_name/repo_history_name_down_01.sql new file mode 100644 index 0000000..7629167 --- /dev/null +++ b/libs/migrate/sql/repo_history_name/repo_history_name_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_history_name_repo; +DROP TABLE IF EXISTS repo_history_name; diff --git a/libs/migrate/sql/repo_history_name/repo_history_name_up_01.sql b/libs/migrate/sql/repo_history_name/repo_history_name_up_01.sql new file mode 100644 index 0000000..91fe282 --- /dev/null +++ b/libs/migrate/sql/repo_history_name/repo_history_name_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists repo_history_name +( + id bigserial + primary key, + repo_uuid uuid not null, + project_uid uuid not null, + name varchar(255) not null, + change_at timestamp with time zone not null +); + +create index if not exists idx_repo_history_name_repo + on repo_history_name (repo_uuid); diff --git a/libs/migrate/sql/repo_hook/repo_hook_down_01.sql b/libs/migrate/sql/repo_hook/repo_hook_down_01.sql new file mode 100644 index 0000000..b3a3c9a --- /dev/null +++ b/libs/migrate/sql/repo_hook/repo_hook_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_hook_repo; +DROP TABLE IF EXISTS repo_hook; diff --git a/libs/migrate/sql/repo_hook/repo_hook_up_01.sql b/libs/migrate/sql/repo_hook/repo_hook_up_01.sql new file mode 100644 index 0000000..60e2740 --- /dev/null +++ b/libs/migrate/sql/repo_hook/repo_hook_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists repo_hook +( + id bigserial + primary key, + repo_uuid uuid not null, + event jsonb not null, + script text not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_repo_hook_repo + on repo_hook (repo_uuid); diff --git a/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_down_01.sql b/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_down_01.sql new file mode 100644 index 0000000..4a31255 --- /dev/null +++ b/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS repo_lfs_lock; diff --git a/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_up_01.sql b/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_up_01.sql new file mode 100644 index 0000000..81ffb7b --- /dev/null +++ b/libs/migrate/sql/repo_lfs_lock/repo_lfs_lock_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists repo_lfs_lock +( + repo_uuid uuid not null, + path varchar(255) not null, + lock_type varchar(255) not null, + locked_by uuid not null, + locked_at timestamp with time zone not null, + unlocked_at timestamp with time zone, + primary key (repo_uuid, path) +); diff --git a/libs/migrate/sql/repo_lfs_object/repo_lfs_object_down_01.sql b/libs/migrate/sql/repo_lfs_object/repo_lfs_object_down_01.sql new file mode 100644 index 0000000..c16f140 --- /dev/null +++ b/libs/migrate/sql/repo_lfs_object/repo_lfs_object_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_lfs_object_repo_oid; +DROP TABLE IF EXISTS repo_lfs_object; diff --git a/libs/migrate/sql/repo_lfs_object/repo_lfs_object_up_01.sql b/libs/migrate/sql/repo_lfs_object/repo_lfs_object_up_01.sql new file mode 100644 index 0000000..5fee181 --- /dev/null +++ b/libs/migrate/sql/repo_lfs_object/repo_lfs_object_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists repo_lfs_object +( + id bigserial + primary key, + oid varchar(255) not null, + repo_uuid uuid not null, + size bigint not null, + storage_path varchar(255) not null, + uploaded_by uuid, + uploaded_at timestamp with time zone not null +); + +create index if not exists idx_repo_lfs_object_repo_oid + on repo_lfs_object (repo_uuid, oid); diff --git a/libs/migrate/sql/repo_lock/repo_lock_down_01.sql b/libs/migrate/sql/repo_lock/repo_lock_down_01.sql new file mode 100644 index 0000000..cd0322e --- /dev/null +++ b/libs/migrate/sql/repo_lock/repo_lock_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS repo_lock; diff --git a/libs/migrate/sql/repo_lock/repo_lock_up_01.sql b/libs/migrate/sql/repo_lock/repo_lock_up_01.sql new file mode 100644 index 0000000..9943ef5 --- /dev/null +++ b/libs/migrate/sql/repo_lock/repo_lock_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists repo_lock +( + repo_uuid uuid not null, + path varchar(255) not null, + lock_type varchar(255) not null, + locked_by uuid not null, + acquired_at timestamp with time zone not null, + released_at timestamp with time zone, + primary key (repo_uuid, path) +); diff --git a/libs/migrate/sql/repo_star/repo_star_down_01.sql b/libs/migrate/sql/repo_star/repo_star_down_01.sql new file mode 100644 index 0000000..1487f57 --- /dev/null +++ b/libs/migrate/sql/repo_star/repo_star_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_star_repo_user; +DROP TABLE IF EXISTS repo_star; diff --git a/libs/migrate/sql/repo_star/repo_star_up_01.sql b/libs/migrate/sql/repo_star/repo_star_up_01.sql new file mode 100644 index 0000000..acf5363 --- /dev/null +++ b/libs/migrate/sql/repo_star/repo_star_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists repo_star +( + id bigserial + primary key, + repo_uuid uuid not null, + user_uuid uuid not null, + created_at timestamp with time zone not null, + unique (repo_uuid, user_uuid) +); + +create unique index if not exists idx_repo_star_repo_user + on repo_star (repo_uuid, user_uuid); diff --git a/libs/migrate/sql/repo_tag/repo_tag_down_01.sql b/libs/migrate/sql/repo_tag/repo_tag_down_01.sql new file mode 100644 index 0000000..e4c5fa1 --- /dev/null +++ b/libs/migrate/sql/repo_tag/repo_tag_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS repo_tag; diff --git a/libs/migrate/sql/repo_tag/repo_tag_up_01.sql b/libs/migrate/sql/repo_tag/repo_tag_up_01.sql new file mode 100644 index 0000000..53e9dc8 --- /dev/null +++ b/libs/migrate/sql/repo_tag/repo_tag_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists repo_tag +( + repo_uuid uuid not null, + name varchar(255) not null, + oid varchar(255) not null, + color varchar(255), + description text, + created_at timestamp with time zone not null, + tagger_name varchar(255) not null, + tagger_email varchar(255) not null, + tagger_uuid uuid, + primary key (repo_uuid, name) +); diff --git a/libs/migrate/sql/repo_upstream/repo_upstream_down_01.sql b/libs/migrate/sql/repo_upstream/repo_upstream_down_01.sql new file mode 100644 index 0000000..e21122d --- /dev/null +++ b/libs/migrate/sql/repo_upstream/repo_upstream_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_upstream_repo; +DROP TABLE IF EXISTS repo_upstream; diff --git a/libs/migrate/sql/repo_upstream/repo_upstream_up_01.sql b/libs/migrate/sql/repo_upstream/repo_upstream_up_01.sql new file mode 100644 index 0000000..01436f7 --- /dev/null +++ b/libs/migrate/sql/repo_upstream/repo_upstream_up_01.sql @@ -0,0 +1,18 @@ +create table if not exists repo_upstream +( + id bigserial + primary key, + repo_uuid uuid not null + unique, + source_url varchar(255) not null, + direction varchar(255) not null, + schedule_cron varchar(255), + last_run_at timestamp with time zone, + next_run_at timestamp with time zone, + status varchar(255) not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create unique index if not exists idx_repo_upstream_repo + on repo_upstream (repo_uuid); diff --git a/libs/migrate/sql/repo_watch/repo_watch_down_01.sql b/libs/migrate/sql/repo_watch/repo_watch_down_01.sql new file mode 100644 index 0000000..86056bd --- /dev/null +++ b/libs/migrate/sql/repo_watch/repo_watch_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_watch_user_repo; +DROP TABLE IF EXISTS repo_watch; diff --git a/libs/migrate/sql/repo_watch/repo_watch_up_01.sql b/libs/migrate/sql/repo_watch/repo_watch_up_01.sql new file mode 100644 index 0000000..a1ed147 --- /dev/null +++ b/libs/migrate/sql/repo_watch/repo_watch_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists repo_watch +( + id bigserial + primary key, + user_uuid uuid not null, + repo_uuid uuid not null, + show_dashboard boolean default false not null, + notify_email boolean default false not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + unique (user_uuid, repo_uuid) +); + +create unique index if not exists idx_repo_watch_user_repo + on repo_watch (user_uuid, repo_uuid); diff --git a/libs/migrate/sql/repo_webhook/repo_webhook_down_01.sql b/libs/migrate/sql/repo_webhook/repo_webhook_down_01.sql new file mode 100644 index 0000000..4796c2e --- /dev/null +++ b/libs/migrate/sql/repo_webhook/repo_webhook_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_repo_webhook_repo; +DROP TABLE IF EXISTS repo_webhook; diff --git a/libs/migrate/sql/repo_webhook/repo_webhook_up_01.sql b/libs/migrate/sql/repo_webhook/repo_webhook_up_01.sql new file mode 100644 index 0000000..8ab1cf6 --- /dev/null +++ b/libs/migrate/sql/repo_webhook/repo_webhook_up_01.sql @@ -0,0 +1,16 @@ +create table if not exists repo_webhook +( + id bigserial + primary key, + repo_uuid uuid not null, + event jsonb not null, + url varchar(255), + access_key varchar(255), + secret_key varchar(255), + created_at timestamp with time zone not null, + last_delivered_at timestamp with time zone, + touch_count bigint default 0 not null +); + +create index if not exists idx_repo_webhook_repo + on repo_webhook (repo_uuid); diff --git a/libs/migrate/sql/room/room_down_01.sql b/libs/migrate/sql/room/room_down_01.sql new file mode 100644 index 0000000..654bf1d --- /dev/null +++ b/libs/migrate/sql/room/room_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_room_category; +DROP INDEX IF EXISTS idx_room_project; +DROP TABLE IF EXISTS room; diff --git a/libs/migrate/sql/room/room_up_01.sql b/libs/migrate/sql/room/room_up_01.sql new file mode 100644 index 0000000..2043a27 --- /dev/null +++ b/libs/migrate/sql/room/room_up_01.sql @@ -0,0 +1,18 @@ +create table if not exists room +( + id uuid not null + primary key, + project uuid not null, + room_name varchar(255) not null, + public boolean default false not null, + category uuid, + created_by uuid not null, + created_at timestamp with time zone not null, + last_msg_at timestamp with time zone not null +); + +create index if not exists idx_room_project + on room (project); + +create index if not exists idx_room_category + on room (category); diff --git a/libs/migrate/sql/room_access/room_access_down_01.sql b/libs/migrate/sql/room_access/room_access_down_01.sql new file mode 100644 index 0000000..e25b2c7 --- /dev/null +++ b/libs/migrate/sql/room_access/room_access_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_access_user; +DROP TABLE IF EXISTS room_access; diff --git a/libs/migrate/sql/room_access/room_access_up_01.sql b/libs/migrate/sql/room_access/room_access_up_01.sql new file mode 100644 index 0000000..89e0d32 --- /dev/null +++ b/libs/migrate/sql/room_access/room_access_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists room_access +( + room uuid not null, + "user" uuid not null, + granted_by uuid not null, + granted_at timestamp with time zone default now() not null, + primary key (room, "user") +); + +create index if not exists idx_room_access_user + on room_access ("user"); diff --git a/libs/migrate/sql/room_ai/room_ai_down_01.sql b/libs/migrate/sql/room_ai/room_ai_down_01.sql new file mode 100644 index 0000000..08e9509 --- /dev/null +++ b/libs/migrate/sql/room_ai/room_ai_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_ai_agent_type; +DROP TABLE IF EXISTS room_ai; diff --git a/libs/migrate/sql/room_ai/room_ai_up_01.sql b/libs/migrate/sql/room_ai/room_ai_up_01.sql new file mode 100644 index 0000000..ec35d93 --- /dev/null +++ b/libs/migrate/sql/room_ai/room_ai_up_01.sql @@ -0,0 +1,24 @@ +create table if not exists room_ai +( + room uuid not null, + model uuid not null, + version uuid, + call_count bigint default 0 not null, + last_call_at timestamp with time zone, + history_limit bigint, + system_prompt text, + temperature double precision, + max_tokens bigint, + use_exact boolean default false not null, + think boolean default false not null, + min_score real, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + stream boolean default true not null, + agent_type varchar(50), + primary key (room, model) +); + +create index if not exists idx_room_ai_agent_type + on room_ai (agent_type) + where (agent_type IS NOT NULL); diff --git a/libs/migrate/sql/room_attachment/room_attachment_down_01.sql b/libs/migrate/sql/room_attachment/room_attachment_down_01.sql new file mode 100644 index 0000000..f1a4cf4 --- /dev/null +++ b/libs/migrate/sql/room_attachment/room_attachment_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_room_attachment_uploader; +DROP INDEX IF EXISTS idx_room_attachment_message; +DROP INDEX IF EXISTS idx_room_attachment_room; +DROP TABLE IF EXISTS room_attachment; diff --git a/libs/migrate/sql/room_attachment/room_attachment_up_01.sql b/libs/migrate/sql/room_attachment/room_attachment_up_01.sql new file mode 100644 index 0000000..4512737 --- /dev/null +++ b/libs/migrate/sql/room_attachment/room_attachment_up_01.sql @@ -0,0 +1,22 @@ +create table if not exists room_attachment +( + id uuid not null + primary key, + room uuid not null, + message uuid not null, + uploader uuid not null, + file_name varchar(255) not null, + file_size bigint not null, + content_type varchar(100) not null, + s3_key varchar(500) not null, + created_at timestamp with time zone default now() not null +); + +create index if not exists idx_room_attachment_room + on room_attachment (room); + +create index if not exists idx_room_attachment_message + on room_attachment (message); + +create index if not exists idx_room_attachment_uploader + on room_attachment (uploader); diff --git a/libs/migrate/sql/room_category/room_category_down_01.sql b/libs/migrate/sql/room_category/room_category_down_01.sql new file mode 100644 index 0000000..3da6ce3 --- /dev/null +++ b/libs/migrate/sql/room_category/room_category_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_category_project; +DROP TABLE IF EXISTS room_category; diff --git a/libs/migrate/sql/room_category/room_category_up_01.sql b/libs/migrate/sql/room_category/room_category_up_01.sql new file mode 100644 index 0000000..3d03340 --- /dev/null +++ b/libs/migrate/sql/room_category/room_category_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists room_category +( + id uuid not null + primary key, + project_uuid uuid not null, + name varchar(255) not null, + position integer not null, + created_by uuid not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_room_category_project + on room_category (project_uuid); diff --git a/libs/migrate/sql/room_compact_summary/room_compact_summary_down_01.sql b/libs/migrate/sql/room_compact_summary/room_compact_summary_down_01.sql new file mode 100644 index 0000000..302fdb3 --- /dev/null +++ b/libs/migrate/sql/room_compact_summary/room_compact_summary_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_compact_summary_room_to_seq; +DROP TABLE IF EXISTS room_compact_summary; diff --git a/libs/migrate/sql/room_compact_summary.sql b/libs/migrate/sql/room_compact_summary/room_compact_summary_up_01.sql similarity index 100% rename from libs/migrate/sql/room_compact_summary.sql rename to libs/migrate/sql/room_compact_summary/room_compact_summary_up_01.sql diff --git a/libs/migrate/sql/room_message/room_message_down_01.sql b/libs/migrate/sql/room_message/room_message_down_01.sql new file mode 100644 index 0000000..c16b11f --- /dev/null +++ b/libs/migrate/sql/room_message/room_message_down_01.sql @@ -0,0 +1,6 @@ +DROP INDEX IF EXISTS idx_room_message_model_id; +DROP INDEX IF EXISTS idx_room_message_content_tsv; +DROP INDEX IF EXISTS idx_room_message_send_at; +DROP INDEX IF EXISTS idx_room_message_thread; +DROP INDEX IF EXISTS idx_room_message_room_seq; +DROP TABLE IF EXISTS room_message; diff --git a/libs/migrate/sql/room_message/room_message_up_01.sql b/libs/migrate/sql/room_message/room_message_up_01.sql new file mode 100644 index 0000000..0440af6 --- /dev/null +++ b/libs/migrate/sql/room_message/room_message_up_01.sql @@ -0,0 +1,36 @@ +create table if not exists room_message +( + id uuid not null + primary key, + seq bigint not null, + room uuid not null, + sender_type varchar(255) not null, + sender_id uuid, + thread uuid, + content text not null, + content_type varchar(255) not null, + edited_at timestamp with time zone, + send_at timestamp with time zone not null, + revoked timestamp with time zone, + revoked_by uuid, + in_reply_to uuid, + content_tsv tsvector, + model_id uuid, + thinking_content text +); + +create index if not exists idx_room_message_room_seq + on room_message (room, seq); + +create index if not exists idx_room_message_thread + on room_message (thread); + +create index if not exists idx_room_message_send_at + on room_message (send_at); + +create index if not exists idx_room_message_content_tsv + on room_message using gin (content_tsv); + +create index if not exists idx_room_message_model_id + on room_message (model_id) + where (model_id IS NOT NULL); diff --git a/libs/migrate/sql/room_message_edit_history/room_message_edit_history_down_01.sql b/libs/migrate/sql/room_message_edit_history/room_message_edit_history_down_01.sql new file mode 100644 index 0000000..5cc7622 --- /dev/null +++ b/libs/migrate/sql/room_message_edit_history/room_message_edit_history_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_room_message_edit_history_user; +DROP INDEX IF EXISTS idx_room_message_edit_history_message; +DROP TABLE IF EXISTS room_message_edit_history; diff --git a/libs/migrate/sql/room_message_edit_history/room_message_edit_history_up_01.sql b/libs/migrate/sql/room_message_edit_history/room_message_edit_history_up_01.sql new file mode 100644 index 0000000..3804fc2 --- /dev/null +++ b/libs/migrate/sql/room_message_edit_history/room_message_edit_history_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists room_message_edit_history +( + id uuid not null + primary key, + message uuid not null + references room_message + on delete cascade, + "user" uuid not null + references "user" + on delete cascade, + old_content text not null, + new_content text not null, + edited_at timestamp with time zone default now() not null +); + +create index if not exists idx_room_message_edit_history_message + on room_message_edit_history (message); + +create index if not exists idx_room_message_edit_history_user + on room_message_edit_history ("user"); diff --git a/libs/migrate/sql/room_message_reaction/room_message_reaction_down_01.sql b/libs/migrate/sql/room_message_reaction/room_message_reaction_down_01.sql new file mode 100644 index 0000000..7eab489 --- /dev/null +++ b/libs/migrate/sql/room_message_reaction/room_message_reaction_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_room_message_reaction_room; +DROP INDEX IF EXISTS idx_room_message_reaction_user; +DROP INDEX IF EXISTS idx_room_message_reaction_message; +DROP TABLE IF EXISTS room_message_reaction; diff --git a/libs/migrate/sql/room_message_reaction/room_message_reaction_up_01.sql b/libs/migrate/sql/room_message_reaction/room_message_reaction_up_01.sql new file mode 100644 index 0000000..58bbe2b --- /dev/null +++ b/libs/migrate/sql/room_message_reaction/room_message_reaction_up_01.sql @@ -0,0 +1,26 @@ +create table if not exists room_message_reaction +( + id uuid not null + primary key, + room uuid not null + references room + on delete cascade, + message uuid not null + references room_message + on delete cascade, + "user" uuid not null + references "user" + on delete cascade, + emoji varchar(50) not null, + created_at timestamp with time zone default now() not null, + unique (message, "user", emoji) +); + +create index if not exists idx_room_message_reaction_message + on room_message_reaction (message); + +create index if not exists idx_room_message_reaction_user + on room_message_reaction ("user"); + +create index if not exists idx_room_message_reaction_room + on room_message_reaction (room); diff --git a/libs/migrate/sql/room_notifications/room_notifications_down_01.sql b/libs/migrate/sql/room_notifications/room_notifications_down_01.sql new file mode 100644 index 0000000..0ce0eb4 --- /dev/null +++ b/libs/migrate/sql/room_notifications/room_notifications_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_room_notifications_expires_at; +DROP INDEX IF EXISTS idx_room_notifications_user_id_created_at; +DROP INDEX IF EXISTS idx_room_notifications_user_id_is_read; +DROP TABLE IF EXISTS room_notifications; diff --git a/libs/migrate/sql/room_notifications/room_notifications_up_01.sql b/libs/migrate/sql/room_notifications/room_notifications_up_01.sql new file mode 100644 index 0000000..fb3cfac --- /dev/null +++ b/libs/migrate/sql/room_notifications/room_notifications_up_01.sql @@ -0,0 +1,29 @@ +create table if not exists room_notifications +( + id uuid not null + primary key, + room uuid, + project uuid, + user_id uuid, + notification_type varchar(255) not null, + related_message_id uuid, + related_user_id uuid, + related_room_id uuid, + title varchar(255) not null, + content text, + metadata jsonb, + is_read boolean default false not null, + is_archived boolean default false not null, + created_at timestamp with time zone not null, + read_at timestamp with time zone, + expires_at timestamp with time zone +); + +create index if not exists idx_room_notifications_user_id_is_read + on room_notifications (user_id, is_read); + +create index if not exists idx_room_notifications_user_id_created_at + on room_notifications (user_id, created_at); + +create index if not exists idx_room_notifications_expires_at + on room_notifications (expires_at); diff --git a/libs/migrate/sql/room_pin/room_pin_down_01.sql b/libs/migrate/sql/room_pin/room_pin_down_01.sql new file mode 100644 index 0000000..7bc3a35 --- /dev/null +++ b/libs/migrate/sql/room_pin/room_pin_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS room_pin; diff --git a/libs/migrate/sql/room_pin/room_pin_up_01.sql b/libs/migrate/sql/room_pin/room_pin_up_01.sql new file mode 100644 index 0000000..4536f70 --- /dev/null +++ b/libs/migrate/sql/room_pin/room_pin_up_01.sql @@ -0,0 +1,8 @@ +create table if not exists room_pin +( + room uuid not null, + message uuid not null, + pinned_by uuid not null, + pinned_at timestamp with time zone not null, + primary key (room, message) +); diff --git a/libs/migrate/sql/room_thread/room_thread_down_01.sql b/libs/migrate/sql/room_thread/room_thread_down_01.sql new file mode 100644 index 0000000..3be93da --- /dev/null +++ b/libs/migrate/sql/room_thread/room_thread_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_thread_room; +DROP TABLE IF EXISTS room_thread; diff --git a/libs/migrate/sql/room_thread/room_thread_up_01.sql b/libs/migrate/sql/room_thread/room_thread_up_01.sql new file mode 100644 index 0000000..149ff5e --- /dev/null +++ b/libs/migrate/sql/room_thread/room_thread_up_01.sql @@ -0,0 +1,16 @@ +create table if not exists room_thread +( + id uuid not null + primary key, + room uuid not null, + parent bigint not null, + created_by uuid not null, + participants jsonb not null, + last_message_at timestamp with time zone not null, + last_message_preview text, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_room_thread_room + on room_thread (room); diff --git a/libs/migrate/sql/room_user_state/room_user_state_down_01.sql b/libs/migrate/sql/room_user_state/room_user_state_down_01.sql new file mode 100644 index 0000000..d61e9f1 --- /dev/null +++ b/libs/migrate/sql/room_user_state/room_user_state_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_room_user_state_user; +DROP TABLE IF EXISTS room_user_state; diff --git a/libs/migrate/sql/room_user_state/room_user_state_up_01.sql b/libs/migrate/sql/room_user_state/room_user_state_up_01.sql new file mode 100644 index 0000000..35e2c75 --- /dev/null +++ b/libs/migrate/sql/room_user_state/room_user_state_up_01.sql @@ -0,0 +1,14 @@ +create table if not exists room_user_state +( + room uuid not null, + "user" uuid not null, + last_read_seq bigint, + do_not_disturb boolean default false not null, + dnd_start_hour smallint, + dnd_end_hour smallint, + joined_at timestamp with time zone, + primary key (room, "user") +); + +create index if not exists idx_room_user_state_user + on room_user_state ("user"); diff --git a/libs/migrate/sql/user/user_down_01.sql b/libs/migrate/sql/user/user_down_01.sql new file mode 100644 index 0000000..8203674 --- /dev/null +++ b/libs/migrate/sql/user/user_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_username; +DROP TABLE IF EXISTS "user"; diff --git a/libs/migrate/sql/user/user_up_01.sql b/libs/migrate/sql/user/user_up_01.sql new file mode 100644 index 0000000..54d7dbc --- /dev/null +++ b/libs/migrate/sql/user/user_up_01.sql @@ -0,0 +1,16 @@ +create table if not exists "user" +( + uid uuid not null + primary key, + username varchar(255) not null, + display_name varchar(255), + avatar_url varchar(255), + website_url varchar(255), + organization varchar(255), + last_sign_in_at timestamp with time zone, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_user_username + on "user" (username); diff --git a/libs/migrate/sql/user_2fa/user_2fa_down_01.sql b/libs/migrate/sql/user_2fa/user_2fa_down_01.sql new file mode 100644 index 0000000..b4dfa08 --- /dev/null +++ b/libs/migrate/sql/user_2fa/user_2fa_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS user_2fa; diff --git a/libs/migrate/sql/user_2fa/user_2fa_up_01.sql b/libs/migrate/sql/user_2fa/user_2fa_up_01.sql new file mode 100644 index 0000000..8602612 --- /dev/null +++ b/libs/migrate/sql/user_2fa/user_2fa_up_01.sql @@ -0,0 +1,11 @@ +create table if not exists user_2fa +( + "user" uuid not null + primary key, + method varchar(255) not null, + secret varchar(255), + backup_codes jsonb not null, + is_enabled boolean default false not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/user_activity_log/user_activity_log_down_01.sql b/libs/migrate/sql/user_activity_log/user_activity_log_down_01.sql new file mode 100644 index 0000000..40671c7 --- /dev/null +++ b/libs/migrate/sql/user_activity_log/user_activity_log_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_user_activity_log_created_at; +DROP INDEX IF EXISTS idx_user_activity_log_user_uid; +DROP TABLE IF EXISTS user_activity_log; diff --git a/libs/migrate/sql/user_activity_log/user_activity_log_up_01.sql b/libs/migrate/sql/user_activity_log/user_activity_log_up_01.sql new file mode 100644 index 0000000..11779e5 --- /dev/null +++ b/libs/migrate/sql/user_activity_log/user_activity_log_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists user_activity_log +( + id bigserial + primary key, + user_uid uuid, + action varchar(255) not null, + ip_address varchar(255), + user_agent varchar(255), + details jsonb not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_activity_log_user_uid + on user_activity_log (user_uid); + +create index if not exists idx_user_activity_log_created_at + on user_activity_log (created_at); diff --git a/libs/migrate/sql/user_billing_history/user_billing_history_down_01.sql b/libs/migrate/sql/user_billing_history/user_billing_history_down_01.sql new file mode 100644 index 0000000..b4c6f19 --- /dev/null +++ b/libs/migrate/sql/user_billing_history/user_billing_history_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_user_billing_history_created_at; +DROP INDEX IF EXISTS idx_user_billing_history_user; +DROP TABLE IF EXISTS user_billing_history; diff --git a/libs/migrate/sql/user_billing_history/user_billing_history_up_01.sql b/libs/migrate/sql/user_billing_history/user_billing_history_up_01.sql new file mode 100644 index 0000000..9b2cf7c --- /dev/null +++ b/libs/migrate/sql/user_billing_history/user_billing_history_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists user_billing_history +( + uid uuid not null + primary key, + user_uuid uuid not null, + amount numeric not null, + currency text not null, + reason text not null, + extra jsonb, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_billing_history_user + on user_billing_history (user_uuid); + +create index if not exists idx_user_billing_history_created_at + on user_billing_history (created_at); diff --git a/libs/migrate/sql/user_email/user_email_down_01.sql b/libs/migrate/sql/user_email/user_email_down_01.sql new file mode 100644 index 0000000..4a88fba --- /dev/null +++ b/libs/migrate/sql/user_email/user_email_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_email_email; +DROP TABLE IF EXISTS user_email; diff --git a/libs/migrate/sql/user_email/user_email_up_01.sql b/libs/migrate/sql/user_email/user_email_up_01.sql new file mode 100644 index 0000000..d8c4d0f --- /dev/null +++ b/libs/migrate/sql/user_email/user_email_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists user_email +( + "user" uuid not null + primary key, + email varchar(255) not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_email_email + on user_email (email); diff --git a/libs/migrate/sql/user_email_change/user_email_change_down_01.sql b/libs/migrate/sql/user_email_change/user_email_change_down_01.sql new file mode 100644 index 0000000..82f07db --- /dev/null +++ b/libs/migrate/sql/user_email_change/user_email_change_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_email_change_user_uid; +DROP TABLE IF EXISTS user_email_change; diff --git a/libs/migrate/sql/user_email_change/user_email_change_up_01.sql b/libs/migrate/sql/user_email_change/user_email_change_up_01.sql new file mode 100644 index 0000000..86541fd --- /dev/null +++ b/libs/migrate/sql/user_email_change/user_email_change_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists user_email_change +( + token varchar(255) not null + primary key, + user_uid uuid not null, + new_email varchar(255) not null, + expires_at timestamp with time zone not null, + used boolean default false not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_email_change_user_uid + on user_email_change (user_uid); diff --git a/libs/migrate/sql/user_notification/user_notification_down_01.sql b/libs/migrate/sql/user_notification/user_notification_down_01.sql new file mode 100644 index 0000000..da983f1 --- /dev/null +++ b/libs/migrate/sql/user_notification/user_notification_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS user_notification; diff --git a/libs/migrate/sql/user_notification/user_notification_up_01.sql b/libs/migrate/sql/user_notification/user_notification_up_01.sql new file mode 100644 index 0000000..177880f --- /dev/null +++ b/libs/migrate/sql/user_notification/user_notification_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists user_notification +( + "user" uuid not null + primary key, + email_enabled boolean default false not null, + in_app_enabled boolean default true not null, + push_enabled boolean default false not null, + digest_mode varchar(255) not null, + dnd_enabled boolean default false not null, + dnd_start_minute integer, + dnd_end_minute integer, + marketing_enabled boolean default true not null, + security_enabled boolean default true not null, + product_enabled boolean default true not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null, + push_subscription_endpoint text, + push_subscription_keys_p256dh text, + push_subscription_keys_auth text +); diff --git a/libs/migrate/sql/user_password/user_password_down_01.sql b/libs/migrate/sql/user_password/user_password_down_01.sql new file mode 100644 index 0000000..6a3da9c --- /dev/null +++ b/libs/migrate/sql/user_password/user_password_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS user_password; diff --git a/libs/migrate/sql/user_password/user_password_up_01.sql b/libs/migrate/sql/user_password/user_password_up_01.sql new file mode 100644 index 0000000..93268c3 --- /dev/null +++ b/libs/migrate/sql/user_password/user_password_up_01.sql @@ -0,0 +1,10 @@ +create table if not exists user_password +( + "user" uuid not null + primary key, + password_hash varchar(255) not null, + password_salt varchar(255), + is_active boolean default true not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/user_password_reset/user_password_reset_down_01.sql b/libs/migrate/sql/user_password_reset/user_password_reset_down_01.sql new file mode 100644 index 0000000..a805236 --- /dev/null +++ b/libs/migrate/sql/user_password_reset/user_password_reset_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_password_reset_user_uid; +DROP TABLE IF EXISTS user_password_reset; diff --git a/libs/migrate/sql/user_password_reset/user_password_reset_up_01.sql b/libs/migrate/sql/user_password_reset/user_password_reset_up_01.sql new file mode 100644 index 0000000..a6a5bf7 --- /dev/null +++ b/libs/migrate/sql/user_password_reset/user_password_reset_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists user_password_reset +( + token varchar(255) not null + primary key, + user_uid uuid not null, + expires_at timestamp with time zone not null, + used boolean default false not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_password_reset_user_uid + on user_password_reset (user_uid); diff --git a/libs/migrate/sql/user_preferences/user_preferences_down_01.sql b/libs/migrate/sql/user_preferences/user_preferences_down_01.sql new file mode 100644 index 0000000..f3b2897 --- /dev/null +++ b/libs/migrate/sql/user_preferences/user_preferences_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS user_preferences; diff --git a/libs/migrate/sql/user_preferences/user_preferences_up_01.sql b/libs/migrate/sql/user_preferences/user_preferences_up_01.sql new file mode 100644 index 0000000..8e3b09e --- /dev/null +++ b/libs/migrate/sql/user_preferences/user_preferences_up_01.sql @@ -0,0 +1,12 @@ +create table if not exists user_preferences +( + "user" uuid not null + primary key, + language varchar(255) not null, + theme varchar(255) not null, + timezone varchar(255) not null, + email_notifications boolean default true not null, + in_app_notifications boolean default true not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/user_relation/user_relation_down_01.sql b/libs/migrate/sql/user_relation/user_relation_down_01.sql new file mode 100644 index 0000000..ca8fadd --- /dev/null +++ b/libs/migrate/sql/user_relation/user_relation_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_user_relation_target; +DROP INDEX IF EXISTS idx_user_relation_user; +DROP TABLE IF EXISTS user_relation; diff --git a/libs/migrate/sql/user_relation/user_relation_up_01.sql b/libs/migrate/sql/user_relation/user_relation_up_01.sql new file mode 100644 index 0000000..eec9250 --- /dev/null +++ b/libs/migrate/sql/user_relation/user_relation_up_01.sql @@ -0,0 +1,15 @@ +create table if not exists user_relation +( + id bigserial + primary key, + "user" uuid not null, + target uuid not null, + relation_type varchar(255) not null, + created_at timestamp with time zone not null +); + +create index if not exists idx_user_relation_user + on user_relation ("user"); + +create index if not exists idx_user_relation_target + on user_relation (target); diff --git a/libs/migrate/sql/user_ssh_key/user_ssh_key_down_01.sql b/libs/migrate/sql/user_ssh_key/user_ssh_key_down_01.sql new file mode 100644 index 0000000..751b198 --- /dev/null +++ b/libs/migrate/sql/user_ssh_key/user_ssh_key_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_ssh_key_user; +DROP TABLE IF EXISTS user_ssh_key; diff --git a/libs/migrate/sql/user_ssh_key/user_ssh_key_up_01.sql b/libs/migrate/sql/user_ssh_key/user_ssh_key_up_01.sql new file mode 100644 index 0000000..3921b5d --- /dev/null +++ b/libs/migrate/sql/user_ssh_key/user_ssh_key_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists user_ssh_key +( + id bigserial + primary key, + "user" uuid not null, + title varchar(255) not null, + public_key text not null, + fingerprint varchar(255) not null, + key_type varchar(255) not null, + key_bits integer, + is_verified boolean default false not null, + last_used_at timestamp with time zone, + expires_at timestamp with time zone, + is_revoked boolean default false not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_user_ssh_key_user + on user_ssh_key ("user"); diff --git a/libs/migrate/sql/user_token/user_token_down_01.sql b/libs/migrate/sql/user_token/user_token_down_01.sql new file mode 100644 index 0000000..fca281b --- /dev/null +++ b/libs/migrate/sql/user_token/user_token_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_user_token_user; +DROP TABLE IF EXISTS user_token; diff --git a/libs/migrate/sql/user_token/user_token_up_01.sql b/libs/migrate/sql/user_token/user_token_up_01.sql new file mode 100644 index 0000000..c34401d --- /dev/null +++ b/libs/migrate/sql/user_token/user_token_up_01.sql @@ -0,0 +1,16 @@ +create table if not exists user_token +( + id bigserial + primary key, + "user" uuid not null, + name varchar(255) not null, + token_hash varchar(255) not null, + scopes jsonb not null, + expires_at timestamp with time zone, + is_revoked boolean default false not null, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); + +create index if not exists idx_user_token_user + on user_token ("user"); diff --git a/libs/migrate/sql/workspace/workspace_down_01.sql b/libs/migrate/sql/workspace/workspace_down_01.sql new file mode 100644 index 0000000..d6d10b0 --- /dev/null +++ b/libs/migrate/sql/workspace/workspace_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS workspace; diff --git a/libs/migrate/sql/workspace/workspace_up_01.sql b/libs/migrate/sql/workspace/workspace_up_01.sql new file mode 100644 index 0000000..65da288 --- /dev/null +++ b/libs/migrate/sql/workspace/workspace_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists workspace +( + id uuid not null + primary key, + slug varchar(255) not null, + name varchar(255) not null, + description text, + avatar_url varchar(255), + plan varchar(50) default 'free'::character varying not null, + billing_email varchar(255), + stripe_customer_id varchar(255), + stripe_subscription_id varchar(255), + plan_expires_at timestamp with time zone, + deleted_at timestamp with time zone, + created_at timestamp with time zone not null, + updated_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/workspace_alert_config/workspace_alert_config_down_01.sql b/libs/migrate/sql/workspace_alert_config/workspace_alert_config_down_01.sql new file mode 100644 index 0000000..abb0486 --- /dev/null +++ b/libs/migrate/sql/workspace_alert_config/workspace_alert_config_down_01.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS idx_alert_config_workspace; +DROP TABLE IF EXISTS workspace_alert_config; diff --git a/libs/migrate/sql/workspace_alert_config/workspace_alert_config_up_01.sql b/libs/migrate/sql/workspace_alert_config/workspace_alert_config_up_01.sql new file mode 100644 index 0000000..b7fc50f --- /dev/null +++ b/libs/migrate/sql/workspace_alert_config/workspace_alert_config_up_01.sql @@ -0,0 +1,17 @@ +create table if not exists workspace_alert_config +( + id serial + primary key, + workspace_id uuid not null, + alert_type varchar(32) not null, + threshold numeric(10, 4) not null, + email_enabled boolean default true, + enabled boolean default true, + created_by integer, + created_at timestamp with time zone default now(), + updated_at timestamp with time zone default now(), + unique (workspace_id, alert_type) +); + +create index if not exists idx_alert_config_workspace + on workspace_alert_config (workspace_id); diff --git a/libs/migrate/sql/workspace_billing/workspace_billing_down_01.sql b/libs/migrate/sql/workspace_billing/workspace_billing_down_01.sql new file mode 100644 index 0000000..9ad0e1f --- /dev/null +++ b/libs/migrate/sql/workspace_billing/workspace_billing_down_01.sql @@ -0,0 +1 @@ +DROP TABLE IF EXISTS workspace_billing; diff --git a/libs/migrate/sql/workspace_billing/workspace_billing_up_01.sql b/libs/migrate/sql/workspace_billing/workspace_billing_up_01.sql new file mode 100644 index 0000000..48af1ad --- /dev/null +++ b/libs/migrate/sql/workspace_billing/workspace_billing_up_01.sql @@ -0,0 +1,13 @@ +create table if not exists workspace_billing +( + workspace_id uuid not null + primary key + references workspace + on delete cascade, + balance numeric(20, 4) default 0 not null, + currency varchar(10) default 'USD'::character varying not null, + monthly_quota numeric(20, 4) default 0 not null, + total_spent numeric(20, 4) default 0 not null, + updated_at timestamp with time zone not null, + created_at timestamp with time zone not null +); diff --git a/libs/migrate/sql/workspace_billing_history/workspace_billing_history_down_01.sql b/libs/migrate/sql/workspace_billing_history/workspace_billing_history_down_01.sql new file mode 100644 index 0000000..cb708e6 --- /dev/null +++ b/libs/migrate/sql/workspace_billing_history/workspace_billing_history_down_01.sql @@ -0,0 +1,3 @@ +DROP INDEX IF EXISTS idx_wsbh_created_at; +DROP INDEX IF EXISTS idx_wsbh_workspace_id; +DROP TABLE IF EXISTS workspace_billing_history; diff --git a/libs/migrate/sql/workspace_billing_history/workspace_billing_history_up_01.sql b/libs/migrate/sql/workspace_billing_history/workspace_billing_history_up_01.sql new file mode 100644 index 0000000..7830b32 --- /dev/null +++ b/libs/migrate/sql/workspace_billing_history/workspace_billing_history_up_01.sql @@ -0,0 +1,20 @@ +create table if not exists workspace_billing_history +( + uid uuid not null + primary key, + workspace_id uuid not null + references workspace + on delete cascade, + user_id uuid, + amount numeric(20, 4) not null, + currency varchar(10) default 'USD'::character varying not null, + reason varchar(100) not null, + extra jsonb, + created_at timestamp with time zone not null +); + +create index if not exists idx_wsbh_workspace_id + on workspace_billing_history (workspace_id); + +create index if not exists idx_wsbh_created_at + on workspace_billing_history (created_at desc); diff --git a/libs/migrate/sql/workspace_membership/workspace_membership_down_01.sql b/libs/migrate/sql/workspace_membership/workspace_membership_down_01.sql new file mode 100644 index 0000000..d611f8f --- /dev/null +++ b/libs/migrate/sql/workspace_membership/workspace_membership_down_01.sql @@ -0,0 +1,4 @@ +DROP INDEX IF EXISTS idx_workspace_membership_invite_token; +DROP INDEX IF EXISTS idx_workspace_membership_user; +DROP INDEX IF EXISTS idx_workspace_membership_ws_user; +DROP TABLE IF EXISTS workspace_membership; diff --git a/libs/migrate/sql/workspace_membership/workspace_membership_up_01.sql b/libs/migrate/sql/workspace_membership/workspace_membership_up_01.sql new file mode 100644 index 0000000..44c4ded --- /dev/null +++ b/libs/migrate/sql/workspace_membership/workspace_membership_up_01.sql @@ -0,0 +1,24 @@ +create table if not exists workspace_membership +( + id bigserial + primary key, + workspace_id uuid not null, + user_id uuid not null, + role varchar(50) default 'member'::character varying not null, + status varchar(50) default 'active'::character varying not null, + invited_by uuid, + joined_at timestamp with time zone not null, + invite_token varchar(255), + invite_expires_at timestamp with time zone, + unique (workspace_id, user_id) +); + +create unique index if not exists idx_workspace_membership_ws_user + on workspace_membership (workspace_id, user_id); + +create index if not exists idx_workspace_membership_user + on workspace_membership (user_id); + +create index if not exists idx_workspace_membership_invite_token + on workspace_membership (invite_token) + where (invite_token IS NOT NULL); diff --git a/libs/migrate/user_billing_history.rs b/libs/migrate/user_billing_history.rs deleted file mode 100644 index fe90567..0000000 --- a/libs/migrate/user_billing_history.rs +++ /dev/null @@ -1,56 +0,0 @@ -use sea_orm_migration::prelude::*; - -pub struct Migration; - -impl MigrationName for Migration { - fn name(&self) -> &str { - "user_billing_history" - } -} - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" -create table if not exists user_billing_history -( - uid uuid not null - primary key, - user_uuid uuid not null, - amount numeric not null, - currency text not null, - reason text not null, - extra jsonb, - created_at timestamp with time zone not null -); - -create index if not exists idx_user_billing_history_user - on user_billing_history (user_uuid); - -create index if not exists idx_user_billing_history_created_at - on user_billing_history (created_at); -"#, - ) - .await?; - - Ok(()) - } - - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .get_connection() - .execute_unprepared( - r#" -drop index if exists idx_user_billing_history_created_at; -drop index if exists idx_user_billing_history_user; -drop table if exists user_billing_history; -"#, - ) - .await?; - - Ok(()) - } -}