-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into AN/refactor_rollout_tests
- Loading branch information
Showing
8 changed files
with
146 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 6 additions & 2 deletions
8
database/migrations/postgres/1720012750850077_rename_commit_events.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
ALTER TABLE IF EXISTS events | ||
RENAME TO commit_events; | ||
DO $$ | ||
BEGIN | ||
IF NOT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'commit_events') THEN | ||
ALTER TABLE IF EXISTS events RENAME TO commit_events; | ||
END IF; | ||
END $$; |
12 changes: 9 additions & 3 deletions
12
database/migrations/postgres/1720014158596691_fk_commit_events.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
DO $$ BEGIN IF NOT EXISTS ( | ||
SELECT 'fk_commit_events_transformer_id' | ||
FROM information_schema.table_constraints | ||
WHERE table_name = 'commit_events' | ||
AND constraint_name = 'fk_commit_events_transformer_id' | ||
) THEN | ||
ALTER TABLE commit_events | ||
ADD COLUMN IF NOT EXISTS transformerEslId INTEGER | ||
CONSTRAINT fk_commit_events_transformer_id | ||
REFERENCES event_sourcing_light(eslId) default 0; | ||
ADD COLUMN IF NOT EXISTS transformerEslId INTEGER CONSTRAINT fk_commit_events_transformer_id REFERENCES event_sourcing_light(eslId) default 0; | ||
end if; | ||
END $$; |
11 changes: 10 additions & 1 deletion
11
database/migrations/postgres/1720428454051313_fk_deployments.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
ALTER TABLE deployments ADD COLUMN IF NOT EXISTS transformerEslId INTEGER; | ||
DO $$ BEGIN IF NOT EXISTS ( | ||
SELECT 'fk_deployments_transformer_id' | ||
FROM information_schema.table_constraints | ||
WHERE table_name = 'deployments' | ||
AND constraint_name = 'fk_deployments_transformer_id' | ||
) THEN | ||
ALTER TABLE deployments | ||
ADD COLUMN IF NOT EXISTS transformerEslId INTEGER CONSTRAINT fk_deployments_transformer_id REFERENCES event_sourcing_light(eslId) default 0; | ||
end if; | ||
END $$; |
7 changes: 7 additions & 0 deletions
7
database/migrations/postgres/1721378995777505_rename_application_locks.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
DO $$ BEGIN IF NOT EXISTS ( | ||
SELECT 1 | ||
FROM information_schema.tables | ||
WHERE table_name = 'app_locks' | ||
) THEN | ||
ALTER TABLE IF EXISTS application_locks | ||
RENAME TO app_locks; | ||
END IF; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*This file is part of kuberpult. | ||
Kuberpult is free software: you can redistribute it and/or modify | ||
it under the terms of the Expat(MIT) License as published by | ||
the Free Software Foundation. | ||
Kuberpult is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
MIT License for more details. | ||
You should have received a copy of the MIT License | ||
along with kuberpult. If not, see <https://directory.fsf.org/wiki/License:Expat>. | ||
Copyright freiheit.com*/ | ||
|
||
package integration_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/freiheit-com/kuberpult/pkg/db" | ||
) | ||
|
||
func deleteSchemaMigrationsTable(cfg db.DBConfig) error { | ||
db, err := db.GetDBConnection(cfg) | ||
if err != nil { | ||
return err | ||
} | ||
_, err = db.Exec("DROP TABLE schema_migrations") | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
func TestMigrations(t *testing.T) { | ||
dbConfig := db.DBConfig{ | ||
DbHost: "localhost", | ||
DbPort: "5432", | ||
DbUser: "postgres", | ||
DbPassword: "mypassword", | ||
DbName: "kuberpult", | ||
DriverName: "postgres", | ||
MigrationsPath: "../../database/migrations/postgres", | ||
} | ||
dbHandler, err := db.Connect(dbConfig) | ||
if err != nil { | ||
t.Fatalf("Error establishing DB connection: %v", err) | ||
} | ||
pErr := dbHandler.DB.Ping() | ||
if pErr != nil { | ||
t.Fatalf("Error pinging database: %v", err) | ||
} | ||
if err := deleteSchemaMigrationsTable(dbConfig); err != nil { | ||
t.Fatalf("Failed to delete schema migrations table: %v", err) | ||
} | ||
testCases := []struct { | ||
name string | ||
}{ | ||
{ | ||
name: "Running migrations multiple times", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
// Run migrations for the first time | ||
if err := db.RunDBMigrations(dbConfig); err != nil { | ||
t.Errorf("Error running migrations: %v", err) | ||
} | ||
// Delete schema migrations | ||
if err := deleteSchemaMigrationsTable(dbConfig); err != nil { | ||
t.Fatalf("Failed to delete schema migrations table: %v", err) | ||
} | ||
// Run migrations again | ||
if err := db.RunDBMigrations(dbConfig); err != nil { | ||
t.Errorf("Error running migrations: %v", err) | ||
} | ||
}) | ||
} | ||
|
||
} |