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

Ensure view_schema exists on pending/running check #399

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/sequent/rake/migration_tasks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ def register_tasks!
EOS
task init: :set_env_var

task connect_to_db: ['sequent:init', :init] do
desc 'Creates sequent view schema if not exists and runs internal migrations'
task create_and_migrate_sequent_view_schema: ['sequent:init', :init] do
ensure_sequent_env_set!
Sequent::Support::Database.connect!(@env)
Sequent::Migrations::ViewSchema.create_view_schema_if_not_exists(env: @env)
mvandiepen marked this conversation as resolved.
Show resolved Hide resolved
end

namespace :db do
Expand Down Expand Up @@ -96,12 +97,12 @@ def register_tasks!
task :init

desc 'Prints the current version in the database'
task current_version: [:connect_to_db] do
task current_version: [:create_and_migrate_sequent_view_schema] do
puts "Current version in the database is: #{Sequent::Migrations::Versions.current_version}"
end

desc 'Returns whether a migration is currently running'
task check_running_migrations: [:connect_to_db] do
task check_running_migrations: [:create_and_migrate_sequent_view_schema] do
if Sequent::Migrations::Versions.running.any?
puts "Migration is running, current version: #{Sequent::Migrations::Versions.current_version}, " /
"target version #{Sequent::Migrations::Versions.version_currently_migrating}"
Expand All @@ -111,7 +112,7 @@ def register_tasks!
end

desc 'Returns whether a migration is pending'
task check_pending_migrations: [:connect_to_db] do
task check_pending_migrations: [:create_and_migrate_sequent_view_schema] do
if Sequent.new_version != Sequent::Migrations::Versions.current_version
puts "Migration is pending, current version: #{Sequent::Migrations::Versions.current_version}, " /
"pending version: #{Sequent.new_version}"
Expand Down
Loading