|
8 | 8 | "path/filepath" |
9 | 9 | "regexp" |
10 | 10 | "strconv" |
11 | | - "strings" |
12 | 11 |
|
13 | 12 | "github.com/go-errors/errors" |
14 | 13 | "github.com/jackc/pgconn" |
@@ -46,43 +45,25 @@ func ListLocalMigrations(migrationsDir string, fsys fs.FS, filter ...func(string |
46 | 45 | fmt.Fprintf(os.Stderr, "Skipping migration %s... (replace \"init\" with a different file name to apply this migration)\n", filename) |
47 | 46 | continue |
48 | 47 | } |
49 | | - if strings.HasPrefix(filename, "r_") { |
50 | | - // silently skip repeatable migrations |
51 | | - continue |
52 | | - } |
53 | 48 | matches := migrateFilePattern.FindStringSubmatch(filename) |
54 | 49 | if len(matches) == 0 { |
55 | | - fmt.Fprintf(os.Stderr, "Skipping migration %s... (file name must match pattern \"<timestamp>_name.sql\")\n", filename) |
| 50 | + fmt.Fprintf(os.Stderr, "Skipping migration %s... (file name must match pattern \"<timestamp>_name.sql\" or \"r_name.sql\")\n", filename) |
56 | 51 | continue |
57 | 52 | } |
58 | 53 | path := filepath.Join(migrationsDir, filename) |
59 | 54 | for _, keep := range filter { |
60 | | - if version := matches[1]; keep(version) { |
| 55 | + version := matches[1] |
| 56 | + if version == "r" && len(matches) > 2 { |
| 57 | + version += "_" + matches[2] |
| 58 | + } |
| 59 | + if keep(version) { |
61 | 60 | clean = append(clean, path) |
62 | 61 | } |
63 | 62 | } |
64 | 63 | } |
65 | 64 | return clean, nil |
66 | 65 | } |
67 | 66 |
|
68 | | -func ListRepeatableMigrations(migrationsDir string, fsys fs.FS) ([]string, error) { |
69 | | - localMigrations, err := fs.ReadDir(fsys, migrationsDir) |
70 | | - if err != nil && !errors.Is(err, os.ErrNotExist) { |
71 | | - return nil, errors.Errorf("failed to read directory: %w", err) |
72 | | - } |
73 | | - var repeatable []string |
74 | | - |
75 | | - for _, migration := range localMigrations { |
76 | | - filename := migration.Name() |
77 | | - if strings.HasPrefix(filename, "r_") && strings.HasSuffix(filename, ".sql") { |
78 | | - path := filepath.Join(migrationsDir, filename) |
79 | | - repeatable = append(repeatable, path) |
80 | | - } |
81 | | - } |
82 | | - |
83 | | - return repeatable, nil |
84 | | -} |
85 | | - |
86 | 67 | var initSchemaPattern = regexp.MustCompile(`([0-9]{14})_init\.sql`) |
87 | 68 |
|
88 | 69 | func shouldSkip(name string) bool { |
|
0 commit comments