Skip to content

Commit cb16748

Browse files
committed
fix: use the default database name in the pg_restore command
1 parent e01f970 commit cb16748

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pkg/retrieval/engine/postgres/logical/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func (d *DumpJob) buildLogicalDumpCommand() []string {
432432
}
433433

434434
func (d *DumpJob) buildLogicalRestoreCommand() []string {
435-
restoreCmd := []string{"|", "pg_restore", "--username", d.globalCfg.Database.User(), "--create", "--dbname", d.globalCfg.Database.Name(),
435+
restoreCmd := []string{"|", "pg_restore", "--username", d.globalCfg.Database.User(), "--create", "--dbname", defaults.DBName,
436436
"--no-privileges", "--no-owner"}
437437

438438
if d.Restore.ForceInit {

pkg/retrieval/engine/postgres/logical/restore.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/dbmarker"
2626
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/engine/postgres/tools"
2727
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/engine/postgres/tools/cont"
28+
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/engine/postgres/tools/defaults"
2829
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/engine/postgres/tools/health"
2930
"gitlab.com/postgres-ai/database-lab/v2/pkg/retrieval/options"
3031
"gitlab.com/postgres-ai/database-lab/v2/pkg/services/provision/resources"
@@ -297,7 +298,7 @@ func (r *RestoreJob) updateDataStateAt() {
297298
}
298299

299300
func (r *RestoreJob) buildLogicalRestoreCommand() []string {
300-
restoreCmd := []string{"pg_restore", "--username", r.globalCfg.Database.User(), "--dbname", r.globalCfg.Database.Name(), "--create",
301+
restoreCmd := []string{"pg_restore", "--username", r.globalCfg.Database.User(), "--dbname", defaults.DBName, "--create",
301302
"--no-privileges", "--no-owner"}
302303

303304
if r.ForceInit {

pkg/retrieval/engine/postgres/logical/restore_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ func TestRestoreCommandBuilding(t *testing.T) {
3333
ForceInit: false,
3434
DumpLocation: "/tmp/db.dump",
3535
},
36-
Command: []string{"pg_restore", "--username", "john", "--dbname", "testdb", "--create", "--no-privileges", "--no-owner", "--jobs", "1", "/tmp/db.dump"},
36+
Command: []string{"pg_restore", "--username", "john", "--dbname", "postgres", "--create", "--no-privileges", "--no-owner", "--jobs", "1", "/tmp/db.dump"},
3737
},
3838
{
3939
CopyOptions: RestoreOptions{
4040
ParallelJobs: 4,
4141
ForceInit: true,
4242
},
43-
Command: []string{"pg_restore", "--username", "john", "--dbname", "testdb", "--create", "--no-privileges", "--no-owner", "--clean", "--if-exists", "--jobs", "4", ""},
43+
Command: []string{"pg_restore", "--username", "john", "--dbname", "postgres", "--create", "--no-privileges", "--no-owner", "--clean", "--if-exists", "--jobs", "4", ""},
4444
},
4545
{
4646
CopyOptions: RestoreOptions{
@@ -49,7 +49,7 @@ func TestRestoreCommandBuilding(t *testing.T) {
4949
Partial: Partial{Tables: []string{"test", "users"}},
5050
DumpLocation: "/tmp/db.dump",
5151
},
52-
Command: []string{"pg_restore", "--username", "john", "--dbname", "testdb", "--create", "--no-privileges", "--no-owner", "--jobs", "1", "--table", "test", "--table", "users", "/tmp/db.dump"},
52+
Command: []string{"pg_restore", "--username", "john", "--dbname", "postgres", "--create", "--no-privileges", "--no-owner", "--jobs", "1", "--table", "test", "--table", "users", "/tmp/db.dump"},
5353
},
5454
}
5555

0 commit comments

Comments
 (0)