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:
Timothy Messier authored and GitHub committed 2021-11-05 14:57:10 -04:00
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) {
@@ -0,0 +1,5 @@
begin;
create table one (
id bigint primary key
);
commit;
@@ -0,0 +1,5 @@
begin;
create table one_also (
id bigint primary key
);
commit;