Run migrations through CLI instead of when app starts
This commit is contained in:
parent
cf13c11236
commit
59654289cb
@ -102,6 +102,10 @@ Kemal.config.extra_options do |parser|
|
||||
puts SOFTWARE.to_pretty_json
|
||||
exit
|
||||
end
|
||||
parser.on("--migrate", "Run any migrations") do
|
||||
Invidious::Database::Migrator.new(PG_DB).migrate
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
Kemal::CLI.new ARGV
|
||||
@ -113,7 +117,10 @@ OUTPUT = CONFIG.output.upcase == "STDOUT" ? STDOUT : File.open(CONFIG.output, mo
|
||||
LOGGER = Invidious::LogHandler.new(OUTPUT, CONFIG.log_level)
|
||||
|
||||
# Run migrations
|
||||
Invidious::Database::Migrator.new(PG_DB).migrate
|
||||
if Invidious::Database::Migrator.new(PG_DB).pending_migrations?
|
||||
puts "There are pending migrations. Run `invidious --migrate` to apply the migrations."
|
||||
exit 46
|
||||
end
|
||||
# Check table integrity
|
||||
Invidious::Database.check_integrity(CONFIG)
|
||||
|
||||
|
@ -22,6 +22,13 @@ class Invidious::Database::Migrator
|
||||
puts "No migrations to run." unless ran_migration
|
||||
end
|
||||
|
||||
def pending_migrations? : Bool
|
||||
versions = load_versions
|
||||
|
||||
load_migrations.sort_by(&.version)
|
||||
.any? { |migration| !versions.includes?(migration.version) }
|
||||
end
|
||||
|
||||
private def load_migrations : Array(Invidious::Database::Migration)
|
||||
self.class.migrations.map(&.new(@db))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user