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

Feature request: Consider support for Postgres' CREATE DATABASE WITH TEMPLATE; or other 'clone a whole database' approaches #839

Open
doconnor-clintel opened this issue Feb 10, 2022 · 2 comments

Comments

@doconnor-clintel
Copy link

Currently; the default assumption is to create, migrate, seed, etc N databases; and this is generally pretty sensible.

  desc "Create test databases via db:create --> parallel:create[num_cpus]"
  task :create, :count do |_, args|
    ParallelTests::Tasks.run_in_parallel(
      "#{ParallelTests::Tasks.rake_bin} db:create RAILS_ENV=#{ParallelTests::Tasks.rails_env}", args
    )
  end

For CI pipelines with a large number of migrations or complex seeding however would benefit from:

  • Migrate, seed once - all of the "prepare" tasks
  • Snapshot
  • Create databases as a snapshot of only the end state.

Right now there are some strategies for dumping + loading schema; but less so with fully seeded data.
https://github.com/grosser/parallel_tests/blob/master/lib/parallel_tests/tasks.rb#L121

Postgres offers support for CREATE DATABASE x WITH TEMPLATE y; and it seems supported in activerecord - see https://dockyard.com/blog/2014/03/03/using-database-templates

SQLIte databases could in theory support this with a copy on the filesystem or inbuilt commands:
https://database.guide/clone-sqlite-database/

MySQL - doesn't seem supported without a dump + load.
SQL server - ditto.
Oracle - similar.

Docker based solutions - a similar effect could probably be achieved with a snapshot + starting many containers; but by this point you might not choose to use parallel_tests.

@grosser
Copy link
Owner

grosser commented Feb 10, 2022

if you can somehow make this work as an additional task and not too much hackery. then PR welcome ... just don't want this to be the default behavior since I expect lots of bugs (at least initially) and it's not what simple users would expect or need

@adis-io
Copy link
Contributor

adis-io commented May 30, 2022

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

3 participants