Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions META6.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"Red::Column": "lib/Red/Column.rakumod",
"Red::ColumnMethods": "lib/Red/ColumnMethods.rakumod",
"Red::Config": "lib/Red/Config.rakumod",
"Red::Configuration": "lib/Red/Configuration.rakumod",
"Red::DB": "lib/Red/DB.rakumod",
"Red::Database": "lib/Red/Database.rakumod",
"Red::DefaultResultSeq": "lib/Red/DefaultResultSeq.rakumod",
Expand All @@ -113,6 +114,7 @@
"Red::FromRelationship": "lib/Red/FromRelationship.rakumod",
"Red::HiddenFromSQLCommenting": "lib/Red/HiddenFromSQLCommenting.rakumod",
"Red::LockType": "lib/Red/LockType.rakumod",
"Red::Migration::Applied": "lib/Red/Migration/Applied.rakumod",
"Red::Migration::Column": "lib/Red/Migration/Column.rakumod",
"Red::Migration::Migration": "lib/Red/Migration/Migration.rakumod",
"Red::Migration::Table": "lib/Red/Migration/Table.rakumod",
Expand Down
60 changes: 56 additions & 4 deletions bin/red
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!env perl6
#!/usr/bin/env raku
use Red::Cli;
use Red::Do;
use Red::DB;
use Red::Database;
use Red::Configuration;

my %*SUB-MAIN-OPTS =
:named-anywhere,
Expand Down Expand Up @@ -36,7 +38,6 @@ multi MAIN(
say gen-stub-code :$schema-class, :$driver, |%pars
}


#| Generates migration plan to upgrade database schema
multi MAIN(
"migration-plan",
Expand All @@ -57,7 +58,6 @@ multi MAIN(
Str :$schema-class,
Bool :$print-stub = False,
Bool :$no-relationships = False,
#Bool :$stub-only,
Str :$driver!,
*%pars
) {
Expand All @@ -84,6 +84,58 @@ multi MAIN(
prepare-database :$populate, :$models, :$driver, |%pars
}

#============================================
# MIGRATION COMMANDS
#============================================

#| Update local DB to match model, save model snapshot for future diffs
multi MAIN(
"migration",
"update",
Str :$model!,
Str :$require = $model,
Str :$driver!,
*%pars
) {
$GLOBAL::RED-DB = database($driver, |%pars);
migration-update :$model, :$require, :$driver, |%pars;
}

#| Rollback the last applied migration on the local DB
multi MAIN(
"migration",
"downgrade",
Str :$driver!,
*%pars
) {
$GLOBAL::RED-DB = database($driver, |%pars);
migration-downgrade :$driver, |%pars;
}

#| Generate SQL migration files (up.sql + down.sql) from model snapshots
multi MAIN(
"migration",
"prepare",
Str :$model!,
Str :$require = $model,
Str :$driver!,
*%pars
) {
$GLOBAL::RED-DB = database($driver, |%pars);
migration-prepare :$model, :$require, :$driver, |%pars;
}

#| Apply pending SQL migrations to the target database
multi MAIN(
"migration",
"apply",
Str :$driver!,
*%pars
) {
$GLOBAL::RED-DB = database($driver, |%pars);
migration-apply :$driver, |%pars;
}

sub dyn-lib(@libs) {
qq[use lib "{ $_ }"].EVAL for @libs
qq[use lib "{ $_ }"].EVAL for @libs

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These days, would it be better to use .AST.EVAL?

}
Loading
Loading