discourse/migrations/lib/database/intermediate_db/user_field.rb
Gerhard Schlager 89f26da39d
MT: Switch to nested module style across migrations/ (#38564)
Ruby's compact module syntax (`module
Migrations::Database::Schema::DSL`) breaks lexical constant lookup —
`Module.nesting` only includes the innermost constant, so every
cross-module reference must be fully qualified. In practice this means
writing `Migrations::Database::Schema::Helpers` even when you're already
inside `Migrations::Database::Schema`.

Nested module definitions restore the full nesting chain, which brings
several practical benefits:

- **Less verbose code**: references like `Schema::Helpers`,
`Database::IntermediateDB`, or `Converters::Base::ProgressStep` work
without repeating the full path from root
- **Easier to write new code**: contributors don't need to remember
which prefixes are required — if you're inside the namespace, short
names just work
- **Fewer aliasing workarounds**: removes the need for constants like
`MappingType = Migrations::Importer::MappingType` that existed solely to
shorten references
- **Standard Ruby style**: consistent with how most Ruby projects and
gems structure their namespaces

The diff is large but mechanical — no logic changes, just module
wrapping and shortening references that the nesting now resolves.
Generated code (intermediate_db models/enums) keeps fully qualified
references like `Migrations::Database.format_*` since it must work
regardless of the configured output namespace.

- Convert 138 lib files from compact to nested module definitions
- Remove now-redundant fully qualified prefixes and aliases
- Update model and enum writers to generate nested modules with correct
indentation
- Regenerate all intermediate_db models and enums
2026-03-19 18:15:19 +01:00

89 lines
2.8 KiB
Ruby

# frozen_string_literal: true
# This file is auto-generated from the IntermediateDB schema. To make changes,
# update the configuration files in "migrations/config/schema/" and then run
# `migrations/bin/cli schema generate` to regenerate this file.
module Migrations
module Database
module IntermediateDB
module UserField
SQL = <<~SQL
INSERT INTO user_fields (
original_id,
created_at,
description,
editable,
external_name,
external_type,
field_type_enum,
name,
position,
requirement,
searchable,
show_on_profile,
show_on_signup,
show_on_user_card
)
VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
)
SQL
private_constant :SQL
# Creates a new `user_fields` record in the IntermediateDB.
#
# @param original_id [Integer, String]
# @param created_at [Time, nil]
# @param description [String]
# @param editable [Boolean, nil]
# @param external_name [String, nil]
# @param external_type [String, nil]
# @param field_type_enum [Integer]
# @param name [String]
# @param position [Integer, nil]
# @param requirement [Integer, nil]
# @param searchable [Boolean, nil]
# @param show_on_profile [Boolean, nil]
# @param show_on_signup [Boolean, nil]
# @param show_on_user_card [Boolean, nil]
#
# @return [void]
def self.create(
original_id:,
created_at: nil,
description:,
editable: nil,
external_name: nil,
external_type: nil,
field_type_enum:,
name:,
position: nil,
requirement: nil,
searchable: nil,
show_on_profile: nil,
show_on_signup: 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_enum,
name,
position,
requirement,
Migrations::Database.format_boolean(searchable),
Migrations::Database.format_boolean(show_on_profile),
Migrations::Database.format_boolean(show_on_signup),
Migrations::Database.format_boolean(show_on_user_card),
)
end
end
end
end
end