Skip to content

Commit

Permalink
fix: simply dump to file
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Aug 8, 2022
1 parent 73708a4 commit c930c12
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
11 changes: 2 additions & 9 deletions internal/db/diff/diff.go
Expand Up @@ -56,15 +56,8 @@ func Run(file string, fsys afero.Fs) error {
}

if len(file) > 0 {
// Pipe to new migration command
r, w, err := os.Pipe()
if err != nil {
return err
}
if _, err := w.WriteString(diff); err != nil {
return err
}
return new.Run(file, r, fsys)
path := new.GetMigrationPath(file)
return afero.WriteFile(fsys, path, []byte(diff), 0644)
} else {
fmt.Println(diff)
}
Expand Down
11 changes: 2 additions & 9 deletions internal/db/diff/migra.go
Expand Up @@ -79,15 +79,8 @@ func RunMigra(ctx context.Context, schema []string, file string, fsys afero.Fs)
if len(out) < 2 {
fmt.Fprintln(os.Stderr, "No changes found")
} else if len(file) > 0 {
// Pipe to new migration command
r, w, err := os.Pipe()
if err != nil {
return err
}
if _, err := w.WriteString(diff); err != nil {
return err
}
return new.Run(file, r, fsys)
path := new.GetMigrationPath(file)
return afero.WriteFile(fsys, path, []byte(out), 0644)
} else {
fmt.Println(out)
}
Expand Down
8 changes: 6 additions & 2 deletions internal/migration/new/new.go
Expand Up @@ -15,8 +15,7 @@ func Run(migrationName string, stdin afero.File, fsys afero.Fs) error {
return err
}

name := utils.GetCurrentTimestamp() + "_" + migrationName + ".sql"
path := filepath.Join(utils.MigrationsDir, name)
path := GetMigrationPath(migrationName)
f, err := fsys.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
Expand All @@ -35,3 +34,8 @@ func Run(migrationName string, stdin afero.File, fsys afero.Fs) error {
fmt.Println("Created new migration at " + utils.Bold(path) + ".")
return nil
}

func GetMigrationPath(migrationName string) string {
name := utils.GetCurrentTimestamp() + "_" + migrationName + ".sql"
return filepath.Join(utils.MigrationsDir, name)
}

0 comments on commit c930c12

Please sign in to comment.