fix(schema): Prevent duplicate versions per edition (#1670)
This should help prevent issues like the one fixed in
f2ad4de554.
A version for a particular edition should only exist once, previously
which ever file was read last for a version would be included, which
would lead to some migrations not running.
This commit is contained in:
1 parent
b6ad76e4d2
commit
242e353f18
4 files changed
+19
No files matched your search
@@ -121,6 +121,9 @@ func New(name string, dialect Dialect, m embed.FS, priority int) Edition {
|
||||
}
|
||||
contents = strings.TrimSpace(contents)
|
||||
|
||||
if _, exists := migrations[fullV]; exists {
|
||||
panic(fmt.Sprintf("migration file for version %d already exists", fullV))
|
||||
}
|
||||
migrations[fullV] = []byte(contents)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -74,6 +74,8 @@ var (
|
||||
noMinorVersion embed.FS
|
||||
//go:embed testdata/invalid/no-major-version
|
||||
noMajorVersion embed.FS
|
||||
//go:embed testdata/invalid/duplicate-versions
|
||||
duplicateVersions embed.FS
|
||||
)
|
||||
|
||||
func TestNewPanics(t *testing.T) {
|
||||
@@ -103,6 +105,10 @@ func TestNewPanics(t *testing.T) {
|
||||
"noMajorVersion",
|
||||
noMajorVersion,
|
||||
},
|
||||
{
|
||||
"duplicateVersions",
|
||||
duplicateVersions,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
begin;
|
||||
create table one (
|
||||
id bigint primary key
|
||||
);
|
||||
commit;
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
begin;
|
||||
create table one_also (
|
||||
id bigint primary key
|
||||
);
|
||||
commit;
|
||||
Reference in new issue
Block a user