Skip to content

Commit af4d016

Browse files
committed
Combine migrations for solid_cache_entries
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.
1 parent 8eaf08b commit af4d016

11 files changed

+35
-49
lines changed

db/migrate/20230724121448_create_solid_cache_entries.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

db/migrate/20240108155507_add_key_hash_and_byte_size_to_solid_cache_entries.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

db/migrate/20240110111600_add_key_hash_and_byte_size_indexes_and_null_constraints_to_solid_cache_entries.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

db/migrate/20240110111702_remove_key_index_from_solid_cache_entries.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class CreateSolidCacheEntries < ActiveRecord::Migration[7.2]
2+
def up
3+
create_table :solid_cache_entries, if_not_exists: true do |t|
4+
t.binary :key, null: false, limit: 1024
5+
t.binary :value, null: false, limit: 512.megabytes
6+
t.datetime :created_at, null: false
7+
t.integer :key_hash, null: false, limit: 8
8+
t.integer :byte_size, null: false, limit: 4
9+
10+
t.index :key_hash, unique: true
11+
t.index [:key_hash, :byte_size]
12+
t.index :byte_size
13+
end
14+
15+
raise "column \"key_hash\" does not exist" unless column_exists? :solid_cache_entries, :key_hash
16+
rescue => e
17+
if e.message =~ /(column "key_hash" does not exist|no such column: key_hash)/
18+
raise \
19+
"Could not find key_hash column on solid_cache_entries, if upgrading from v0.3 or earlier, have you followed " \
20+
"the steps in https://github.com/rails/solid_cache/blob/main/upgrading_to_version_0.4.x.md?"
21+
else
22+
raise
23+
end
24+
end
25+
26+
def down
27+
drop_table :solid_cache_entries
28+
end
29+
end

test/dummy/db/primary_shard_one_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do
1414
create_table "solid_cache_entries", force: :cascade do |t|
1515
t.binary "key", limit: 1024, null: false
1616
t.binary "value", limit: 536870912, null: false
@@ -21,5 +21,4 @@
2121
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
2222
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
2323
end
24-
2524
end

test/dummy/db/primary_shard_two_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do
1414
create_table "solid_cache_entries", force: :cascade do |t|
1515
t.binary "key", limit: 1024, null: false
1616
t.binary "value", limit: 536870912, null: false
@@ -21,5 +21,4 @@
2121
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
2222
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
2323
end
24-
2524
end

test/dummy/db/primary_unprepared_statements_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do
1414
create_table "solid_cache_entries", force: :cascade do |t|
1515
t.binary "key", limit: 1024, null: false
1616
t.binary "value", limit: 536870912, null: false
@@ -21,5 +21,4 @@
2121
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
2222
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
2323
end
24-
2524
end

test/dummy/db/schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do
1414
create_table "solid_cache_entries", force: :cascade do |t|
1515
t.binary "key", limit: 1024, null: false
1616
t.binary "value", limit: 536870912, null: false
@@ -21,5 +21,4 @@
2121
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
2222
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
2323
end
24-
2524
end

test/dummy/db/secondary_shard_one_schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2024_01_10_111702) do
13+
ActiveRecord::Schema[7.2].define(version: 2024_08_20_123641) do
1414
create_table "solid_cache_entries", force: :cascade do |t|
1515
t.binary "key", limit: 1024, null: false
1616
t.binary "value", limit: 536870912, null: false
@@ -21,5 +21,4 @@
2121
t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size"
2222
t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true
2323
end
24-
2524
end

0 commit comments

Comments
 (0)