diff --git a/db/migrate/20230724121448_create_solid_cache_entries.rb b/db/migrate/20230724121448_create_solid_cache_entries.rb deleted file mode 100644 index 82749d9..0000000 --- a/db/migrate/20230724121448_create_solid_cache_entries.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateSolidCacheEntries < ActiveRecord::Migration[7.0] - def change - create_table :solid_cache_entries do |t| - t.binary :key, null: false, limit: 1024 - t.binary :value, null: false, limit: 512.megabytes - t.datetime :created_at, null: false - - t.index :key, unique: true - end - end -end diff --git a/db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb b/db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb deleted file mode 100644 index 871d5b9..0000000 --- a/db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddKeyHashAndByteSizeToSolidCacheEntries < ActiveRecord::Migration[7.0] - def change - change_table :solid_cache_entries do |t| - t.column :key_hash, :integer, null: true, limit: 8 - t.column :byte_size, :integer, null: true, limit: 4 - end - end -end diff --git a/db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb b/db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb deleted file mode 100644 index a0662ec..0000000 --- a/db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb +++ /dev/null @@ -1,11 +0,0 @@ -class AddKeyHashAndByteSizeIndexesAndNullConstraintsToSolidCacheEntries < ActiveRecord::Migration[7.0] - def change - change_table :solid_cache_entries, bulk: true do |t| - t.change_null :key_hash, false - t.change_null :byte_size, false - t.index :key_hash, unique: true - t.index [:key_hash, :byte_size] - t.index :byte_size - end - end -end diff --git a/db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb b/db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb deleted file mode 100644 index 975834b..0000000 --- a/db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RemoveKeyIndexFromSolidCacheEntries < ActiveRecord::Migration[7.0] - def change - change_table :solid_cache_entries do |t| - t.remove_index :key, unique: true - end - end -end diff --git a/db/migrate/20240820123641_create_solid_cache_entries.rb b/db/migrate/20240820123641_create_solid_cache_entries.rb new file mode 100644 index 0000000..8f85f55 --- /dev/null +++ b/db/migrate/20240820123641_create_solid_cache_entries.rb @@ -0,0 +1,29 @@ +class CreateSolidCacheEntries < ActiveRecord::Migration[7.2] + def up + create_table :solid_cache_entries, if_not_exists: true do |t| + t.binary :key, null: false, limit: 1024 + t.binary :value, null: false, limit: 512.megabytes + t.datetime :created_at, null: false + t.integer :key_hash, null: false, limit: 8 + t.integer :byte_size, null: false, limit: 4 + + t.index :key_hash, unique: true + t.index [:key_hash, :byte_size] + t.index :byte_size + end + + raise "column \"key_hash\" does not exist" unless column_exists? :solid_cache_entries, :key_hash + rescue => e + if e.message =~ /(column "key_hash" does not exist|no such column: key_hash)/ + raise \ + "Could not find key_hash column on solid_cache_entries, if upgrading from v0.3 or earlier, have you followed " \ + "the steps in https://github.com/rails/solid_cache/blob/main/upgrading_to_version_0.4.x.md?" + else + raise + end + end + + def down + drop_table :solid_cache_entries + end +end diff --git a/test/dummy/db/primary_shard_one_schema.rb b/test/dummy/db/primary_shard_one_schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/primary_shard_one_schema.rb +++ b/test/dummy/db/primary_shard_one_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end diff --git a/test/dummy/db/primary_shard_two_schema.rb b/test/dummy/db/primary_shard_two_schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/primary_shard_two_schema.rb +++ b/test/dummy/db/primary_shard_two_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end diff --git a/test/dummy/db/primary_unprepared_statements_schema.rb b/test/dummy/db/primary_unprepared_statements_schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/primary_unprepared_statements_schema.rb +++ b/test/dummy/db/primary_unprepared_statements_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end diff --git a/test/dummy/db/schema.rb b/test/dummy/db/schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/schema.rb +++ b/test/dummy/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end diff --git a/test/dummy/db/secondary_shard_one_schema.rb b/test/dummy/db/secondary_shard_one_schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/secondary_shard_one_schema.rb +++ b/test/dummy/db/secondary_shard_one_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end diff --git a/test/dummy/db/secondary_shard_two_schema.rb b/test/dummy/db/secondary_shard_two_schema.rb index 1adf031..cc79c10 100644 --- a/test/dummy/db/secondary_shard_two_schema.rb +++ b/test/dummy/db/secondary_shard_two_schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do +ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do create_table "solid_cache_entries", force: :cascade do |t| t.binary "key", limit: 1024, null: false t.binary "value", limit: 536870912, null: false @@ -21,5 +21,4 @@ t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true end - end