@@ -165,6 +165,27 @@ type (
165165 URL string
166166 RevisionsSchema string
167167 }
168+ // MigrateLsParams are the parameters for the `migrate ls` command.
169+ MigrateLsParams struct {
170+ ConfigURL string
171+ Env string
172+ Vars VarArgs
173+
174+ DirURL string
175+ Short bool // -s: print only migration version (omit description and .sql suffix)
176+ Latest bool // -l: print only the latest migration file
177+ }
178+ // MigrateSetParams are the parameters for the `migrate set` command.
179+ MigrateSetParams struct {
180+ ConfigURL string
181+ Env string
182+ Vars VarArgs
183+
184+ DirURL string
185+ URL string
186+ RevisionsSchema string
187+ Version string
188+ }
168189 // MigrateDiffParams are the parameters for the `migrate diff` command.
169190 MigrateDiffParams struct {
170191 ConfigURL string
@@ -419,6 +440,58 @@ func (c *Client) MigrateStatus(ctx context.Context, params *MigrateStatusParams)
419440 return firstResult (jsonDecode [MigrateStatus ](c .runCommand (ctx , args )))
420441}
421442
443+ // MigrateLs runs the 'migrate ls' command and returns the listed migration file names (or versions when Short is true), one per line.
444+ func (c * Client ) MigrateLs (ctx context.Context , params * MigrateLsParams ) (string , error ) {
445+ args := []string {"migrate" , "ls" }
446+ if params .ConfigURL != "" {
447+ args = append (args , "--config" , params .ConfigURL )
448+ }
449+ if params .Env != "" {
450+ args = append (args , "--env" , params .Env )
451+ }
452+ if params .DirURL != "" {
453+ args = append (args , "--dir" , params .DirURL )
454+ }
455+ if params .Vars != nil {
456+ args = append (args , params .Vars .AsArgs ()... )
457+ }
458+ if params .Short {
459+ args = append (args , "--short" )
460+ }
461+ if params .Latest {
462+ args = append (args , "--latest" )
463+ }
464+ return stringVal (c .runCommand (ctx , args ))
465+ }
466+
467+ // MigrateSet runs the 'migrate set' command.
468+ func (c * Client ) MigrateSet (ctx context.Context , params * MigrateSetParams ) error {
469+ args := []string {"migrate" , "set" }
470+ if params .Env != "" {
471+ args = append (args , "--env" , params .Env )
472+ }
473+ if params .ConfigURL != "" {
474+ args = append (args , "--config" , params .ConfigURL )
475+ }
476+ if params .URL != "" {
477+ args = append (args , "--url" , params .URL )
478+ }
479+ if params .DirURL != "" {
480+ args = append (args , "--dir" , params .DirURL )
481+ }
482+ if params .RevisionsSchema != "" {
483+ args = append (args , "--revisions-schema" , params .RevisionsSchema )
484+ }
485+ if params .Vars != nil {
486+ args = append (args , params .Vars .AsArgs ()... )
487+ }
488+ if params .Version != "" {
489+ args = append (args , params .Version )
490+ }
491+ _ , err := c .runCommand (ctx , args )
492+ return err
493+ }
494+
422495// MigrateDiff runs the 'migrate diff --dry-run' command and returns the generated migration files without changing the filesystem.
423496// Requires atlas CLI to be logged in to the cloud.
424497func (c * Client ) MigrateDiff (ctx context.Context , params * MigrateDiffParams ) (* MigrateDiff , error ) {
@@ -526,7 +599,7 @@ func (c *Client) MigrateRebase(ctx context.Context, params *MigrateRebaseParams)
526599 if params .DirURL != "" {
527600 args = append (args , "--dir" , params .DirURL )
528601 }
529- args = append (args , strings . Join ( params .Files , " " ) )
602+ args = append (args , params .Files ... )
530603 _ , err := c .runCommand (ctx , args )
531604 return err
532605}
@@ -734,10 +807,16 @@ func newMigrateApplyError(r []*MigrateApply, stderr string) error {
734807
735808// Error implements the error interface.
736809func (e * MigrateApplyError ) Error () string {
810+ var errs []string
811+ for _ , r := range e .Result {
812+ if r .Error != "" {
813+ errs = append (errs , r .Error )
814+ }
815+ }
737816 if e .Stderr != "" {
738- return e .Stderr
817+ errs = append ( errs , e .Stderr )
739818 }
740- return last ( e . Result ). Error
819+ return strings . Join ( errs , " \n " )
741820}
742821
743822func plural (n int ) (s string ) {
0 commit comments