Skip to content

Commit

Permalink
Combine migrations for solid_cache_entries
Browse files Browse the repository at this point in the history
Combine the migrations for solid_cache_entries into a single file. Spot
if someone is migrating directly from v0.3 or earlier and raise an error.
  • Loading branch information
djmb committed Aug 20, 2024
1 parent 8eaf08b commit af4d016
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 49 deletions.
11 changes: 0 additions & 11 deletions db/migrate/20230724121448_create_solid_cache_entries.rb

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 29 additions & 0 deletions db/migrate/20240820123641_create_solid_cache_entries.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/primary_shard_one_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/primary_shard_two_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/primary_unprepared_statements_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/secondary_shard_one_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 1 addition & 2 deletions test/dummy/db/secondary_shard_two_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit af4d016

Please sign in to comment.