diff options
author | Starfall <us@starfall.systems> | 2022-07-25 18:53:31 -0500 |
---|---|---|
committer | Starfall <us@starfall.systems> | 2022-07-25 18:53:31 -0500 |
commit | 5b9419060d79eda85c40a12c567dd0e1e44a7ecb (patch) | |
tree | f5e21930844f7c11ae40b9097a78a32916ba5dba /db/migrate | |
parent | a137fecf94d25a03ef7224843c1afd0c30f428e6 (diff) | |
parent | 3a7c641dd4db1d67b172f731518b472d58dd2262 (diff) |
Merge remote-tracking branch 'glitch/main'
Diffstat (limited to 'db/migrate')
7 files changed, 105 insertions, 0 deletions
diff --git a/db/migrate/20220611210335_create_user_roles.rb b/db/migrate/20220611210335_create_user_roles.rb new file mode 100644 index 000000000..6b7f2b637 --- /dev/null +++ b/db/migrate/20220611210335_create_user_roles.rb @@ -0,0 +1,13 @@ +class CreateUserRoles < ActiveRecord::Migration[6.1] + def change + create_table :user_roles do |t| + t.string :name, null: false, default: '' + t.string :color, null: false, default: '' + t.integer :position, null: false, default: 0 + t.bigint :permissions, null: false, default: 0 + t.boolean :highlighted, null: false, default: false + + t.timestamps + end + end +end diff --git a/db/migrate/20220611212541_add_role_id_to_users.rb b/db/migrate/20220611212541_add_role_id_to_users.rb new file mode 100644 index 000000000..2fda647d4 --- /dev/null +++ b/db/migrate/20220611212541_add_role_id_to_users.rb @@ -0,0 +1,8 @@ +class AddRoleIdToUsers < ActiveRecord::Migration[6.1] + disable_ddl_transaction! + + def change + safety_assured { add_reference :users, :role, foreign_key: { to_table: 'user_roles', on_delete: :nullify }, index: false } + add_index :users, :role_id, algorithm: :concurrently, where: 'role_id IS NOT NULL' + end +end diff --git a/db/migrate/20220613110628_create_custom_filter_keywords.rb b/db/migrate/20220613110628_create_custom_filter_keywords.rb new file mode 100644 index 000000000..353fc334f --- /dev/null +++ b/db/migrate/20220613110628_create_custom_filter_keywords.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class CreateCustomFilterKeywords < ActiveRecord::Migration[6.1] + def change + create_table :custom_filter_keywords do |t| + t.belongs_to :custom_filter, foreign_key: { on_delete: :cascade }, null: false + t.text :keyword, null: false, default: '' + t.boolean :whole_word, null: false, default: true + + t.timestamps + end + end +end diff --git a/db/migrate/20220613110711_migrate_custom_filters.rb b/db/migrate/20220613110711_migrate_custom_filters.rb new file mode 100644 index 000000000..ea6a9b8c6 --- /dev/null +++ b/db/migrate/20220613110711_migrate_custom_filters.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +class MigrateCustomFilters < ActiveRecord::Migration[6.1] + def up + # Preserve IDs as much as possible to not confuse existing clients. + # As long as this migration is irreversible, we do not have to deal with conflicts. + safety_assured do + execute <<-SQL.squish + INSERT INTO custom_filter_keywords (id, custom_filter_id, keyword, whole_word, created_at, updated_at) + SELECT id, id, phrase, whole_word, created_at, updated_at + FROM custom_filters + SQL + end + end + + def down + # Copy back changes from custom filters guaranteed to be from the old API + safety_assured do + execute <<-SQL.squish + UPDATE custom_filters + SET phrase = custom_filter_keywords.keyword, whole_word = custom_filter_keywords.whole_word + FROM custom_filter_keywords + WHERE custom_filters.id = custom_filter_keywords.id AND custom_filters.id = custom_filter_keywords.custom_filter_id + SQL + end + + # Drop every keyword as we can't safely provide a 1:1 mapping + safety_assured do + execute <<-SQL.squish + TRUNCATE custom_filter_keywords RESTART IDENTITY + SQL + end + end +end diff --git a/db/migrate/20220613110834_add_action_to_custom_filters.rb b/db/migrate/20220613110834_add_action_to_custom_filters.rb new file mode 100644 index 000000000..9427a66fc --- /dev/null +++ b/db/migrate/20220613110834_add_action_to_custom_filters.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +require Rails.root.join('lib', 'mastodon', 'migration_helpers') + +class AddActionToCustomFilters < ActiveRecord::Migration[6.1] + include Mastodon::MigrationHelpers + + disable_ddl_transaction! + + def up + safety_assured do + add_column_with_default :custom_filters, :action, :integer, allow_null: false, default: 0 + execute 'UPDATE custom_filters SET action = 1 WHERE irreversible IS TRUE' + end + end + + def down + execute 'UPDATE custom_filters SET irreversible = (action = 1)' + remove_column :custom_filters, :action + end +end diff --git a/db/migrate/20220710102457_add_display_name_to_tags.rb b/db/migrate/20220710102457_add_display_name_to_tags.rb new file mode 100644 index 000000000..aa7867645 --- /dev/null +++ b/db/migrate/20220710102457_add_display_name_to_tags.rb @@ -0,0 +1,5 @@ +class AddDisplayNameToTags < ActiveRecord::Migration[6.1] + def change + add_column :tags, :display_name, :string + end +end diff --git a/db/migrate/20220714171049_create_tag_follows.rb b/db/migrate/20220714171049_create_tag_follows.rb new file mode 100644 index 000000000..a393e90f5 --- /dev/null +++ b/db/migrate/20220714171049_create_tag_follows.rb @@ -0,0 +1,12 @@ +class CreateTagFollows < ActiveRecord::Migration[6.1] + def change + create_table :tag_follows do |t| + t.belongs_to :tag, null: false, foreign_key: { on_delete: :cascade } + t.belongs_to :account, null: false, foreign_key: { on_delete: :cascade }, index: false + + t.timestamps + end + + add_index :tag_follows, [:account_id, :tag_id], unique: true + end +end |