discourse/db/fixtures/600_themes.rb
Sam 6a3c8fe69c FEATURE: protect against accidental column or table drops
Often we need to amend our schema, it is tempting to use
drop_table, rename_column and drop_column to amned schema
trouble though is that existing code that is running in production
can depend on the existance of previous schema leading to application
breaking until new code base is deployed.

The commit enforces new rules to ensure we can never drop tables or
columns in migrations and instead use Migration::ColumnDropper and
Migration::TableDropper to defer drop the db objects
2018-03-21 15:43:32 +11:00

29 lines
1008 B
Ruby

# we can not guess what to do if customization already started, so skip it
if !Theme.exists?
STDERR.puts "> Seeding dark and light themes"
name = I18n.t("wizard.step.colors.fields.theme_id.choices.dark.label")
dark_scheme = ColorScheme.find_by(base_scheme_id: "dark")
dark_scheme ||= ColorScheme.create_from_base(name: name, via_wizard: true, base_scheme_id: "dark")
name = I18n.t('color_schemes.dark_theme_name')
_dark_theme = Theme.create(name: name, user_id: -1,
color_scheme_id: dark_scheme.id,
user_selectable: true)
name = I18n.t('color_schemes.default_theme_name')
default_theme = Theme.create(name: name, user_id: -1,
user_selectable: true)
default_theme.set_default!
end
Migration::ColumnDropper.drop(
table: 'theme_fields',
after_migration: 'AddUploadIdToThemeFields',
columns: ['target'],
on_drop: ->() {
STDERR.puts 'Removing superflous theme_fields target column!'
}
)