Skip to content

Commit

Permalink
Fix typo: SchemaDatabaseDNS -> SchemaDatabaseDSN
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelosalloum committed Apr 23, 2024
1 parent 7cf34a7 commit b51454d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
14 changes: 7 additions & 7 deletions cmd/db/schema_migration_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
type SchemaMigrationManager struct {
MigrationRouter migrations.MigrationRouter
SchemaName string
SchemaDatabaseDNS string
SchemaDatabaseDSN string
schemaDBConnectionPool db.DBConnectionPool
}

Expand All @@ -30,7 +30,7 @@ func (m *SchemaMigrationManager) Close() error {
func NewSchemaMigrationManager(
migrationRouter migrations.MigrationRouter,
schemaName string,
schemaDatabaseDNS string,
schemaDatabaseDSN string,
) (*SchemaMigrationManager, error) {
if utils.IsEmpty(migrationRouter) {
return nil, fmt.Errorf("migrationRouter cannot be empty")
Expand All @@ -40,19 +40,19 @@ func NewSchemaMigrationManager(
return nil, fmt.Errorf("schemaName cannot be empty")
}

if strings.TrimSpace(schemaDatabaseDNS) == "" {
return nil, fmt.Errorf("schemaDatabaseDNS cannot be empty")
if strings.TrimSpace(schemaDatabaseDSN) == "" {
return nil, fmt.Errorf("schemaDatabaseDSN cannot be empty")
}

schemaDBConnectionPool, err := db.OpenDBConnectionPool(schemaDatabaseDNS)
schemaDBConnectionPool, err := db.OpenDBConnectionPool(schemaDatabaseDSN)
if err != nil {
return nil, fmt.Errorf("opening the database connection pool for the '%s' schema: %w", schemaName, err)
}

return &SchemaMigrationManager{
MigrationRouter: migrationRouter,
SchemaName: schemaName,
SchemaDatabaseDNS: schemaDatabaseDNS,
SchemaDatabaseDSN: schemaDatabaseDSN,
schemaDBConnectionPool: schemaDBConnectionPool,
}, nil
}
Expand Down Expand Up @@ -97,7 +97,7 @@ func (m *SchemaMigrationManager) deleteSchemaIfNeeded(ctx context.Context) error
}

func (m *SchemaMigrationManager) executeMigrations(ctx context.Context, dir migrate.MigrationDirection, count int) error {
err := ExecuteMigrations(ctx, m.SchemaDatabaseDNS, dir, count, m.MigrationRouter)
err := ExecuteMigrations(ctx, m.SchemaDatabaseDSN, dir, count, m.MigrationRouter)
if err != nil {
return fmt.Errorf("executing migrations for router %s: %w", m.MigrationRouter.TableName, err)
}
Expand Down
26 changes: 13 additions & 13 deletions cmd/db/schema_migration_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ func Test_NewSchemaMigrationManager(t *testing.T) {
assert.EqualError(t, err, "schemaName cannot be empty")
})

t.Run("schemaDatabaseDNS cannot be empty", func(t *testing.T) {
t.Run("schemaDatabaseDSN cannot be empty", func(t *testing.T) {
manager, err := NewSchemaMigrationManager(migrations.SDPMigrationRouter, tc.SchemaName, "")
assert.Nil(t, manager)
assert.EqualError(t, err, "schemaDatabaseDNS cannot be empty")
assert.EqualError(t, err, "schemaDatabaseDSN cannot be empty")
})

t.Run("🎉 successfully constructs the instance", func(t *testing.T) {
schemaDatabaseDNS, err := tc.getDatabaseDNS(dbt.DSN)
schemaDatabaseDSN, err := tc.getDatabaseDNS(dbt.DSN)
require.NoError(t, err)

manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDNS)
manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDSN)
require.NoError(t, err)
defer manager.Close()
assert.NotNil(t, manager.schemaDBConnectionPool)
wantManager := &SchemaMigrationManager{
MigrationRouter: tc.MigrationRouter,
SchemaName: tc.SchemaName,
SchemaDatabaseDNS: schemaDatabaseDNS,
SchemaDatabaseDSN: schemaDatabaseDSN,
schemaDBConnectionPool: manager.schemaDBConnectionPool,
}
assert.Equal(t, wantManager, manager)
Expand All @@ -85,10 +85,10 @@ func Test_SchemaMigrationManager_createSchemaIfNeeded(t *testing.T) {

ctx := context.Background()

schemaDatabaseDNS, err := tc.getDatabaseDNS(dbt.DSN)
schemaDatabaseDSN, err := tc.getDatabaseDNS(dbt.DSN)
require.NoError(t, err)

manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDNS)
manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDSN)
require.NoError(t, err)
defer manager.Close()

Expand Down Expand Up @@ -130,10 +130,10 @@ func Test_SchemaMigrationManager_deleteSchemaIfNeeded(t *testing.T) {

ctx := context.Background()

schemaDatabaseDNS, err := tc.getDatabaseDNS(dbt.DSN)
schemaDatabaseDSN, err := tc.getDatabaseDNS(dbt.DSN)
require.NoError(t, err)

manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDNS)
manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDSN)
require.NoError(t, err)
defer manager.Close()

Expand Down Expand Up @@ -182,10 +182,10 @@ func Test_SchemaMigrationManager_executeMigrations(t *testing.T) {

ctx := context.Background()

schemaDatabaseDNS, err := tc.getDatabaseDNS(dbt.DSN)
schemaDatabaseDSN, err := tc.getDatabaseDNS(dbt.DSN)
require.NoError(t, err)

manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDNS)
manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDSN)
require.NoError(t, err)
defer manager.Close()

Expand Down Expand Up @@ -250,10 +250,10 @@ func Test_SchemaMigrationManager_OrchestrateSchemaMigrations(t *testing.T) {

ctx := context.Background()

schemaDatabaseDNS, err := tc.getDatabaseDNS(dbt.DSN)
schemaDatabaseDSN, err := tc.getDatabaseDNS(dbt.DSN)
require.NoError(t, err)

manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDNS)
manager, err := NewSchemaMigrationManager(tc.MigrationRouter, tc.SchemaName, schemaDatabaseDSN)
require.NoError(t, err)
defer manager.Close()

Expand Down

0 comments on commit b51454d

Please sign in to comment.