MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / migrateDownCommands

Function migrateDownCommands

cmd/migrate.go:89–124  ·  view source on GitHub ↗

migrateDownCommands creates the command for rolling back migrations.

()

Source from the content-addressed store, hash-verified

87
88// migrateDownCommands creates the command for rolling back migrations.
89func migrateDownCommands() *cobra.Command {
90 cmd := &cobra.Command{
91 Use: "down",
92 Run: func(cmd *cobra.Command, args []string) {
93 // Define the source of the migrations.
94 migrations := migrate.EmbedFileSystemMigrationSource{
95 FileSystem: ledgerforge.SQLFiles,
96 Root: "sql",
97 }
98
99 // Fetch the configuration.
100 cnf, err := config.Fetch()
101 if err != nil {
102 logrus.Errorf("Error fetching config: %v", err)
103 return
104 }
105
106 // Connect to the database.
107 db, err := database.ConnectDB(cnf.DataSource)
108 if err != nil {
109 logrus.Errorf("Error connecting to database: %v", err)
110 return
111 }
112
113 // Roll back the migrations.
114 n, err := migrate.Exec(db, "postgres", migrations, migrate.Down)
115 if err != nil {
116 logrus.Errorf("Error migrating down: %v", err)
117 } else {
118 logrus.Infof("Rolled back %d migrations!\n", n)
119 }
120 },
121 }
122
123 return cmd
124}

Callers 1

migrateCommandsFunction · 0.85

Calls 2

FetchFunction · 0.92
ConnectDBFunction · 0.92

Tested by

no test coverage detected