mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 11:41:45 +08:00
REFACTOR: Code generator for migrations IntemerdiateDB
* Splits the existing script into multiple classes * Adds command for generating IntermediateDB schema (`migrations/bin/cli schema generate`) * Changes the syntax of the IntermediateDB schema config * Adds validation for the schema config * It uses YAML schema aka JSON schema to validate the config file * It generates the SQL schema file and Ruby classes for storing data in the IntermediateDB
This commit is contained in:

committed by
Gerhard Schlager

parent
71a90dcba2
commit
17ba19c7ae
105
migrations/lib/database/intermediate_db/user.rb
Normal file
105
migrations/lib/database/intermediate_db/user.rb
Normal file
@ -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 User
|
||||
SQL = <<~SQL
|
||||
INSERT INTO users (
|
||||
original_id,
|
||||
active,
|
||||
admin,
|
||||
approved,
|
||||
approved_at,
|
||||
approved_by_id,
|
||||
created_at,
|
||||
date_of_birth,
|
||||
first_seen_at,
|
||||
flair_group_id,
|
||||
group_locked_trust_level,
|
||||
ip_address,
|
||||
last_seen_at,
|
||||
locale,
|
||||
manual_locked_trust_level,
|
||||
moderator,
|
||||
name,
|
||||
original_username,
|
||||
primary_group_id,
|
||||
registration_ip_address,
|
||||
silenced_till,
|
||||
staged,
|
||||
title,
|
||||
trust_level,
|
||||
uploaded_avatar_id,
|
||||
username,
|
||||
views
|
||||
)
|
||||
VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
SQL
|
||||
|
||||
def self.create(
|
||||
original_id:,
|
||||
active: nil,
|
||||
admin: nil,
|
||||
approved: nil,
|
||||
approved_at: nil,
|
||||
approved_by_id: nil,
|
||||
created_at:,
|
||||
date_of_birth: nil,
|
||||
first_seen_at: nil,
|
||||
flair_group_id: nil,
|
||||
group_locked_trust_level: nil,
|
||||
ip_address: nil,
|
||||
last_seen_at: nil,
|
||||
locale: nil,
|
||||
manual_locked_trust_level: nil,
|
||||
moderator: nil,
|
||||
name: nil,
|
||||
original_username: nil,
|
||||
primary_group_id: nil,
|
||||
registration_ip_address: nil,
|
||||
silenced_till: nil,
|
||||
staged: nil,
|
||||
title: nil,
|
||||
trust_level:,
|
||||
uploaded_avatar_id: nil,
|
||||
username:,
|
||||
views: nil
|
||||
)
|
||||
::Migrations::Database::IntermediateDB.insert(
|
||||
SQL,
|
||||
original_id,
|
||||
::Migrations::Database.format_boolean(active),
|
||||
::Migrations::Database.format_boolean(admin),
|
||||
::Migrations::Database.format_boolean(approved),
|
||||
::Migrations::Database.format_datetime(approved_at),
|
||||
approved_by_id,
|
||||
::Migrations::Database.format_datetime(created_at),
|
||||
::Migrations::Database.format_date(date_of_birth),
|
||||
::Migrations::Database.format_datetime(first_seen_at),
|
||||
flair_group_id,
|
||||
group_locked_trust_level,
|
||||
::Migrations::Database.format_ip_address(ip_address),
|
||||
::Migrations::Database.format_datetime(last_seen_at),
|
||||
locale,
|
||||
manual_locked_trust_level,
|
||||
::Migrations::Database.format_boolean(moderator),
|
||||
name,
|
||||
original_username,
|
||||
primary_group_id,
|
||||
::Migrations::Database.format_ip_address(registration_ip_address),
|
||||
::Migrations::Database.format_datetime(silenced_till),
|
||||
::Migrations::Database.format_boolean(staged),
|
||||
title,
|
||||
trust_level,
|
||||
uploaded_avatar_id,
|
||||
username,
|
||||
views,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
31
migrations/lib/database/intermediate_db/user_email.rb
Normal file
31
migrations/lib/database/intermediate_db/user_email.rb
Normal file
@ -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 UserEmail
|
||||
SQL = <<~SQL
|
||||
INSERT INTO user_emails (
|
||||
email,
|
||||
created_at,
|
||||
"primary",
|
||||
user_id
|
||||
)
|
||||
VALUES (
|
||||
?, ?, ?, ?
|
||||
)
|
||||
SQL
|
||||
|
||||
def self.create(email:, created_at:, primary: nil, user_id:)
|
||||
::Migrations::Database::IntermediateDB.insert(
|
||||
SQL,
|
||||
email,
|
||||
::Migrations::Database.format_datetime(created_at),
|
||||
::Migrations::Database.format_boolean(primary),
|
||||
user_id,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
199
migrations/lib/database/intermediate_db/user_option.rb
Normal file
199
migrations/lib/database/intermediate_db/user_option.rb
Normal file
@ -0,0 +1,199 @@
|
||||
# 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 UserOption
|
||||
SQL = <<~SQL
|
||||
INSERT INTO user_options (
|
||||
user_id,
|
||||
allow_private_messages,
|
||||
auto_track_topics_after_msecs,
|
||||
automatically_unpin_topics,
|
||||
bookmark_auto_delete_preference,
|
||||
chat_email_frequency,
|
||||
chat_enabled,
|
||||
chat_header_indicator_preference,
|
||||
chat_quick_reaction_type,
|
||||
chat_quick_reactions_custom,
|
||||
chat_send_shortcut,
|
||||
chat_separate_sidebar_mode,
|
||||
chat_sound,
|
||||
color_scheme_id,
|
||||
dark_scheme_id,
|
||||
default_calendar,
|
||||
digest_after_minutes,
|
||||
dismissed_channel_retention_reminder,
|
||||
dismissed_dm_retention_reminder,
|
||||
dynamic_favicon,
|
||||
email_digests,
|
||||
email_in_reply_to,
|
||||
email_level,
|
||||
email_messages_level,
|
||||
email_previous_replies,
|
||||
enable_allowed_pm_users,
|
||||
enable_defer,
|
||||
enable_experimental_sidebar,
|
||||
enable_quoting,
|
||||
enable_smart_lists,
|
||||
external_links_in_new_tab,
|
||||
hide_presence,
|
||||
hide_profile,
|
||||
hide_profile_and_presence,
|
||||
homepage_id,
|
||||
ignore_channel_wide_mention,
|
||||
include_tl0_in_digests,
|
||||
last_redirected_to_top_at,
|
||||
like_notification_frequency,
|
||||
mailing_list_mode,
|
||||
mailing_list_mode_frequency,
|
||||
new_topic_duration_minutes,
|
||||
notification_level_when_replying,
|
||||
oldest_search_log_date,
|
||||
only_chat_push_notifications,
|
||||
seen_popups,
|
||||
show_thread_title_prompts,
|
||||
sidebar_link_to_filtered_list,
|
||||
sidebar_show_count_of_new_items,
|
||||
skip_new_user_tips,
|
||||
text_size_key,
|
||||
text_size_seq,
|
||||
theme_ids,
|
||||
theme_key_seq,
|
||||
timezone,
|
||||
title_count_mode_key,
|
||||
topics_unread_when_closed,
|
||||
watched_precedence_over_muted
|
||||
)
|
||||
VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
||||
)
|
||||
SQL
|
||||
|
||||
def self.create(
|
||||
user_id:,
|
||||
allow_private_messages: nil,
|
||||
auto_track_topics_after_msecs: nil,
|
||||
automatically_unpin_topics: nil,
|
||||
bookmark_auto_delete_preference: nil,
|
||||
chat_email_frequency: nil,
|
||||
chat_enabled: nil,
|
||||
chat_header_indicator_preference: nil,
|
||||
chat_quick_reaction_type: nil,
|
||||
chat_quick_reactions_custom: nil,
|
||||
chat_send_shortcut: nil,
|
||||
chat_separate_sidebar_mode: nil,
|
||||
chat_sound: nil,
|
||||
color_scheme_id: nil,
|
||||
dark_scheme_id: nil,
|
||||
default_calendar: nil,
|
||||
digest_after_minutes: nil,
|
||||
dismissed_channel_retention_reminder: nil,
|
||||
dismissed_dm_retention_reminder: nil,
|
||||
dynamic_favicon: nil,
|
||||
email_digests: nil,
|
||||
email_in_reply_to: nil,
|
||||
email_level: nil,
|
||||
email_messages_level: nil,
|
||||
email_previous_replies: nil,
|
||||
enable_allowed_pm_users: nil,
|
||||
enable_defer: nil,
|
||||
enable_experimental_sidebar: nil,
|
||||
enable_quoting: nil,
|
||||
enable_smart_lists: nil,
|
||||
external_links_in_new_tab: nil,
|
||||
hide_presence: nil,
|
||||
hide_profile: nil,
|
||||
hide_profile_and_presence: nil,
|
||||
homepage_id: nil,
|
||||
ignore_channel_wide_mention: nil,
|
||||
include_tl0_in_digests: nil,
|
||||
last_redirected_to_top_at: nil,
|
||||
like_notification_frequency: nil,
|
||||
mailing_list_mode: nil,
|
||||
mailing_list_mode_frequency: nil,
|
||||
new_topic_duration_minutes: nil,
|
||||
notification_level_when_replying: nil,
|
||||
oldest_search_log_date: nil,
|
||||
only_chat_push_notifications: nil,
|
||||
seen_popups: nil,
|
||||
show_thread_title_prompts: nil,
|
||||
sidebar_link_to_filtered_list: nil,
|
||||
sidebar_show_count_of_new_items: nil,
|
||||
skip_new_user_tips: nil,
|
||||
text_size_key: nil,
|
||||
text_size_seq: nil,
|
||||
theme_ids: nil,
|
||||
theme_key_seq: nil,
|
||||
timezone: nil,
|
||||
title_count_mode_key: nil,
|
||||
topics_unread_when_closed: nil,
|
||||
watched_precedence_over_muted: nil
|
||||
)
|
||||
::Migrations::Database::IntermediateDB.insert(
|
||||
SQL,
|
||||
user_id,
|
||||
::Migrations::Database.format_boolean(allow_private_messages),
|
||||
auto_track_topics_after_msecs,
|
||||
::Migrations::Database.format_boolean(automatically_unpin_topics),
|
||||
bookmark_auto_delete_preference,
|
||||
chat_email_frequency,
|
||||
::Migrations::Database.format_boolean(chat_enabled),
|
||||
chat_header_indicator_preference,
|
||||
chat_quick_reaction_type,
|
||||
chat_quick_reactions_custom,
|
||||
chat_send_shortcut,
|
||||
chat_separate_sidebar_mode,
|
||||
chat_sound,
|
||||
color_scheme_id,
|
||||
dark_scheme_id,
|
||||
default_calendar,
|
||||
digest_after_minutes,
|
||||
::Migrations::Database.format_boolean(dismissed_channel_retention_reminder),
|
||||
::Migrations::Database.format_boolean(dismissed_dm_retention_reminder),
|
||||
::Migrations::Database.format_boolean(dynamic_favicon),
|
||||
::Migrations::Database.format_boolean(email_digests),
|
||||
::Migrations::Database.format_boolean(email_in_reply_to),
|
||||
email_level,
|
||||
email_messages_level,
|
||||
email_previous_replies,
|
||||
::Migrations::Database.format_boolean(enable_allowed_pm_users),
|
||||
::Migrations::Database.format_boolean(enable_defer),
|
||||
::Migrations::Database.format_boolean(enable_experimental_sidebar),
|
||||
::Migrations::Database.format_boolean(enable_quoting),
|
||||
::Migrations::Database.format_boolean(enable_smart_lists),
|
||||
::Migrations::Database.format_boolean(external_links_in_new_tab),
|
||||
::Migrations::Database.format_boolean(hide_presence),
|
||||
::Migrations::Database.format_boolean(hide_profile),
|
||||
::Migrations::Database.format_boolean(hide_profile_and_presence),
|
||||
homepage_id,
|
||||
::Migrations::Database.format_boolean(ignore_channel_wide_mention),
|
||||
::Migrations::Database.format_boolean(include_tl0_in_digests),
|
||||
::Migrations::Database.format_datetime(last_redirected_to_top_at),
|
||||
like_notification_frequency,
|
||||
::Migrations::Database.format_boolean(mailing_list_mode),
|
||||
mailing_list_mode_frequency,
|
||||
new_topic_duration_minutes,
|
||||
notification_level_when_replying,
|
||||
::Migrations::Database.format_datetime(oldest_search_log_date),
|
||||
::Migrations::Database.format_boolean(only_chat_push_notifications),
|
||||
seen_popups,
|
||||
::Migrations::Database.format_boolean(show_thread_title_prompts),
|
||||
::Migrations::Database.format_boolean(sidebar_link_to_filtered_list),
|
||||
::Migrations::Database.format_boolean(sidebar_show_count_of_new_items),
|
||||
::Migrations::Database.format_boolean(skip_new_user_tips),
|
||||
text_size_key,
|
||||
text_size_seq,
|
||||
theme_ids,
|
||||
theme_key_seq,
|
||||
timezone,
|
||||
title_count_mode_key,
|
||||
::Migrations::Database.format_boolean(topics_unread_when_closed),
|
||||
::Migrations::Database.format_boolean(watched_precedence_over_muted),
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
29
migrations/lib/database/intermediate_db/user_suspension.rb
Normal file
29
migrations/lib/database/intermediate_db/user_suspension.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Migrations::Database::IntermediateDB
|
||||
module UserSuspension
|
||||
SQL = <<~SQL
|
||||
INSERT INTO user_suspensions (
|
||||
user_id,
|
||||
suspended_at,
|
||||
suspended_till,
|
||||
suspended_by_id,
|
||||
reason
|
||||
)
|
||||
VALUES (
|
||||
?, ?, ?, ?, ?
|
||||
)
|
||||
SQL
|
||||
|
||||
def self.create(user_id:, suspended_at:, suspended_till: nil, suspended_by_id: nil, reason: nil)
|
||||
::Migrations::Database::IntermediateDB.insert(
|
||||
SQL,
|
||||
user_id,
|
||||
::Migrations::Database.format_datetime(suspended_at),
|
||||
::Migrations::Database.format_datetime(suspended_till),
|
||||
suspended_by_id,
|
||||
reason,
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user