From 6a1dcef6ef8bde6e0e62267bd024e175042acdc3 Mon Sep 17 00:00:00 2001 From: Jorge Manrubia Date: Fri, 25 Apr 2025 09:26:47 +0200 Subject: [PATCH] Add script to migrate existing events to the new format --- ...070025_migrate_existing_events_prefixes.rb | 20 +++++++++++++++++++ db/schema.rb | 3 ++- db/schema_cache.yml | 20 +++++++++++++++++-- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20250425070025_migrate_existing_events_prefixes.rb diff --git a/db/migrate/20250425070025_migrate_existing_events_prefixes.rb b/db/migrate/20250425070025_migrate_existing_events_prefixes.rb new file mode 100644 index 000000000..0b3840be9 --- /dev/null +++ b/db/migrate/20250425070025_migrate_existing_events_prefixes.rb @@ -0,0 +1,20 @@ +class MigrateExistingEventsPrefixes < ActiveRecord::Migration[8.1] + def change + execute <<-SQL + UPDATE events + SET + action = CASE + WHEN action = 'commented' THEN 'comment_created' + ELSE 'card_' || action + END, + eventable_id = CASE + WHEN action = 'commented' THEN json_extract(particulars, '$.comment_id') + ELSE eventable_id + END, + eventable_type = CASE + WHEN action = 'commented' THEN 'Comment' + ELSE eventable_type + END; + SQL + end +end diff --git a/db/schema.rb b/db/schema.rb index c318b2ee1..39f007f59 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.1].define(version: 2025_04_24_105223) do +ActiveRecord::Schema[8.1].define(version: 2025_04_25_070025) do create_table "accesses", force: :cascade do |t| t.integer "collection_id", null: false t.datetime "created_at", null: false @@ -292,6 +292,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_04_24_105223) do t.datetime "created_at", null: false t.string "title" t.datetime "updated_at", null: false + t.index ["title"], name: "index_tags_on_account_id_and_title", unique: true end create_table "users", force: :cascade do |t| diff --git a/db/schema_cache.yml b/db/schema_cache.yml index 208449c4b..00b890f15 100644 --- a/db/schema_cache.yml +++ b/db/schema_cache.yml @@ -1941,7 +1941,23 @@ indexes: nulls_not_distinct: comment: valid: true - tags: [] + tags: + - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition + table: tags + name: index_tags_on_account_id_and_title + unique: true + columns: + - title + lengths: {} + orders: {} + opclasses: {} + where: + type: + using: + include: + nulls_not_distinct: + comment: + valid: true users: - !ruby/object:ActiveRecord::ConnectionAdapters::IndexDefinition table: users @@ -2026,4 +2042,4 @@ indexes: comment: valid: true workflows: [] -version: 20250424105223 +version: 20250425070025