DEV: Apply syntax_tree formatting to db/*

This commit is contained in:
David Taylor
2023-01-09 11:59:41 +00:00
parent cb932d6ee1
commit b0fda61a8e
467 changed files with 1682 additions and 1624 deletions
+7 -13
View File
@@ -14,27 +14,23 @@ class AddThemes < ActiveRecord::Migration[4.2]
t.timestamps null: false
end
add_index :child_themes, [:parent_theme_id, :child_theme_id], unique: true
add_index :child_themes, [:child_theme_id, :parent_theme_id], unique: true
add_index :child_themes, %i[parent_theme_id child_theme_id], unique: true
add_index :child_themes, %i[child_theme_id parent_theme_id], unique: true
# versioning in color scheme table was very confusing, remove it
execute "DELETE FROM color_schemes WHERE versioned_id IS NOT NULL"
remove_column :color_schemes, :versioned_id
enabled_theme_count = execute("SELECT count(*) FROM themes WHERE enabled")
.to_a[0]["count"].to_i
enabled_theme_count = execute("SELECT count(*) FROM themes WHERE enabled").to_a[0]["count"].to_i
enabled_scheme_id = execute("SELECT id FROM color_schemes WHERE enabled")
.to_a[0]&.fetch("id")
enabled_scheme_id = execute("SELECT id FROM color_schemes WHERE enabled").to_a[0]&.fetch("id")
theme_key, theme_id =
execute("SELECT key, id FROM themes WHERE enabled").to_a[0]&.values
theme_key, theme_id = execute("SELECT key, id FROM themes WHERE enabled").to_a[0]&.values
if (enabled_theme_count == 0 && enabled_scheme_id) || enabled_theme_count > 1
puts "Creating a new default theme!"
theme_key = '7e202ef2-6666-47d5-98d8-a9c8d15e57dd'
theme_key = "7e202ef2-6666-47d5-98d8-a9c8d15e57dd"
sql = <<SQL
INSERT INTO themes(name,created_at,updated_at, enabled, key, user_id)
@@ -46,13 +42,11 @@ SQL
theme_id = execute(sql).to_a[0]["id"].to_i
end
if enabled_theme_count > 1
execute <<SQL
execute <<SQL if enabled_theme_count > 1
INSERT INTO child_themes(parent_theme_id, child_theme_id, created_at, updated_at)
SELECT #{theme_id.to_i}, id, created_at, updated_at
FROM themes WHERE enabled
SQL
end
if enabled_scheme_id
execute "UPDATE themes SET color_scheme_id=#{enabled_scheme_id.to_i} WHERE id=#{theme_id.to_i}"