Skip to content

Commit

Permalink
Merge pull request #29 from planetscale/schema-load
Browse files Browse the repository at this point in the history
Adds a general psdb:schema:load for single DB rails apps
  • Loading branch information
mscoutermarsh authored Feb 26, 2025
2 parents eda66d0 + 2bb6c31 commit 6c0ba39
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/planetscale_rails/tasks/psdb.rake
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@ namespace :psdb do
end

namespace :schema do
desc "Connects to the current PlanetScale branch and runs rails db:schema:load"
task load: %i[environment check_ci create_creds] do
db_configs = ActiveRecord::Base.configurations.configs_for(env_name: ActiveRecord::Tasks::DatabaseTasks.env)

unless db_configs.size == 1
raise "Found multiple database configurations, please specify which database you want to load schema for using `psdb:schema:load:<database_name>`".colorize(:red)
end

puts "Loading schema..."

command = "DATABASE_URL=\"#{ENV["PSCALE_DATABASE_URL"]}\" bundle exec rails db:schema:load"
IO.popen(command) do |io|
io.each_line do |line|
puts line
end
end

unless $CHILD_STATUS.success?
puts "Failed to load schema".colorize(:red)
end
ensure
delete_password
end

namespace :load do
ActiveRecord::Tasks::DatabaseTasks.for_each(databases) do |name|
desc "Connects to the current PlanetScale branch and runs rails db:schema:load:#{name}"
Expand Down

0 comments on commit 6c0ba39

Please sign in to comment.