Skip to content

Confusion regarding auto-generated cache_schema.rb #248

Open
@davidrossdegroot

Description

@davidrossdegroot

If your application is adding solid_cache and you have config.active_record.schema_format = :sql set, should the cache_schema.rb file be generated?

I was under the impression that you would not since:

  1. the application's database does not have a corresonding schema.rb
  2. the database.yml files specify a migrations_path which is where you would add the migration to create the solid_cache_entries table, not via the cache_schema.rb file.

db:seed Gets run twice

The reason I bring this up is that if for some reason a developer follows these steps, the db:seed task will be run a 2nd time on the application's database. Here are the steps to reproduce:

  1. rails new solid-cache-app --database=postgresql
  2. rails g model Dog. Add a name attribute to the dog and add this to the seeds.rb file Dog.create(name: "Fido")
  3. Set config.active_record.schema_format = :sql in application.rb
  4. Run rails db:prepare

add cache database steps

  1. Update the database.yml file to include the cache database
development:
  primary: &primary_development
    <<: *default
    database: multiple_db_app_development
  cache:
    <<: *primary_development
    database: multiple_db_app_development_cache
    migrations_paths: db/cache_migrate
  1. Create a migration for the solid_cache_entries.
class AddCacheDatabaseEntries < ActiveRecord::Migration[8.0]
  def change
    create_table "solid_cache_entries" do |t|
      t.binary "key", limit: 1024, null: false
      t.binary "value", limit: 536_870_912, null: false
      t.datetime "created_at", null: false
      t.integer "key_hash", limit: 8, null: false
      t.integer "byte_size", limit: 4, null: false
      t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size"
      t.index %w[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
end
  1. Remove the cache_schema.rb file because of the reasons mentioned above.
  2. Run rails db:prepare.

Expect the seed file to not have run on the primary database

Actual results: Seed file was run on primary database and you now have two dogs named Fido.

Environment

Rails version: 8.0.1
solid_cache version: 1.0.6
Ruby version: 3.4.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions