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

support structure.sql #17

Closed
mscoutermarsh opened this issue Nov 20, 2023 · 10 comments · Fixed by #18
Closed

support structure.sql #17

mscoutermarsh opened this issue Nov 20, 2023 · 10 comments · Fixed by #18

Comments

@mscoutermarsh
Copy link
Member

Currently, psdb:migrate errors for apps that use structure.sql for their schema.

Due to an SSL error with mysqldump. We likely need to modify some setting so that mysqldump passes the correct certificate when connecting.

mscoutermarsh added a commit that referenced this issue Nov 29, 2023
For: #17

This checks common CA paths and adds it to the connection string.
@joeldrapper
Copy link

I’ve been running into this. It’s great to see you're already on it! 🙏

@mscoutermarsh
Copy link
Member Author

Oh great! We've been struggling to recreate it consistently.

We tried this branch on one persons machine but it did not resolve it.

Could you share your mysqldump version?

@joeldrapper
Copy link

It’s 100% consistent on my machine. Happy to help out or even jump on a call if it would help. This is my version:

mysqldump  Ver 8.2.0 for macos14.0 on arm64 (Homebrew)

@mscoutermarsh
Copy link
Member Author

Thank you! I now have it reproducing on my own laptop. A solution feels close. 😄

@joeldrapper
Copy link

@mscoutermarsh it seems to mostly work, but there’s an incompatibility with the structure.sql generated on the server which means you can't use it locally.

This is the error I’m getting

@@GLOBAL.GTID_PURGED cannot be changed: the added gtid set must not overlap with @@GLOBAL.GTID_EXECUTED

My workaround for now is to:

  1. Run migrations locally
  2. Commit locally-generated structure.sql into version control
  3. Run migrations on PlanetScale branch
  4. Delete the structure.sql generated by PlanetScale.

@mscoutermarsh
Copy link
Member Author

Which Rails version? Latest?

It should be skipping the dump step.

@mscoutermarsh mscoutermarsh reopened this Jan 13, 2024
@mscoutermarsh
Copy link
Member Author

Ah, I've found the problem. Will try to get a fix done soon.

@mscoutermarsh
Copy link
Member Author

A fix for the schema dump has been released in 0.2.2. An env var is now set which can be used to disable the schema dump.

In config/application.rb you can add:

if ENV["DISABLE_SCHEMA_DUMP"]
  config.active_record.dump_schema_after_migration = false
end

@joeldrapper
Copy link

@mscoutermarsh this seems to work perfectly now. It does leave me wondering how anyone would notice drift between the local structure.sql file and the actual structure of production. Do you have any advice on detecting that?

@mscoutermarsh
Copy link
Member Author

@joeldrapper great!

We've found schema drift to be pretty unlikely when using this flow. The top cause is people modifying production directly.
With Safe Migrations turned on in production, any changes outside of the branching flow are blocked.

The other common cause of schema drift in most Rails apps is failed production migrations (running halfway and failing). This isn't an issue either when using the branching flow since we run every schema change through vitess online DDL. It must be successful before we write to the schema_migrations table in prod.

So while it is unlikely because of the above. I think the best way to check would be to do the following:

  1. create a branch
  2. rails psdb:schema:load
  3. Then check the branch page on planetscale for a diff. There shouldn't be one

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

Successfully merging a pull request may close this issue.

2 participants