Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bin/rails solid_cache:install doesn't respect schema_format = :sql #228

Open
MaxLap opened this issue Oct 17, 2024 · 1 comment
Open

bin/rails solid_cache:install doesn't respect schema_format = :sql #228

MaxLap opened this issue Oct 17, 2024 · 1 comment

Comments

@MaxLap
Copy link

MaxLap commented Oct 17, 2024

In my config, I have config.active_record.schema_format = :sql

When running bin/rails solid_cache:install, it creates a db/cache_schema.rb, which appears to then be swiftly ignored by Rails' db:prepare task.

As a result, the database gets created, but is empty... which leads to problems :)

I don't know if sql mode can be supported or not. But if not, I would suggest raising and error in bin/rails solid_cache:install is that config is :sql.

Thanks!

@julianrubisch
Copy link

this has just bitten me too, so here's a workaround that helped:

  1. comment out config.active_record.schema_format = :sql
  2. now, run bin/rails db:create:cache and bin/rails db:prepare DATABASE=cache
  3. comment config.active_record.schema_format = :sql in again
  4. run bin/rails db:schema:dump:cache

that way you end up with a not quite valid cache_structure.sql. In my case, I had to manually add semicolons and remove the CREATE TABLE sqlite_sequence(name,seq); part.

here's the structure, for reference:

CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime(6) NOT NULL, "updated_at" datetime(6) NOT NULL);

CREATE TABLE "schema_migrations" ("version" varchar NOT NULL PRIMARY KEY);

CREATE TABLE "solid_cache_entries" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "key" blob(1024) NOT NULL, "value" blob(536870912) NOT NULL, "created_at" datetime(6) NOT NULL, "key_hash" integer(8) NOT NULL, "byte_size" integer(4) NOT NULL);
CREATE INDEX "index_solid_cache_entries_on_byte_size" ON "solid_cache_entries" ("byte_size");
CREATE UNIQUE INDEX "index_solid_cache_entries_on_key_hash" ON "solid_cache_entries" ("key_hash");
CREATE INDEX "index_solid_cache_entries_on_key_hash_and_byte_size" ON "solid_cache_entries" ("key_hash", "byte_size");
INSERT INTO "schema_migrations" (version) VALUES ('1');

pdobb added a commit to pdobb/minesweeper_alliance that referenced this issue Dec 21, 2024
Don't autoload templates. These are just used as generators and will
fail with syntax errors at autoload time in the production env.

Don't add environmnet-specific encrypted credentials keys to the repo.
- Also, we needed to check in config/credentials/production.yml.enc.

Fix the schema dumps for the solid trifecta to use *_structure.sql, as
expected in this app (as per the application config:
`config.active_record.schema_format = :sql`).
- This was required to get the database tables built when running e.g.
  `RAILS_ENV=production DB_PASSWORD=<password> rails db:create`
  ... and friends.
  - Basically, there's no other way that the databases for the solid_*
    gems can be created/added (we don't have their migration files).
- See: rails/solid_cache#228
pdobb added a commit to pdobb/minesweeper_alliance that referenced this issue Dec 23, 2024
Don't autoload templates. These are just used as generators and will
fail with syntax errors at autoload time in the production env.

Don't add environmnet-specific encrypted credentials keys to the repo.
- Also, we needed to check in config/credentials/production.yml.enc.

Fix the schema dumps for the solid trifecta to use *_structure.sql, as
expected in this app (as per the application config:
`config.active_record.schema_format = :sql`).
- This was required to get the database tables built when running e.g.
  `RAILS_ENV=production DB_PASSWORD=<password> rails db:create`
  ... and friends.
  - Basically, there's no other way that the databases for the solid_*
    gems can be created/added (we don't have their migration files).
- See: rails/solid_cache#228
pdobb added a commit to pdobb/minesweeper_alliance that referenced this issue Dec 27, 2024
Don't autoload templates. These are just used as generators and will
fail with syntax errors at autoload time in the production env.

Don't add environmnet-specific encrypted credentials keys to the repo.
- Also, we needed to check in config/credentials/production.yml.enc.

Fix the schema dumps for the solid trifecta to use *_structure.sql, as
expected in this app (as per the application config:
`config.active_record.schema_format = :sql`).
- This was required to get the database tables built when running e.g.
  `RAILS_ENV=production DB_PASSWORD=<password> rails db:create`
  ... and friends.
  - Basically, there's no other way that the databases for the solid_*
    gems can be created/added (we don't have their migration files).
- See: rails/solid_cache#228
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants