The PostgreSQL is dead, long live the SQLite !#258
Merged
Conversation
…from the primary database.
…d, before making the assertion.
251c051 to
882448a
Compare
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What I did in this Pull Request, and how to move the development database to SQLite
Back up the Postgres database with pg_dump
pg_dump postgres://postgres:postgres@127.0.0.1:25432/mie_development --inserts --data-only -T schema_migrations -T ar_internal_metadata -T '*solid_queue*' > tmp/database_backup.sql--insertoption to dump as SQLINSERTstatements instead of using theCOPYcommand.--data-onlyoption to exclude table creation queries from the dump file.-T schema_migrationsand-T ar_internal_metadataoptions to exclude the ActiveRecord metadata records. They already exists in the SQLite database file when migrating.-T '*solid_queue*'option to exclude the SolidQueue data.pg_dump postgres://postgres:postgres@127.0.0.1:25432/mie_development --inserts --data-only -t '*solid_queue*' > tmp/database_solid_queue_backup.sqlModify the dump file so that it can be restored in SQLite.
pgcatalog.setvalstatements.Remove the pg gem from you Gemfile, and add the sqlite3 gem.
vim Gemfile # Remove the `pg` gem manually in an editor. bundle add sqlite3Modify config/database.yml to use SQLite
(Optional) Move the
solid_queuetables to a separate database, isolating them from the primary database.When using SolidQueue before version 0.8, the tables for SolidQueue are created in the primary database. However, after version 0.8, the default behavior of SolidQueue is to create a separate database for SolidQueue. The tables still work in the primary database, but I think this is the best time to separate the database, as done in version 0.8 and later.
Add the queue database for
config/database.ymlThen, modify the environment config files
production.rbanddevelopment.rbto set the SolidQueueconnects_tooption to connect to the queue database.And migrate the queue database.
Add a concern to auto-gen UUID PK for models.
In SQLite, you can't use auto-generated UUID primary keys, so add a concern to generate a UUID when models are saved to the database.
Update your migration files from the first one, replacing PostgreSQL-specific statements with SQLite-compatible ones.
db/schema.rbfile so it will be regenerated when running a migration.Set up database.
Run
bin/rails db:migrateto regeneratedb/schema.rb.Run test.
Run tests, and if some tests fail, check the reason for failure and fix it. If it didn't happen due to differences between PostgreSQL and SQLite, modify the models or controllers accordingly.
bin/rails testIn this case, only one test has failed. This test checks an array retrieved via the model's
throughassociation and returns the correct array, but the order is different. Fix the test to call theordermethod on the array, ordering it byuid, before making the assertion.Restore the database with the modified dump files.
Remove docker-compose.yml
Clean up containers and remove docker-compose.yml file.