From e63f83ff884df41b16c2da807ff30a9655f47c94 Mon Sep 17 00:00:00 2001 From: Selase Krakani Date: Thu, 22 May 2025 01:15:49 +0000 Subject: [PATCH 1/3] DEV: Add intermediate DB tables from converter V1 --- migrations/config/intermediate_db.yml | 286 +++++++++-- .../100-base-schema.sql | 483 ++++++++++++++++++ .../lib/database/intermediate_db/badge.rb | 87 ++++ .../lib/database/intermediate_db/category.rb | 163 ++++++ .../intermediate_db/category_custom_field.rb | 24 + .../database/intermediate_db/category_user.rb | 31 ++ .../database/intermediate_db/chat_channel.rb | 84 +++ .../database/intermediate_db/chat_mention.rb | 33 ++ .../database/intermediate_db/chat_message.rb | 69 +++ .../intermediate_db/chat_message_reaction.rb | 31 ++ .../database/intermediate_db/chat_thread.rb | 54 ++ .../lib/database/intermediate_db/group.rb | 96 ++++ .../database/intermediate_db/group_user.rb | 45 ++ .../database/intermediate_db/muted_user.rb | 29 ++ .../lib/database/intermediate_db/permalink.rb | 48 ++ .../lib/database/intermediate_db/poll.rb | 72 +++ .../database/intermediate_db/poll_option.rb | 31 ++ .../lib/database/intermediate_db/poll_vote.rb | 33 ++ .../lib/database/intermediate_db/post.rb | 105 ++++ .../intermediate_db/post_custom_field.rb | 24 + .../lib/database/intermediate_db/tag.rb | 42 ++ .../lib/database/intermediate_db/tag_group.rb | 33 ++ .../lib/database/intermediate_db/tag_user.rb | 33 ++ .../lib/database/intermediate_db/topic.rb | 111 ++++ .../lib/database/intermediate_db/topic_tag.rb | 31 ++ .../database/intermediate_db/topic_user.rb | 69 +++ .../user_associated_account.rb | 45 ++ .../database/intermediate_db/user_badge.rb | 48 ++ .../user_chat_channel_membership.rb | 60 +++ .../user_chat_thread_membership.rb | 45 ++ .../intermediate_db/user_custom_field.rb | 33 ++ .../database/intermediate_db/user_field.rb | 72 +++ .../lib/database/schema/table_writer.rb | 1 + 33 files changed, 2420 insertions(+), 31 deletions(-) create mode 100644 migrations/lib/database/intermediate_db/badge.rb create mode 100644 migrations/lib/database/intermediate_db/category.rb create mode 100644 migrations/lib/database/intermediate_db/category_custom_field.rb create mode 100644 migrations/lib/database/intermediate_db/category_user.rb create mode 100644 migrations/lib/database/intermediate_db/chat_channel.rb create mode 100644 migrations/lib/database/intermediate_db/chat_mention.rb create mode 100644 migrations/lib/database/intermediate_db/chat_message.rb create mode 100644 migrations/lib/database/intermediate_db/chat_message_reaction.rb create mode 100644 migrations/lib/database/intermediate_db/chat_thread.rb create mode 100644 migrations/lib/database/intermediate_db/group.rb create mode 100644 migrations/lib/database/intermediate_db/group_user.rb create mode 100644 migrations/lib/database/intermediate_db/muted_user.rb create mode 100644 migrations/lib/database/intermediate_db/permalink.rb create mode 100644 migrations/lib/database/intermediate_db/poll.rb create mode 100644 migrations/lib/database/intermediate_db/poll_option.rb create mode 100644 migrations/lib/database/intermediate_db/poll_vote.rb create mode 100644 migrations/lib/database/intermediate_db/post.rb create mode 100644 migrations/lib/database/intermediate_db/post_custom_field.rb create mode 100644 migrations/lib/database/intermediate_db/tag.rb create mode 100644 migrations/lib/database/intermediate_db/tag_group.rb create mode 100644 migrations/lib/database/intermediate_db/tag_user.rb create mode 100644 migrations/lib/database/intermediate_db/topic.rb create mode 100644 migrations/lib/database/intermediate_db/topic_tag.rb create mode 100644 migrations/lib/database/intermediate_db/topic_user.rb create mode 100644 migrations/lib/database/intermediate_db/user_associated_account.rb create mode 100644 migrations/lib/database/intermediate_db/user_badge.rb create mode 100644 migrations/lib/database/intermediate_db/user_chat_channel_membership.rb create mode 100644 migrations/lib/database/intermediate_db/user_chat_thread_membership.rb create mode 100644 migrations/lib/database/intermediate_db/user_custom_field.rb create mode 100644 migrations/lib/database/intermediate_db/user_field.rb diff --git a/migrations/config/intermediate_db.yml b/migrations/config/intermediate_db.yml index b3300526e1ef9..21edbf6d66158 100644 --- a/migrations/config/intermediate_db.yml +++ b/migrations/config/intermediate_db.yml @@ -7,14 +7,267 @@ output: schema: tables: + badges: + columns: + add: + - name: "existing_id" + datatype: "text" + exclude: + - "grant_count" + categories: + columns: + add: + - name: "about_topic_title" + datatype: text + - name: "existing_id" + datatype: text + exclude: + - "contains_messages" + - "latest_post_id" + - "latest_topic_id" + - "name_lower" + - "post_count" + - "posts_day" + - "posts_month" + - "posts_week" + - "posts_year" + - "topic_count" + - "topics_day" + - "topics_month" + - "topics_week" + - "topics_year" + category_custom_fields: + primary_key_column_names: [ "category_id", "name" ] + columns: + exclude: + - "created_at" + - "id" + category_users: + columns: + exclude: + - "id" + chat_channels: + columns: + add: + - name: "is_group" + datatype: boolean + exclude: + - "last_message_id" + - "user_count_stale" + chat_mentions: {} + chat_message_reactions: + primary_key_column_names: [ "chat_message_id", "user_id", "emoji" ] + columns: + exclude: + - "id" + chat_messages: + columns: + add: + - name: "original_message" + datatype: text + exclude: + - "cooked_version" + - "cooked" + chat_threads: + primary_key_column_names: [original_id, channel_id, original_message_id, original_message_user_id ] + group_users: + primary_key_column_names: [ "group_id", "user_id" ] + groups: + columns: + include: + - "allow_membership_requests" + - "allow_unknown_sender_topic_replies" + - "automatic" + - "automatic_membership_email_domains" + - "bio_raw" + - "created_at" + - "default_notification_level" + - "flair_bg_color" + - "flair_color" + - "flair_icon" + - "flair_upload_id" + - "full_name" + - "grant_trust_level" + - "id" + - "members_visibility_level" + - "membership_request_template" + - "mentionable_level" + - "messageable_level" + - "name" + - "primary_group" + - "public_admission" + - "public_exit" + - "title" + - "visibility_level" + muted_users: + columns: + exclude: + - "id" + primary_key_column_names: [ "user_id", "muted_user_id" ] + permalinks: + primary_key_column_names: [ "url" ] + columns: + add: + - name: "external_url_placeholders" + datatype: json + exclude: + - "created_at" + - "id" + poll_options: + columns: + exclude: + - "digest" + - "html" + poll_votes: + primary_key_column_names: [ "poll_option_id", "user_id" ] + polls: {} + post_custom_fields: + primary_key_column_names: [ "post_id", "name" ] + columns: + exclude: + - "created_at" + - "id" + posts: + columns: + add: + - name: "original_raw" + datatype: text + - name: "reply_to_post_id" + datatype: numeric + exclude: + - "action_code" + - "baked_at" + - "baked_version" + - "bookmark_count" + - "cook_method" + - "cooked" + - "edit_reason" + - "illegal_count" + - "incoming_link_count" + - "inappropriate_count" + - "like_score" + - "notify_moderators_count" + - "notify_user_count" + - "off_topic_count" + - "outbound_message_id" + - "percent_rank" + - "public_version" + - "raw_email" + - "reply_quoted" + - "reply_to_post_number" + - "score" + - "self_edits" + - "sort_order" + - "version" + - "via_email" + - "word_count" + indexes: + - name: "posts_by_topic_post_number" + columns: + - "topic_id" + - "post_number" + tag_groups: {} + tag_users: + primary_key_column_names: [ "tag_id", "user_id" ] + tags: + columns: + add: + - name: "tag_group_id" + datatype: numeric + exclude: + - "pm_topic_count" + - "public_topic_count" + - "staff_topic_count" + topic_tags: + primary_key_column_names: [ "topic_id", "tag_id" ] + topic_users: + primary_key_column_names: ["user_id", "topic_id" ] + columns: + exclude: + - "id" + topics: + columns: + exclude: + - "external_id" + - "fancy_title" + - "highest_post_number" + - "highest_staff_post_number" + - "last_post_user_id" + - "last_posted_at" + - "like_count" + - "moderator_posts_count" + - "notify_moderators_count" + - "participant_count" + - "percent_rank" + - "posts_count" + - "reply_count" + - "reviewable_score" + - "score" + - "slow_mode_seconds" + - "spam_count" + - "visibility_reason_id" + - "word_count" + user_associated_accounts: + primary_key_column_names: [ "user_id", "provider_name" ] + columns: + exclude: + - "id" + - "created_at" + user_badges: + columns: + exclude: + - "id" + - "notification_id" + - "seq" + user_chat_channel_memberships: + primary_key_column_names: [ "user_id", "chat_channel_id" ] + columns: + exclude: + - "id" + user_chat_thread_memberships: + primary_key_column_names: [ "user_id", "thread_id" ] + columns: + exclude: + - "id" + user_custom_fields: + columns: + add: + - name: "field_id" + datatype: numeric + nullable: false + - name: "is_multiselect_field" + datatype: boolean + nullable: false + exclude: + - "id" + - "created_at" + indexes: + - name: "user_field_values_multiselect" + columns: + - "user_id" + - "field_id" + - "value" + unique: true + condition: "WHERE is_multiselect_field = TRUE" + - name: "user_field_values_not_multiselect" + columns: + - "user_id" + - "field_id" + unique: true + condition: "WHERE is_multiselect_field = FALSE" user_emails: columns: include: + - "created_at" - "email" - "primary" - "user_id" - - "created_at" primary_key_column_names: [ "email" ] + user_fields: + columns: + add: + - name: "options" + datatype: json user_options: primary_key_column_names: [ "user_id" ] users: @@ -35,6 +288,7 @@ schema: - "suspended_till" - "username_lower" + global: columns: modify: @@ -63,11 +317,8 @@ schema: - "backup_metadata" - "badge_groupings" - "badge_types" - - "badges" - "bookmarks" - - "categories" - "categories_web_hooks" - - "category_custom_fields" - "category_featured_topics" - "category_form_templates" - "category_groups" @@ -79,20 +330,14 @@ schema: - "category_tag_groups" - "category_tag_stats" - "category_tags" - - "category_users" - "chat_channel_archives" - "chat_channel_custom_fields" - - "chat_channels" - "chat_drafts" - "chat_mention_notifications" - - "chat_mentions" - "chat_message_custom_fields" - "chat_message_interactions" - - "chat_message_reactions" - "chat_message_revisions" - - "chat_messages" - "chat_thread_custom_fields" - - "chat_threads" - "chat_webhook_events" - "child_themes" - "color_scheme_colors" @@ -130,8 +375,6 @@ schema: - "group_mentions" - "group_requests" - "group_tag_notification_defaults" - - "group_users" - - "groups" - "groups_web_hooks" - "ignored_users" - "imap_sync_logs" @@ -147,19 +390,13 @@ schema: - "linked_topics" - "message_bus" - "moved_posts" - - "muted_users" - "notifications" - "oauth2_user_infos" - "onceoff_logs" - "optimized_images" - - "permalinks" - "plugin_store_rows" - - "poll_options" - - "poll_votes" - - "polls" - "post_action_types" - "post_actions" - - "post_custom_fields" - "post_details" - "post_hotlinked_media" - "post_localizations" @@ -169,7 +406,6 @@ schema: - "post_search_data" - "post_stats" - "post_timings" - - "posts" - "problem_check_trackers" - "published_pages" - "push_subscriptions" @@ -200,10 +436,7 @@ schema: - "summary_sections" - "tag_group_memberships" - "tag_group_permissions" - - "tag_groups" - "tag_search_data" - - "tag_users" - - "tags" - "tags_web_hooks" - "theme_color_schemes" - "theme_fields" @@ -225,13 +458,10 @@ schema: - "topic_links" - "topic_localizations" - "topic_search_data" - - "topic_tags" - "topic_thumbnails" - "topic_timers" - - "topic_users" - "topic_view_stats" - "topic_views" - - "topics" - "translation_overrides" - "unsubscribe_keys" - "upload_references" @@ -242,18 +472,12 @@ schema: - "user_api_key_scopes" - "user_api_keys" - "user_archived_messages" - - "user_associated_accounts" - "user_associated_groups" - "user_auth_token_logs" - "user_auth_tokens" - "user_avatars" - - "user_badges" - - "user_chat_channel_memberships" - - "user_chat_thread_memberships" - - "user_custom_fields" - "user_exports" - "user_field_options" - - "user_fields" - "user_histories" - "user_ip_address_histories" - "user_notification_schedules" diff --git a/migrations/db/intermediate_db_schema/100-base-schema.sql b/migrations/db/intermediate_db_schema/100-base-schema.sql index 01af108251a01..892f311bdb0a8 100644 --- a/migrations/db/intermediate_db_schema/100-base-schema.sql +++ b/migrations/db/intermediate_db_schema/100-base-schema.sql @@ -2,6 +2,469 @@ -- update the "config/intermediate_db.yml" configuration file and then run -- `bin/cli schema generate` to regenerate this file. +CREATE TABLE badges +( + original_id NUMERIC NOT NULL PRIMARY KEY, + allow_title BOOLEAN, + auto_revoke BOOLEAN, + badge_grouping_id NUMERIC, + badge_type_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + description TEXT, + enabled BOOLEAN, + existing_id TEXT, + icon TEXT, + image_upload_id TEXT, + listable BOOLEAN, + long_description TEXT, + multiple_grant BOOLEAN, + name TEXT NOT NULL, + "query" TEXT, + show_in_post_header BOOLEAN, + show_posts BOOLEAN, + system BOOLEAN, + target_posts BOOLEAN, + "trigger" INTEGER +); + +CREATE TABLE categories +( + original_id NUMERIC NOT NULL PRIMARY KEY, + about_topic_title TEXT, + all_topics_wiki BOOLEAN, + allow_badges BOOLEAN, + allow_global_tags BOOLEAN, + allow_unlimited_owner_edits_on_first_post BOOLEAN, + auto_close_based_on_last_post BOOLEAN, + auto_close_hours FLOAT, + color TEXT, + created_at DATETIME NOT NULL, + default_list_filter TEXT, + default_slow_mode_seconds INTEGER, + default_top_period TEXT, + default_view TEXT, + description TEXT, + email_in TEXT, + email_in_allow_strangers BOOLEAN, + emoji TEXT, + existing_id TEXT, + icon TEXT, + mailinglist_mirror BOOLEAN, + minimum_required_tags INTEGER, + name TEXT NOT NULL, + navigate_to_first_post_after_read BOOLEAN, + num_featured_topics INTEGER, + parent_category_id NUMERIC, + position INTEGER, + read_only_banner TEXT, + read_restricted BOOLEAN, + reviewable_by_group_id NUMERIC, + search_priority INTEGER, + show_subcategory_list BOOLEAN, + slug TEXT NOT NULL, + sort_ascending BOOLEAN, + sort_order TEXT, + style_type INTEGER, + subcategory_list_style TEXT, + text_color TEXT, + topic_featured_link_allowed BOOLEAN, + topic_id NUMERIC, + topic_template TEXT, + uploaded_background_dark_id TEXT, + uploaded_background_id TEXT, + uploaded_logo_dark_id TEXT, + uploaded_logo_id TEXT, + user_id NUMERIC NOT NULL +); + +CREATE TABLE category_custom_fields +( + category_id NUMERIC NOT NULL, + name TEXT NOT NULL, + value TEXT, + PRIMARY KEY (category_id, name) +); + +CREATE TABLE category_users +( + category_id NUMERIC NOT NULL, + last_seen_at DATETIME, + notification_level INTEGER NOT NULL, + user_id NUMERIC NOT NULL +); + +CREATE TABLE chat_channels +( + original_id NUMERIC NOT NULL PRIMARY KEY, + allow_channel_wide_mentions BOOLEAN, + auto_join_users BOOLEAN, + chatable_id NUMERIC NOT NULL, + chatable_type TEXT NOT NULL, + created_at DATETIME NOT NULL, + delete_after_seconds INTEGER, + deleted_at DATETIME, + deleted_by_id NUMERIC, + description TEXT, + featured_in_category_id NUMERIC, + icon_upload_id TEXT, + is_group BOOLEAN, + messages_count INTEGER, + name TEXT, + slug TEXT, + status INTEGER, + threading_enabled BOOLEAN, + type TEXT, + user_count INTEGER +); + +CREATE TABLE chat_mentions +( + original_id NUMERIC NOT NULL PRIMARY KEY, + chat_message_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + target_id NUMERIC, + type TEXT NOT NULL +); + +CREATE TABLE chat_message_reactions +( + chat_message_id NUMERIC, + emoji TEXT, + user_id NUMERIC, + created_at DATETIME NOT NULL, + PRIMARY KEY (chat_message_id, user_id, emoji) +); + +CREATE TABLE chat_messages +( + original_id NUMERIC NOT NULL PRIMARY KEY, + blocks JSON_TEXT, + chat_channel_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + created_by_sdk BOOLEAN, + deleted_at DATETIME, + deleted_by_id NUMERIC, + excerpt TEXT, + in_reply_to_id NUMERIC, + last_editor_id NUMERIC NOT NULL, + message TEXT, + original_message TEXT, + streaming BOOLEAN, + thread_id NUMERIC, + user_id NUMERIC +); + +CREATE TABLE chat_threads +( + channel_id NUMERIC NOT NULL, + original_message_id NUMERIC NOT NULL, + original_message_user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + force BOOLEAN, + last_message_id NUMERIC, + original_id NUMERIC NOT NULL, + replies_count INTEGER, + status INTEGER, + title TEXT, + PRIMARY KEY (original_id, channel_id, original_message_id, original_message_user_id) +); + +CREATE TABLE group_users +( + group_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + first_unread_pm_at DATETIME NOT NULL, + notification_level INTEGER, + original_id NUMERIC NOT NULL, + owner BOOLEAN, + PRIMARY KEY (group_id, user_id) +); + +CREATE TABLE "groups" +( + original_id NUMERIC NOT NULL PRIMARY KEY, + allow_membership_requests BOOLEAN, + allow_unknown_sender_topic_replies BOOLEAN, + automatic BOOLEAN, + automatic_membership_email_domains TEXT, + bio_raw TEXT, + created_at DATETIME NOT NULL, + default_notification_level INTEGER, + flair_bg_color TEXT, + flair_color TEXT, + flair_icon TEXT, + flair_upload_id TEXT, + full_name TEXT, + grant_trust_level INTEGER, + members_visibility_level INTEGER, + membership_request_template TEXT, + mentionable_level INTEGER, + messageable_level INTEGER, + name TEXT NOT NULL, + primary_group BOOLEAN, + public_admission BOOLEAN, + public_exit BOOLEAN, + title TEXT, + visibility_level INTEGER +); + +CREATE TABLE muted_users +( + muted_user_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + PRIMARY KEY (user_id, muted_user_id) +); + +CREATE TABLE permalinks +( + url TEXT NOT NULL PRIMARY KEY, + category_id NUMERIC, + external_url TEXT, + external_url_placeholders JSON_TEXT, + post_id NUMERIC, + tag_id NUMERIC, + topic_id NUMERIC, + user_id NUMERIC +); + +CREATE TABLE poll_options +( + original_id NUMERIC NOT NULL PRIMARY KEY, + anonymous_votes INTEGER, + created_at DATETIME NOT NULL, + poll_id NUMERIC +); + +CREATE TABLE poll_votes +( + poll_option_id NUMERIC, + user_id NUMERIC, + created_at DATETIME NOT NULL, + poll_id NUMERIC, + rank INTEGER, + PRIMARY KEY (poll_option_id, user_id) +); + +CREATE TABLE polls +( + original_id NUMERIC NOT NULL PRIMARY KEY, + anonymous_voters INTEGER, + chart_type INTEGER, + close_at DATETIME, + created_at DATETIME NOT NULL, + "groups" TEXT, + max INTEGER, + min INTEGER, + name TEXT, + post_id NUMERIC, + results INTEGER, + status INTEGER, + step INTEGER, + title TEXT, + type INTEGER, + visibility INTEGER +); + +CREATE TABLE post_custom_fields +( + name TEXT NOT NULL, + post_id NUMERIC NOT NULL, + value TEXT, + PRIMARY KEY (post_id, name) +); + +CREATE TABLE posts +( + original_id NUMERIC NOT NULL PRIMARY KEY, + created_at DATETIME NOT NULL, + deleted_at DATETIME, + deleted_by_id NUMERIC, + hidden BOOLEAN, + hidden_at DATETIME, + hidden_reason_id NUMERIC, + image_upload_id TEXT, + last_editor_id NUMERIC, + last_version_at DATETIME NOT NULL, + like_count INTEGER, + locale TEXT, + locked_by_id NUMERIC, + original_raw TEXT, + post_number INTEGER NOT NULL, + post_type INTEGER, + quote_count INTEGER, + raw TEXT NOT NULL, + reads INTEGER, + reply_count INTEGER, + reply_to_post_id NUMERIC, + reply_to_user_id NUMERIC, + spam_count INTEGER, + topic_id NUMERIC NOT NULL, + user_deleted BOOLEAN, + user_id NUMERIC, + wiki BOOLEAN +); + +CREATE INDEX posts_by_topic_post_number ON posts (topic_id, post_number); + +CREATE TABLE tag_groups +( + original_id NUMERIC NOT NULL PRIMARY KEY, + created_at DATETIME NOT NULL, + name TEXT NOT NULL, + one_per_topic BOOLEAN, + parent_tag_id NUMERIC +); + +CREATE TABLE tag_users +( + tag_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + notification_level INTEGER NOT NULL, + original_id NUMERIC NOT NULL, + PRIMARY KEY (tag_id, user_id) +); + +CREATE TABLE tags +( + original_id NUMERIC NOT NULL PRIMARY KEY, + created_at DATETIME NOT NULL, + description TEXT, + name TEXT NOT NULL, + tag_group_id NUMERIC, + target_tag_id NUMERIC +); + +CREATE TABLE topic_tags +( + tag_id NUMERIC NOT NULL, + topic_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + original_id NUMERIC NOT NULL, + PRIMARY KEY (topic_id, tag_id) +); + +CREATE TABLE topic_users +( + topic_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + bookmarked BOOLEAN, + cleared_pinned_at DATETIME, + first_visited_at DATETIME, + last_emailed_post_number INTEGER, + last_posted_at DATETIME, + last_read_post_number INTEGER, + last_visited_at DATETIME, + liked BOOLEAN, + notification_level INTEGER, + notifications_changed_at DATETIME, + notifications_reason_id NUMERIC, + posted BOOLEAN, + total_msecs_viewed INTEGER, + PRIMARY KEY (user_id, topic_id) +); + +CREATE TABLE topics +( + original_id NUMERIC NOT NULL PRIMARY KEY, + archetype TEXT, + archived BOOLEAN, + bannered_until DATETIME, + bumped_at DATETIME NOT NULL, + category_id NUMERIC, + closed BOOLEAN, + created_at DATETIME NOT NULL, + deleted_at DATETIME, + deleted_by_id NUMERIC, + excerpt TEXT, + featured_link TEXT, + featured_user1_id NUMERIC, + featured_user2_id NUMERIC, + featured_user3_id NUMERIC, + featured_user4_id NUMERIC, + has_summary BOOLEAN, + image_upload_id TEXT, + incoming_link_count INTEGER, + locale TEXT, + pinned_at DATETIME, + pinned_globally BOOLEAN, + pinned_until DATETIME, + slug TEXT, + subtype TEXT, + title TEXT NOT NULL, + user_id NUMERIC, + views INTEGER, + visible BOOLEAN +); + +CREATE TABLE user_associated_accounts +( + provider_name TEXT NOT NULL, + user_id NUMERIC, + credentials JSON_TEXT, + extra JSON_TEXT, + info JSON_TEXT, + last_used DATETIME NOT NULL, + provider_uid TEXT NOT NULL, + PRIMARY KEY (user_id, provider_name) +); + +CREATE TABLE user_badges +( + badge_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + featured_rank INTEGER, + granted_at DATETIME NOT NULL, + granted_by_id NUMERIC NOT NULL, + is_favorite BOOLEAN, + post_id NUMERIC, + user_id NUMERIC NOT NULL +); + +CREATE TABLE user_chat_channel_memberships +( + chat_channel_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + desktop_notification_level INTEGER, + "following" BOOLEAN, + join_mode INTEGER, + last_read_message_id NUMERIC, + last_unread_mention_when_emailed_id NUMERIC, + last_viewed_at DATETIME NOT NULL, + mobile_notification_level INTEGER, + muted BOOLEAN, + notification_level INTEGER, + PRIMARY KEY (user_id, chat_channel_id) +); + +CREATE TABLE user_chat_thread_memberships +( + thread_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, + created_at DATETIME NOT NULL, + last_read_message_id NUMERIC, + last_unread_message_when_emailed_id NUMERIC, + notification_level INTEGER, + thread_title_prompt_seen BOOLEAN, + PRIMARY KEY (user_id, thread_id) +); + +CREATE TABLE user_custom_fields +( + field_id NUMERIC NOT NULL, + is_multiselect_field BOOLEAN NOT NULL, + name TEXT NOT NULL, + user_id NUMERIC NOT NULL, + value TEXT +); + +CREATE UNIQUE INDEX user_field_values_multiselect ON user_custom_fields (user_id, field_id, value) WHERE is_multiselect_field = TRUE; + +CREATE UNIQUE INDEX user_field_values_not_multiselect ON user_custom_fields (user_id, field_id) WHERE is_multiselect_field = FALSE; + CREATE TABLE user_emails ( email TEXT NOT NULL PRIMARY KEY, @@ -10,6 +473,26 @@ CREATE TABLE user_emails user_id NUMERIC NOT NULL ); +CREATE TABLE user_fields +( + original_id NUMERIC NOT NULL PRIMARY KEY, + created_at DATETIME NOT NULL, + description TEXT NOT NULL, + editable BOOLEAN, + external_name TEXT, + external_type TEXT, + field_type TEXT, + field_type_enum INTEGER NOT NULL, + name TEXT NOT NULL, + options JSON_TEXT, + position INTEGER, + required BOOLEAN, + requirement INTEGER, + searchable BOOLEAN, + show_on_profile BOOLEAN, + show_on_user_card BOOLEAN +); + CREATE TABLE user_options ( user_id NUMERIC NOT NULL PRIMARY KEY, diff --git a/migrations/lib/database/intermediate_db/badge.rb b/migrations/lib/database/intermediate_db/badge.rb new file mode 100644 index 0000000000000..c70669889f224 --- /dev/null +++ b/migrations/lib/database/intermediate_db/badge.rb @@ -0,0 +1,87 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Badge + SQL = <<~SQL + INSERT INTO badges ( + original_id, + allow_title, + auto_revoke, + badge_grouping_id, + badge_type_id, + created_at, + description, + enabled, + existing_id, + icon, + image_upload_id, + listable, + long_description, + multiple_grant, + name, + "query", + show_in_post_header, + show_posts, + system, + target_posts, + "trigger" + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + allow_title: nil, + auto_revoke: nil, + badge_grouping_id: nil, + badge_type_id:, + created_at:, + description: nil, + enabled: nil, + existing_id: nil, + icon: nil, + image_upload_id: nil, + listable: nil, + long_description: nil, + multiple_grant: nil, + name:, + query: nil, + show_in_post_header: nil, + show_posts: nil, + system: nil, + target_posts: nil, + trigger: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_boolean(allow_title), + ::Migrations::Database.format_boolean(auto_revoke), + badge_grouping_id, + badge_type_id, + ::Migrations::Database.format_datetime(created_at), + description, + ::Migrations::Database.format_boolean(enabled), + existing_id, + icon, + image_upload_id, + ::Migrations::Database.format_boolean(listable), + long_description, + ::Migrations::Database.format_boolean(multiple_grant), + name, + query, + ::Migrations::Database.format_boolean(show_in_post_header), + ::Migrations::Database.format_boolean(show_posts), + ::Migrations::Database.format_boolean(system), + ::Migrations::Database.format_boolean(target_posts), + trigger, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/category.rb b/migrations/lib/database/intermediate_db/category.rb new file mode 100644 index 0000000000000..149962fdb3956 --- /dev/null +++ b/migrations/lib/database/intermediate_db/category.rb @@ -0,0 +1,163 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Category + SQL = <<~SQL + INSERT INTO categories ( + original_id, + about_topic_title, + all_topics_wiki, + allow_badges, + allow_global_tags, + allow_unlimited_owner_edits_on_first_post, + auto_close_based_on_last_post, + auto_close_hours, + color, + created_at, + default_list_filter, + default_slow_mode_seconds, + default_top_period, + default_view, + description, + email_in, + email_in_allow_strangers, + emoji, + existing_id, + icon, + mailinglist_mirror, + minimum_required_tags, + name, + navigate_to_first_post_after_read, + num_featured_topics, + parent_category_id, + position, + read_only_banner, + read_restricted, + reviewable_by_group_id, + search_priority, + show_subcategory_list, + slug, + sort_ascending, + sort_order, + style_type, + subcategory_list_style, + text_color, + topic_featured_link_allowed, + topic_id, + topic_template, + uploaded_background_dark_id, + uploaded_background_id, + uploaded_logo_dark_id, + uploaded_logo_id, + user_id + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + about_topic_title: nil, + all_topics_wiki: nil, + allow_badges: nil, + allow_global_tags: nil, + allow_unlimited_owner_edits_on_first_post: nil, + auto_close_based_on_last_post: nil, + auto_close_hours: nil, + color: nil, + created_at:, + default_list_filter: nil, + default_slow_mode_seconds: nil, + default_top_period: nil, + default_view: nil, + description: nil, + email_in: nil, + email_in_allow_strangers: nil, + emoji: nil, + existing_id: nil, + icon: nil, + mailinglist_mirror: nil, + minimum_required_tags: nil, + name:, + navigate_to_first_post_after_read: nil, + num_featured_topics: nil, + parent_category_id: nil, + position: nil, + read_only_banner: nil, + read_restricted: nil, + reviewable_by_group_id: nil, + search_priority: nil, + show_subcategory_list: nil, + slug:, + sort_ascending: nil, + sort_order: nil, + style_type: nil, + subcategory_list_style: nil, + text_color: nil, + topic_featured_link_allowed: nil, + topic_id: nil, + topic_template: nil, + uploaded_background_dark_id: nil, + uploaded_background_id: nil, + uploaded_logo_dark_id: nil, + uploaded_logo_id: nil, + user_id: + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + about_topic_title, + ::Migrations::Database.format_boolean(all_topics_wiki), + ::Migrations::Database.format_boolean(allow_badges), + ::Migrations::Database.format_boolean(allow_global_tags), + ::Migrations::Database.format_boolean(allow_unlimited_owner_edits_on_first_post), + ::Migrations::Database.format_boolean(auto_close_based_on_last_post), + auto_close_hours, + color, + ::Migrations::Database.format_datetime(created_at), + default_list_filter, + default_slow_mode_seconds, + default_top_period, + default_view, + description, + email_in, + ::Migrations::Database.format_boolean(email_in_allow_strangers), + emoji, + existing_id, + icon, + ::Migrations::Database.format_boolean(mailinglist_mirror), + minimum_required_tags, + name, + ::Migrations::Database.format_boolean(navigate_to_first_post_after_read), + num_featured_topics, + parent_category_id, + position, + read_only_banner, + ::Migrations::Database.format_boolean(read_restricted), + reviewable_by_group_id, + search_priority, + ::Migrations::Database.format_boolean(show_subcategory_list), + slug, + ::Migrations::Database.format_boolean(sort_ascending), + sort_order, + style_type, + subcategory_list_style, + text_color, + ::Migrations::Database.format_boolean(topic_featured_link_allowed), + topic_id, + topic_template, + uploaded_background_dark_id, + uploaded_background_id, + uploaded_logo_dark_id, + uploaded_logo_id, + user_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/category_custom_field.rb b/migrations/lib/database/intermediate_db/category_custom_field.rb new file mode 100644 index 0000000000000..c7d6a4bb58e9d --- /dev/null +++ b/migrations/lib/database/intermediate_db/category_custom_field.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module CategoryCustomField + SQL = <<~SQL + INSERT INTO category_custom_fields ( + category_id, + name, + value + ) + VALUES ( + ?, ?, ? + ) + SQL + + def self.create(category_id:, name:, value: nil) + ::Migrations::Database::IntermediateDB.insert(SQL, category_id, name, value) + end + end +end diff --git a/migrations/lib/database/intermediate_db/category_user.rb b/migrations/lib/database/intermediate_db/category_user.rb new file mode 100644 index 0000000000000..44b250e285cef --- /dev/null +++ b/migrations/lib/database/intermediate_db/category_user.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module CategoryUser + SQL = <<~SQL + INSERT INTO category_users ( + category_id, + last_seen_at, + notification_level, + user_id + ) + VALUES ( + ?, ?, ?, ? + ) + SQL + + def self.create(category_id:, last_seen_at: nil, notification_level:, user_id:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + category_id, + ::Migrations::Database.format_datetime(last_seen_at), + notification_level, + user_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/chat_channel.rb b/migrations/lib/database/intermediate_db/chat_channel.rb new file mode 100644 index 0000000000000..0b70058bd3431 --- /dev/null +++ b/migrations/lib/database/intermediate_db/chat_channel.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module ChatChannel + SQL = <<~SQL + INSERT INTO chat_channels ( + original_id, + allow_channel_wide_mentions, + auto_join_users, + chatable_id, + chatable_type, + created_at, + delete_after_seconds, + deleted_at, + deleted_by_id, + description, + featured_in_category_id, + icon_upload_id, + is_group, + messages_count, + name, + slug, + status, + threading_enabled, + type, + user_count + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + allow_channel_wide_mentions: nil, + auto_join_users: nil, + chatable_id:, + chatable_type:, + created_at:, + delete_after_seconds: nil, + deleted_at: nil, + deleted_by_id: nil, + description: nil, + featured_in_category_id: nil, + icon_upload_id: nil, + is_group: nil, + messages_count: nil, + name: nil, + slug: nil, + status: nil, + threading_enabled: nil, + type: nil, + user_count: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_boolean(allow_channel_wide_mentions), + ::Migrations::Database.format_boolean(auto_join_users), + chatable_id, + chatable_type, + ::Migrations::Database.format_datetime(created_at), + delete_after_seconds, + ::Migrations::Database.format_datetime(deleted_at), + deleted_by_id, + description, + featured_in_category_id, + icon_upload_id, + ::Migrations::Database.format_boolean(is_group), + messages_count, + name, + slug, + status, + ::Migrations::Database.format_boolean(threading_enabled), + type, + user_count, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/chat_mention.rb b/migrations/lib/database/intermediate_db/chat_mention.rb new file mode 100644 index 0000000000000..45c1e657d7099 --- /dev/null +++ b/migrations/lib/database/intermediate_db/chat_mention.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module ChatMention + SQL = <<~SQL + INSERT INTO chat_mentions ( + original_id, + chat_message_id, + created_at, + target_id, + type + ) + VALUES ( + ?, ?, ?, ?, ? + ) + SQL + + def self.create(original_id:, chat_message_id:, created_at:, target_id: nil, type:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + chat_message_id, + ::Migrations::Database.format_datetime(created_at), + target_id, + type, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/chat_message.rb b/migrations/lib/database/intermediate_db/chat_message.rb new file mode 100644 index 0000000000000..0d0e62d65a0f8 --- /dev/null +++ b/migrations/lib/database/intermediate_db/chat_message.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module ChatMessage + SQL = <<~SQL + INSERT INTO chat_messages ( + original_id, + blocks, + chat_channel_id, + created_at, + created_by_sdk, + deleted_at, + deleted_by_id, + excerpt, + in_reply_to_id, + last_editor_id, + message, + original_message, + streaming, + thread_id, + user_id + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + blocks: nil, + chat_channel_id:, + created_at:, + created_by_sdk: nil, + deleted_at: nil, + deleted_by_id: nil, + excerpt: nil, + in_reply_to_id: nil, + last_editor_id:, + message: nil, + original_message: nil, + streaming: nil, + thread_id: nil, + user_id: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.to_json(blocks), + chat_channel_id, + ::Migrations::Database.format_datetime(created_at), + ::Migrations::Database.format_boolean(created_by_sdk), + ::Migrations::Database.format_datetime(deleted_at), + deleted_by_id, + excerpt, + in_reply_to_id, + last_editor_id, + message, + original_message, + ::Migrations::Database.format_boolean(streaming), + thread_id, + user_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/chat_message_reaction.rb b/migrations/lib/database/intermediate_db/chat_message_reaction.rb new file mode 100644 index 0000000000000..4f59ca2c74e54 --- /dev/null +++ b/migrations/lib/database/intermediate_db/chat_message_reaction.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module ChatMessageReaction + SQL = <<~SQL + INSERT INTO chat_message_reactions ( + chat_message_id, + emoji, + user_id, + created_at + ) + VALUES ( + ?, ?, ?, ? + ) + SQL + + def self.create(chat_message_id:, emoji:, user_id:, created_at:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + chat_message_id, + emoji, + user_id, + ::Migrations::Database.format_datetime(created_at), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/chat_thread.rb b/migrations/lib/database/intermediate_db/chat_thread.rb new file mode 100644 index 0000000000000..9aaeeb994a206 --- /dev/null +++ b/migrations/lib/database/intermediate_db/chat_thread.rb @@ -0,0 +1,54 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module ChatThread + SQL = <<~SQL + INSERT INTO chat_threads ( + channel_id, + original_message_id, + original_message_user_id, + created_at, + force, + last_message_id, + original_id, + replies_count, + status, + title + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + channel_id:, + original_message_id:, + original_message_user_id:, + created_at:, + force: nil, + last_message_id: nil, + original_id:, + replies_count: nil, + status: nil, + title: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + channel_id, + original_message_id, + original_message_user_id, + ::Migrations::Database.format_datetime(created_at), + ::Migrations::Database.format_boolean(force), + last_message_id, + original_id, + replies_count, + status, + title, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/group.rb b/migrations/lib/database/intermediate_db/group.rb new file mode 100644 index 0000000000000..dccc0339ace7f --- /dev/null +++ b/migrations/lib/database/intermediate_db/group.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Group + SQL = <<~SQL + INSERT INTO "groups" ( + original_id, + allow_membership_requests, + allow_unknown_sender_topic_replies, + automatic, + automatic_membership_email_domains, + bio_raw, + created_at, + default_notification_level, + flair_bg_color, + flair_color, + flair_icon, + flair_upload_id, + full_name, + grant_trust_level, + members_visibility_level, + membership_request_template, + mentionable_level, + messageable_level, + name, + primary_group, + public_admission, + public_exit, + title, + visibility_level + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + allow_membership_requests: nil, + allow_unknown_sender_topic_replies: nil, + automatic: nil, + automatic_membership_email_domains: nil, + bio_raw: nil, + created_at:, + default_notification_level: nil, + flair_bg_color: nil, + flair_color: nil, + flair_icon: nil, + flair_upload_id: nil, + full_name: nil, + grant_trust_level: nil, + members_visibility_level: nil, + membership_request_template: nil, + mentionable_level: nil, + messageable_level: nil, + name:, + primary_group: nil, + public_admission: nil, + public_exit: nil, + title: nil, + visibility_level: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_boolean(allow_membership_requests), + ::Migrations::Database.format_boolean(allow_unknown_sender_topic_replies), + ::Migrations::Database.format_boolean(automatic), + automatic_membership_email_domains, + bio_raw, + ::Migrations::Database.format_datetime(created_at), + default_notification_level, + flair_bg_color, + flair_color, + flair_icon, + flair_upload_id, + full_name, + grant_trust_level, + members_visibility_level, + membership_request_template, + mentionable_level, + messageable_level, + name, + ::Migrations::Database.format_boolean(primary_group), + ::Migrations::Database.format_boolean(public_admission), + ::Migrations::Database.format_boolean(public_exit), + title, + visibility_level, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/group_user.rb b/migrations/lib/database/intermediate_db/group_user.rb new file mode 100644 index 0000000000000..934921a4ef304 --- /dev/null +++ b/migrations/lib/database/intermediate_db/group_user.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module GroupUser + SQL = <<~SQL + INSERT INTO group_users ( + group_id, + user_id, + created_at, + first_unread_pm_at, + notification_level, + original_id, + owner + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + group_id:, + user_id:, + created_at:, + first_unread_pm_at:, + notification_level: nil, + original_id:, + owner: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + group_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + ::Migrations::Database.format_datetime(first_unread_pm_at), + notification_level, + original_id, + ::Migrations::Database.format_boolean(owner), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/muted_user.rb b/migrations/lib/database/intermediate_db/muted_user.rb new file mode 100644 index 0000000000000..340e1bdce4491 --- /dev/null +++ b/migrations/lib/database/intermediate_db/muted_user.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module MutedUser + SQL = <<~SQL + INSERT INTO muted_users ( + muted_user_id, + user_id, + created_at + ) + VALUES ( + ?, ?, ? + ) + SQL + + def self.create(muted_user_id:, user_id:, created_at:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + muted_user_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/permalink.rb b/migrations/lib/database/intermediate_db/permalink.rb new file mode 100644 index 0000000000000..daa24510b8c66 --- /dev/null +++ b/migrations/lib/database/intermediate_db/permalink.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Permalink + SQL = <<~SQL + INSERT INTO permalinks ( + url, + category_id, + external_url, + external_url_placeholders, + post_id, + tag_id, + topic_id, + user_id + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + url:, + category_id: nil, + external_url: nil, + external_url_placeholders: nil, + post_id: nil, + tag_id: nil, + topic_id: nil, + user_id: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + url, + category_id, + external_url, + ::Migrations::Database.to_json(external_url_placeholders), + post_id, + tag_id, + topic_id, + user_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/poll.rb b/migrations/lib/database/intermediate_db/poll.rb new file mode 100644 index 0000000000000..5aebc59fec4aa --- /dev/null +++ b/migrations/lib/database/intermediate_db/poll.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Poll + SQL = <<~SQL + INSERT INTO polls ( + original_id, + anonymous_voters, + chart_type, + close_at, + created_at, + "groups", + max, + min, + name, + post_id, + results, + status, + step, + title, + type, + visibility + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + anonymous_voters: nil, + chart_type: nil, + close_at: nil, + created_at:, + groups: nil, + max: nil, + min: nil, + name: nil, + post_id: nil, + results: nil, + status: nil, + step: nil, + title: nil, + type: nil, + visibility: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + anonymous_voters, + chart_type, + ::Migrations::Database.format_datetime(close_at), + ::Migrations::Database.format_datetime(created_at), + groups, + max, + min, + name, + post_id, + results, + status, + step, + title, + type, + visibility, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/poll_option.rb b/migrations/lib/database/intermediate_db/poll_option.rb new file mode 100644 index 0000000000000..69fb47a3f351a --- /dev/null +++ b/migrations/lib/database/intermediate_db/poll_option.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module PollOption + SQL = <<~SQL + INSERT INTO poll_options ( + original_id, + anonymous_votes, + created_at, + poll_id + ) + VALUES ( + ?, ?, ?, ? + ) + SQL + + def self.create(original_id:, anonymous_votes: nil, created_at:, poll_id: nil) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + anonymous_votes, + ::Migrations::Database.format_datetime(created_at), + poll_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/poll_vote.rb b/migrations/lib/database/intermediate_db/poll_vote.rb new file mode 100644 index 0000000000000..2039ea922e540 --- /dev/null +++ b/migrations/lib/database/intermediate_db/poll_vote.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module PollVote + SQL = <<~SQL + INSERT INTO poll_votes ( + poll_option_id, + user_id, + created_at, + poll_id, + rank + ) + VALUES ( + ?, ?, ?, ?, ? + ) + SQL + + def self.create(poll_option_id:, user_id:, created_at:, poll_id: nil, rank: nil) + ::Migrations::Database::IntermediateDB.insert( + SQL, + poll_option_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + poll_id, + rank, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/post.rb b/migrations/lib/database/intermediate_db/post.rb new file mode 100644 index 0000000000000..1f98316b7745a --- /dev/null +++ b/migrations/lib/database/intermediate_db/post.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Post + SQL = <<~SQL + INSERT INTO posts ( + original_id, + created_at, + deleted_at, + deleted_by_id, + hidden, + hidden_at, + hidden_reason_id, + image_upload_id, + last_editor_id, + last_version_at, + like_count, + locale, + locked_by_id, + original_raw, + post_number, + post_type, + quote_count, + raw, + reads, + reply_count, + reply_to_post_id, + reply_to_user_id, + spam_count, + topic_id, + user_deleted, + user_id, + wiki + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + created_at:, + deleted_at: nil, + deleted_by_id: nil, + hidden: nil, + hidden_at: nil, + hidden_reason_id: nil, + image_upload_id: nil, + last_editor_id: nil, + last_version_at:, + like_count: nil, + locale: nil, + locked_by_id: nil, + original_raw: nil, + post_number:, + post_type: nil, + quote_count: nil, + raw:, + reads: nil, + reply_count: nil, + reply_to_post_id: nil, + reply_to_user_id: nil, + spam_count: nil, + topic_id:, + user_deleted: nil, + user_id: nil, + wiki: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_datetime(created_at), + ::Migrations::Database.format_datetime(deleted_at), + deleted_by_id, + ::Migrations::Database.format_boolean(hidden), + ::Migrations::Database.format_datetime(hidden_at), + hidden_reason_id, + image_upload_id, + last_editor_id, + ::Migrations::Database.format_datetime(last_version_at), + like_count, + locale, + locked_by_id, + original_raw, + post_number, + post_type, + quote_count, + raw, + reads, + reply_count, + reply_to_post_id, + reply_to_user_id, + spam_count, + topic_id, + ::Migrations::Database.format_boolean(user_deleted), + user_id, + ::Migrations::Database.format_boolean(wiki), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/post_custom_field.rb b/migrations/lib/database/intermediate_db/post_custom_field.rb new file mode 100644 index 0000000000000..3c8842f9b8355 --- /dev/null +++ b/migrations/lib/database/intermediate_db/post_custom_field.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module PostCustomField + SQL = <<~SQL + INSERT INTO post_custom_fields ( + name, + post_id, + value + ) + VALUES ( + ?, ?, ? + ) + SQL + + def self.create(name:, post_id:, value: nil) + ::Migrations::Database::IntermediateDB.insert(SQL, name, post_id, value) + end + end +end diff --git a/migrations/lib/database/intermediate_db/tag.rb b/migrations/lib/database/intermediate_db/tag.rb new file mode 100644 index 0000000000000..e0f58edb1fb6e --- /dev/null +++ b/migrations/lib/database/intermediate_db/tag.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Tag + SQL = <<~SQL + INSERT INTO tags ( + original_id, + created_at, + description, + name, + tag_group_id, + target_tag_id + ) + VALUES ( + ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + created_at:, + description: nil, + name:, + tag_group_id: nil, + target_tag_id: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_datetime(created_at), + description, + name, + tag_group_id, + target_tag_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/tag_group.rb b/migrations/lib/database/intermediate_db/tag_group.rb new file mode 100644 index 0000000000000..36445f6450530 --- /dev/null +++ b/migrations/lib/database/intermediate_db/tag_group.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module TagGroup + SQL = <<~SQL + INSERT INTO tag_groups ( + original_id, + created_at, + name, + one_per_topic, + parent_tag_id + ) + VALUES ( + ?, ?, ?, ?, ? + ) + SQL + + def self.create(original_id:, created_at:, name:, one_per_topic: nil, parent_tag_id: nil) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_datetime(created_at), + name, + ::Migrations::Database.format_boolean(one_per_topic), + parent_tag_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/tag_user.rb b/migrations/lib/database/intermediate_db/tag_user.rb new file mode 100644 index 0000000000000..8c1feb2ae75e2 --- /dev/null +++ b/migrations/lib/database/intermediate_db/tag_user.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module TagUser + SQL = <<~SQL + INSERT INTO tag_users ( + tag_id, + user_id, + created_at, + notification_level, + original_id + ) + VALUES ( + ?, ?, ?, ?, ? + ) + SQL + + def self.create(tag_id:, user_id:, created_at:, notification_level:, original_id:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + tag_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + notification_level, + original_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/topic.rb b/migrations/lib/database/intermediate_db/topic.rb new file mode 100644 index 0000000000000..450cfcc7d8c18 --- /dev/null +++ b/migrations/lib/database/intermediate_db/topic.rb @@ -0,0 +1,111 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module Topic + SQL = <<~SQL + INSERT INTO topics ( + original_id, + archetype, + archived, + bannered_until, + bumped_at, + category_id, + closed, + created_at, + deleted_at, + deleted_by_id, + excerpt, + featured_link, + featured_user1_id, + featured_user2_id, + featured_user3_id, + featured_user4_id, + has_summary, + image_upload_id, + incoming_link_count, + locale, + pinned_at, + pinned_globally, + pinned_until, + slug, + subtype, + title, + user_id, + views, + visible + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + archetype: nil, + archived: nil, + bannered_until: nil, + bumped_at:, + category_id: nil, + closed: nil, + created_at:, + deleted_at: nil, + deleted_by_id: nil, + excerpt: nil, + featured_link: nil, + featured_user1_id: nil, + featured_user2_id: nil, + featured_user3_id: nil, + featured_user4_id: nil, + has_summary: nil, + image_upload_id: nil, + incoming_link_count: nil, + locale: nil, + pinned_at: nil, + pinned_globally: nil, + pinned_until: nil, + slug: nil, + subtype: nil, + title:, + user_id: nil, + views: nil, + visible: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + archetype, + ::Migrations::Database.format_boolean(archived), + ::Migrations::Database.format_datetime(bannered_until), + ::Migrations::Database.format_datetime(bumped_at), + category_id, + ::Migrations::Database.format_boolean(closed), + ::Migrations::Database.format_datetime(created_at), + ::Migrations::Database.format_datetime(deleted_at), + deleted_by_id, + excerpt, + featured_link, + featured_user1_id, + featured_user2_id, + featured_user3_id, + featured_user4_id, + ::Migrations::Database.format_boolean(has_summary), + image_upload_id, + incoming_link_count, + locale, + ::Migrations::Database.format_datetime(pinned_at), + ::Migrations::Database.format_boolean(pinned_globally), + ::Migrations::Database.format_datetime(pinned_until), + slug, + subtype, + title, + user_id, + views, + ::Migrations::Database.format_boolean(visible), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/topic_tag.rb b/migrations/lib/database/intermediate_db/topic_tag.rb new file mode 100644 index 0000000000000..864dde361d0d8 --- /dev/null +++ b/migrations/lib/database/intermediate_db/topic_tag.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module TopicTag + SQL = <<~SQL + INSERT INTO topic_tags ( + tag_id, + topic_id, + created_at, + original_id + ) + VALUES ( + ?, ?, ?, ? + ) + SQL + + def self.create(tag_id:, topic_id:, created_at:, original_id:) + ::Migrations::Database::IntermediateDB.insert( + SQL, + tag_id, + topic_id, + ::Migrations::Database.format_datetime(created_at), + original_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/topic_user.rb b/migrations/lib/database/intermediate_db/topic_user.rb new file mode 100644 index 0000000000000..2e6281f627c09 --- /dev/null +++ b/migrations/lib/database/intermediate_db/topic_user.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module TopicUser + SQL = <<~SQL + INSERT INTO topic_users ( + topic_id, + user_id, + bookmarked, + cleared_pinned_at, + first_visited_at, + last_emailed_post_number, + last_posted_at, + last_read_post_number, + last_visited_at, + liked, + notification_level, + notifications_changed_at, + notifications_reason_id, + posted, + total_msecs_viewed + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + topic_id:, + user_id:, + bookmarked: nil, + cleared_pinned_at: nil, + first_visited_at: nil, + last_emailed_post_number: nil, + last_posted_at: nil, + last_read_post_number: nil, + last_visited_at: nil, + liked: nil, + notification_level: nil, + notifications_changed_at: nil, + notifications_reason_id: nil, + posted: nil, + total_msecs_viewed: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + topic_id, + user_id, + ::Migrations::Database.format_boolean(bookmarked), + ::Migrations::Database.format_datetime(cleared_pinned_at), + ::Migrations::Database.format_datetime(first_visited_at), + last_emailed_post_number, + ::Migrations::Database.format_datetime(last_posted_at), + last_read_post_number, + ::Migrations::Database.format_datetime(last_visited_at), + ::Migrations::Database.format_boolean(liked), + notification_level, + ::Migrations::Database.format_datetime(notifications_changed_at), + notifications_reason_id, + ::Migrations::Database.format_boolean(posted), + total_msecs_viewed, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_associated_account.rb b/migrations/lib/database/intermediate_db/user_associated_account.rb new file mode 100644 index 0000000000000..a271a3b3fa47a --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_associated_account.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserAssociatedAccount + SQL = <<~SQL + INSERT INTO user_associated_accounts ( + provider_name, + user_id, + credentials, + extra, + info, + last_used, + provider_uid + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + provider_name:, + user_id:, + credentials: nil, + extra: nil, + info: nil, + last_used:, + provider_uid: + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + provider_name, + user_id, + ::Migrations::Database.to_json(credentials), + ::Migrations::Database.to_json(extra), + ::Migrations::Database.to_json(info), + ::Migrations::Database.format_datetime(last_used), + provider_uid, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_badge.rb b/migrations/lib/database/intermediate_db/user_badge.rb new file mode 100644 index 0000000000000..17732e801a095 --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_badge.rb @@ -0,0 +1,48 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserBadge + SQL = <<~SQL + INSERT INTO user_badges ( + badge_id, + created_at, + featured_rank, + granted_at, + granted_by_id, + is_favorite, + post_id, + user_id + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + badge_id:, + created_at:, + featured_rank: nil, + granted_at:, + granted_by_id:, + is_favorite: nil, + post_id: nil, + user_id: + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + badge_id, + ::Migrations::Database.format_datetime(created_at), + featured_rank, + ::Migrations::Database.format_datetime(granted_at), + granted_by_id, + ::Migrations::Database.format_boolean(is_favorite), + post_id, + user_id, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_chat_channel_membership.rb b/migrations/lib/database/intermediate_db/user_chat_channel_membership.rb new file mode 100644 index 0000000000000..e356488251d07 --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_chat_channel_membership.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserChatChannelMembership + SQL = <<~SQL + INSERT INTO user_chat_channel_memberships ( + chat_channel_id, + user_id, + created_at, + desktop_notification_level, + "following", + join_mode, + last_read_message_id, + last_unread_mention_when_emailed_id, + last_viewed_at, + mobile_notification_level, + muted, + notification_level + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + chat_channel_id:, + user_id:, + created_at:, + desktop_notification_level: nil, + following: nil, + join_mode: nil, + last_read_message_id: nil, + last_unread_mention_when_emailed_id: nil, + last_viewed_at:, + mobile_notification_level: nil, + muted: nil, + notification_level: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + chat_channel_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + desktop_notification_level, + ::Migrations::Database.format_boolean(following), + join_mode, + last_read_message_id, + last_unread_mention_when_emailed_id, + ::Migrations::Database.format_datetime(last_viewed_at), + mobile_notification_level, + ::Migrations::Database.format_boolean(muted), + notification_level, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_chat_thread_membership.rb b/migrations/lib/database/intermediate_db/user_chat_thread_membership.rb new file mode 100644 index 0000000000000..ab2b4fbf4b1be --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_chat_thread_membership.rb @@ -0,0 +1,45 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserChatThreadMembership + SQL = <<~SQL + INSERT INTO user_chat_thread_memberships ( + thread_id, + user_id, + created_at, + last_read_message_id, + last_unread_message_when_emailed_id, + notification_level, + thread_title_prompt_seen + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + thread_id:, + user_id:, + created_at:, + last_read_message_id: nil, + last_unread_message_when_emailed_id: nil, + notification_level: nil, + thread_title_prompt_seen: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + thread_id, + user_id, + ::Migrations::Database.format_datetime(created_at), + last_read_message_id, + last_unread_message_when_emailed_id, + notification_level, + ::Migrations::Database.format_boolean(thread_title_prompt_seen), + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_custom_field.rb b/migrations/lib/database/intermediate_db/user_custom_field.rb new file mode 100644 index 0000000000000..fde5eb9f604cb --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_custom_field.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserCustomField + SQL = <<~SQL + INSERT INTO user_custom_fields ( + field_id, + is_multiselect_field, + name, + user_id, + value + ) + VALUES ( + ?, ?, ?, ?, ? + ) + SQL + + def self.create(field_id:, is_multiselect_field:, name:, user_id:, value: nil) + ::Migrations::Database::IntermediateDB.insert( + SQL, + field_id, + ::Migrations::Database.format_boolean(is_multiselect_field), + name, + user_id, + value, + ) + end + end +end diff --git a/migrations/lib/database/intermediate_db/user_field.rb b/migrations/lib/database/intermediate_db/user_field.rb new file mode 100644 index 0000000000000..0b24aef864dc2 --- /dev/null +++ b/migrations/lib/database/intermediate_db/user_field.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +# This file is auto-generated from the IntermediateDB schema. To make changes, +# update the "config/intermediate_db.yml" configuration file and then run +# `bin/cli schema generate` to regenerate this file. + +module Migrations::Database::IntermediateDB + module UserField + SQL = <<~SQL + INSERT INTO user_fields ( + original_id, + created_at, + description, + editable, + external_name, + external_type, + field_type, + field_type_enum, + name, + options, + position, + required, + requirement, + searchable, + show_on_profile, + show_on_user_card + ) + VALUES ( + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ) + SQL + + def self.create( + original_id:, + created_at:, + description:, + editable: nil, + external_name: nil, + external_type: nil, + field_type: nil, + field_type_enum:, + name:, + options: nil, + position: nil, + required: nil, + requirement: nil, + searchable: nil, + show_on_profile: nil, + show_on_user_card: nil + ) + ::Migrations::Database::IntermediateDB.insert( + SQL, + original_id, + ::Migrations::Database.format_datetime(created_at), + description, + ::Migrations::Database.format_boolean(editable), + external_name, + external_type, + field_type, + field_type_enum, + name, + ::Migrations::Database.to_json(options), + position, + ::Migrations::Database.format_boolean(required), + requirement, + ::Migrations::Database.format_boolean(searchable), + ::Migrations::Database.format_boolean(show_on_profile), + ::Migrations::Database.format_boolean(show_on_user_card), + ) + end + end +end diff --git a/migrations/lib/database/schema/table_writer.rb b/migrations/lib/database/schema/table_writer.rb index 7e8e9ff7c2437..af9ccf83aa78f 100644 --- a/migrations/lib/database/schema/table_writer.rb +++ b/migrations/lib/database/schema/table_writer.rb @@ -28,6 +28,7 @@ def output_create_table_statement(table) def output_columns(table) column_definitions = create_column_definitions(table) + column_definitions << "" if table.primary_key_column_names.size > 1 @output.puts column_definitions.join(",\n") end From 681c53f70c4e9818031efbef6e0347223fba01b2 Mon Sep 17 00:00:00 2001 From: Selase Krakani Date: Mon, 26 May 2025 01:48:20 +0000 Subject: [PATCH 2/3] ammend --- migrations/config/intermediate_db.yml | 8 ++++++++ .../intermediate_db_schema/100-base-schema.sql | 6 +++--- .../database/intermediate_db/category_user.rb | 8 ++++---- migrations/lib/database/intermediate_db/group.rb | 5 ++++- .../lib/database/intermediate_db/group_user.rb | 16 ++-------------- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/migrations/config/intermediate_db.yml b/migrations/config/intermediate_db.yml index 21edbf6d66158..8c439b8bde76c 100644 --- a/migrations/config/intermediate_db.yml +++ b/migrations/config/intermediate_db.yml @@ -43,6 +43,7 @@ schema: - "created_at" - "id" category_users: + primary_key_column_names: [ "category_id", "user_id" ] columns: exclude: - "id" @@ -72,8 +73,15 @@ schema: primary_key_column_names: [original_id, channel_id, original_message_id, original_message_user_id ] group_users: primary_key_column_names: [ "group_id", "user_id" ] + columns: + exclude: + - "id" + - "created_at" groups: columns: + add: + - name: "existing_id" + datatype: text include: - "allow_membership_requests" - "allow_unknown_sender_topic_replies" diff --git a/migrations/db/intermediate_db_schema/100-base-schema.sql b/migrations/db/intermediate_db_schema/100-base-schema.sql index 892f311bdb0a8..649e5424555b2 100644 --- a/migrations/db/intermediate_db_schema/100-base-schema.sql +++ b/migrations/db/intermediate_db_schema/100-base-schema.sql @@ -88,9 +88,10 @@ CREATE TABLE category_custom_fields CREATE TABLE category_users ( category_id NUMERIC NOT NULL, + user_id NUMERIC NOT NULL, last_seen_at DATETIME, notification_level INTEGER NOT NULL, - user_id NUMERIC NOT NULL + PRIMARY KEY (category_id, user_id) ); CREATE TABLE chat_channels @@ -173,10 +174,8 @@ CREATE TABLE group_users ( group_id NUMERIC NOT NULL, user_id NUMERIC NOT NULL, - created_at DATETIME NOT NULL, first_unread_pm_at DATETIME NOT NULL, notification_level INTEGER, - original_id NUMERIC NOT NULL, owner BOOLEAN, PRIMARY KEY (group_id, user_id) ); @@ -191,6 +190,7 @@ CREATE TABLE "groups" bio_raw TEXT, created_at DATETIME NOT NULL, default_notification_level INTEGER, + existing_id TEXT, flair_bg_color TEXT, flair_color TEXT, flair_icon TEXT, diff --git a/migrations/lib/database/intermediate_db/category_user.rb b/migrations/lib/database/intermediate_db/category_user.rb index 44b250e285cef..8867dc114b417 100644 --- a/migrations/lib/database/intermediate_db/category_user.rb +++ b/migrations/lib/database/intermediate_db/category_user.rb @@ -9,22 +9,22 @@ module CategoryUser SQL = <<~SQL INSERT INTO category_users ( category_id, + user_id, last_seen_at, - notification_level, - user_id + notification_level ) VALUES ( ?, ?, ?, ? ) SQL - def self.create(category_id:, last_seen_at: nil, notification_level:, user_id:) + def self.create(category_id:, user_id:, last_seen_at: nil, notification_level:) ::Migrations::Database::IntermediateDB.insert( SQL, category_id, + user_id, ::Migrations::Database.format_datetime(last_seen_at), notification_level, - user_id, ) end end diff --git a/migrations/lib/database/intermediate_db/group.rb b/migrations/lib/database/intermediate_db/group.rb index dccc0339ace7f..1afb0c9f335a5 100644 --- a/migrations/lib/database/intermediate_db/group.rb +++ b/migrations/lib/database/intermediate_db/group.rb @@ -16,6 +16,7 @@ module Group bio_raw, created_at, default_notification_level, + existing_id, flair_bg_color, flair_color, flair_icon, @@ -34,7 +35,7 @@ module Group visibility_level ) VALUES ( - ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) SQL @@ -47,6 +48,7 @@ def self.create( bio_raw: nil, created_at:, default_notification_level: nil, + existing_id: nil, flair_bg_color: nil, flair_color: nil, flair_icon: nil, @@ -74,6 +76,7 @@ def self.create( bio_raw, ::Migrations::Database.format_datetime(created_at), default_notification_level, + existing_id, flair_bg_color, flair_color, flair_icon, diff --git a/migrations/lib/database/intermediate_db/group_user.rb b/migrations/lib/database/intermediate_db/group_user.rb index 934921a4ef304..08b1380c74111 100644 --- a/migrations/lib/database/intermediate_db/group_user.rb +++ b/migrations/lib/database/intermediate_db/group_user.rb @@ -10,34 +10,22 @@ module GroupUser INSERT INTO group_users ( group_id, user_id, - created_at, first_unread_pm_at, notification_level, - original_id, owner ) VALUES ( - ?, ?, ?, ?, ?, ?, ? + ?, ?, ?, ?, ? ) SQL - def self.create( - group_id:, - user_id:, - created_at:, - first_unread_pm_at:, - notification_level: nil, - original_id:, - owner: nil - ) + def self.create(group_id:, user_id:, first_unread_pm_at:, notification_level: nil, owner: nil) ::Migrations::Database::IntermediateDB.insert( SQL, group_id, user_id, - ::Migrations::Database.format_datetime(created_at), ::Migrations::Database.format_datetime(first_unread_pm_at), notification_level, - original_id, ::Migrations::Database.format_boolean(owner), ) end From 97107aa8518b71218b63eb1aef1107807a607a95 Mon Sep 17 00:00:00 2001 From: Selase Krakani Date: Tue, 27 May 2025 01:18:05 +0000 Subject: [PATCH 3/3] DEV: First pass at `tag_users` step for Discourse converter This change implements converter step for converting Discourse `tag_users` to intermediate DB format needed for import into Discourse. --- .../converters/discourse/steps/tag_users.rb | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 migrations/lib/converters/discourse/steps/tag_users.rb diff --git a/migrations/lib/converters/discourse/steps/tag_users.rb b/migrations/lib/converters/discourse/steps/tag_users.rb new file mode 100644 index 0000000000000..4f7145dea401b --- /dev/null +++ b/migrations/lib/converters/discourse/steps/tag_users.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module Migrations::Converters::Discourse + class TagUsers < ::Migrations::Converters::Base::ProgressStep + attr_accessor :source_db + + def max_progress + @source_db.count <<~SQL + SELECT COUNT(*) FROM tag_users + SQL + end + + def items + @source_db.query <<~SQL + SELECT * FROM tag_users + SQL + end + + def process_item(item) + IntermediateDB::TagUser.create( + tag_id: item[:tag_id], + user_id: item[:user_id], + created_at: item[:created_at], + notification_level: item[:notification_level], + original_id: item[:id], + ) + end + end +end