You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2021/08/02 20:58:04 UTC

[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #6057: Make `db/admin` use Migrate to migrate the Traffic Ops database

rawlinp commented on a change in pull request #6057:
URL: https://github.com/apache/trafficcontrol/pull/6057#discussion_r681265217



##########
File path: traffic_ops/app/db/admin.go
##########
@@ -463,3 +564,49 @@ func main() {
 		die("invalid command: " + userCmd)
 	}
 }
+
+func initMigrate() {
+	var err error
+	connectionString := fmt.Sprintf("%s://%s:%s@%s:%s/%s?sslmode=%s", DBDriver, DBUser, DBPassword, HostIP, HostPort, DBName, SSLMode)
+	if !TrafficVault {

Review comment:
       this might be easier to read if we remove the negation and switch the branches
   ```
   if TrafficVault { 
       // do TV stuff
   } else {
       // do regular stuff
   }
   ```

##########
File path: traffic_ops/app/db/admin.go
##########
@@ -255,35 +302,84 @@ func reset() {
 	dropDB()
 	createDB()
 	loadSchema()
-	migrate()
+	runMigrations()
 }
 
 func upgrade() {
-	goose(GooseUp)
+	runMigrations()
 	if !TrafficVault {
 		seed()
 		patch()
 	}
 }
 
-func migrate() {
-	goose(GooseUp)
+func runMigrations() {
+	initMigrate()
+	migratedFromGoose := false
+	if !TrafficVault {
+		_, _, versionErr := Migrate.Version()
+		if versionErr != nil {
+			if versionErr != migrate.ErrNilVersion {
+				die("Error running migrate version: " + versionErr.Error())
+			}
+			migratedFromGoose = true
+			if err := Migrate.Steps(1); err != nil {
+				die("Error migrating to Migrate from Goose: " + err.Error())
+			}
+		}
+	}
+	upErr := Migrate.Up()
+	if upErr == migrate.ErrNoChange {
+		if !migratedFromGoose {
+			println(upErr.Error())
+		}
+	} else if upErr != nil {
+		die("Error running migrate up: " + upErr.Error())
+	}
+
+}
+
+func runUp() {
+	runMigrations()
 }
 
 func down() {
-	goose(CmdDown)
+	initMigrate()
+	if err := Migrate.Steps(-1); err != nil {
+		die("Error running migrate down: " + err.Error())
+	}
 }
 
 func redo() {
-	goose(CmdRedo)
+	initMigrate()
+	{

Review comment:
       are these separate scopes necessary? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org