diff --git a/cmd/auth.go b/cmd/auth.go index 147662701..fcbbb4625 100644 --- a/cmd/auth.go +++ b/cmd/auth.go @@ -10,8 +10,8 @@ import ( "github.com/stellar/go/support/config" "github.com/stellar/go/support/log" cmdUtils "github.com/stellar/stellar-disbursement-platform-backend/cmd/utils" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" di "github.com/stellar/stellar-disbursement-platform-backend/internal/dependencyinjection" "github.com/stellar/stellar-disbursement-platform-backend/internal/htmltemplate" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" diff --git a/cmd/auth_test.go b/cmd/auth_test.go index ac68219f9..e803b5e07 100644 --- a/cmd/auth_test.go +++ b/cmd/auth_test.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/cmd/channel_accounts_test.go b/cmd/channel_accounts_test.go index 7567ed42d..3e3fa3718 100644 --- a/cmd/channel_accounts_test.go +++ b/cmd/channel_accounts_test.go @@ -14,8 +14,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" txSubSvc "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/services" ) diff --git a/cmd/db.go b/cmd/db.go index 80f3aa4ca..99bdb7800 100644 --- a/cmd/db.go +++ b/cmd/db.go @@ -7,7 +7,8 @@ import ( migrate "github.com/rubenv/sql-migrate" "github.com/spf13/cobra" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" + migrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/sdp-migrations" "github.com/stellar/stellar-disbursement-platform-backend/internal/services" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/cli" @@ -127,7 +128,7 @@ func (c *DatabaseCommand) Command() *cobra.Command { } func (c *DatabaseCommand) migrate(dir migrate.MigrationDirection, count int) error { - numMigrationsRun, err := db.Migrate(globalOptions.databaseURL, dir, count) + numMigrationsRun, err := db.Migrate(globalOptions.databaseURL, dir, count, migrations.FS, db.StellarAuthMigrationsTableName) if err != nil { return fmt.Errorf("migrating database: %w", err) } diff --git a/cmd/db_test.go b/cmd/db_test.go index 24d084491..d462779a3 100644 --- a/cmd/db_test.go +++ b/cmd/db_test.go @@ -9,9 +9,9 @@ import ( "github.com/stellar/go/keypair" "github.com/stellar/go/network" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/services" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" diff --git a/cmd/integration_tests_test.go b/cmd/integration_tests_test.go index 2e6cc965a..1747bd467 100644 --- a/cmd/integration_tests_test.go +++ b/cmd/integration_tests_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/spf13/cobra" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/integrationtests" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/cmd/serve.go b/cmd/serve.go index 729e2a116..c040a1e24 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -6,10 +6,10 @@ import ( "go/types" cmdUtils "github.com/stellar/stellar-disbursement-platform-backend/cmd/utils" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" di "github.com/stellar/stellar-disbursement-platform-backend/internal/dependencyinjection" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/scheduler" diff --git a/cmd/serve_test.go b/cmd/serve_test.go index be9d2872c..51dfeca3d 100644 --- a/cmd/serve_test.go +++ b/cmd/serve_test.go @@ -9,9 +9,9 @@ import ( "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/network" cmdUtils "github.com/stellar/stellar-disbursement-platform-backend/cmd/utils" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" di "github.com/stellar/stellar-disbursement-platform-backend/internal/dependencyinjection" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" diff --git a/internal/db/db.go b/db/db.go similarity index 88% rename from internal/db/db.go rename to db/db.go index 0cf93d234..3645fd2ff 100644 --- a/internal/db/db.go +++ b/db/db.go @@ -7,6 +7,7 @@ import ( "time" "github.com/jmoiron/sqlx" + _ "github.com/lib/pq" "github.com/stellar/go/support/log" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" ) @@ -16,6 +17,13 @@ const ( MaxOpenDBConns = 30 ) +// DBConnectionPoolFromSqlDB returns a new DBConnectionPool wrapper for a PRE-EXISTING *sql.DB. The driverName of the +// original database is required for named query support. ATTENTION: this will not start a new connection pool, just +// create a wrap aroung the pre-existing connection pool. +func DBConnectionPoolFromSqlDB(sqlDB *sql.DB, driverName string) DBConnectionPool { + return &DBConnectionPoolImplementation{DB: sqlx.NewDb(sqlDB, driverName)} +} + // DBConnectionPool is an interface that wraps the sqlx.DB structs methods and includes the RunInTransaction helper. type DBConnectionPool interface { SQLExecuter @@ -24,11 +32,13 @@ type DBConnectionPool interface { Ping() error SqlDB() *sql.DB SqlxDB() *sqlx.DB + DSN() string } // DBConnectionPoolImplementation is a wrapper around sqlx.DB that implements DBConnectionPool. type DBConnectionPoolImplementation struct { *sqlx.DB + dataSourceName string } func (db *DBConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (DBTransaction, error) { @@ -43,6 +53,10 @@ func (db *DBConnectionPoolImplementation) SqlxDB() *sqlx.DB { return db.DB } +func (db *DBConnectionPoolImplementation) DSN() string { + return db.dataSourceName +} + // RunInTransactionWithResult runs the given atomic function in an atomic database transaction and returns a result and // an error. Boilerplate code for database transactions. func RunInTransactionWithResult[T any](ctx context.Context, dbConnectionPool DBConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx DBTransaction) (T, error)) (result T, err error) { @@ -141,7 +155,7 @@ func OpenDBConnectionPool(dataSourceName string) (DBConnectionPool, error) { return nil, fmt.Errorf("error pinging app DB connection pool: %w", err) } - return &DBConnectionPoolImplementation{DB: sqlxDB}, nil + return &DBConnectionPoolImplementation{DB: sqlxDB, dataSourceName: dataSourceName}, nil } // OpenDBConnectionPoolWithMetrics opens a new database connection pool with the monitor service. It returns an error if it can't connect to the database. diff --git a/internal/db/db_connection_pool_with_metrics.go b/db/db_connection_pool_with_metrics.go similarity index 94% rename from internal/db/db_connection_pool_with_metrics.go rename to db/db_connection_pool_with_metrics.go index 6782889cb..97295aed7 100644 --- a/internal/db/db_connection_pool_with_metrics.go +++ b/db/db_connection_pool_with_metrics.go @@ -54,3 +54,7 @@ func (dbc *DBConnectionPoolWithMetrics) SqlDB() *sql.DB { func (dbc *DBConnectionPoolWithMetrics) SqlxDB() *sqlx.DB { return dbc.dbConnectionPool.SqlxDB() } + +func (dbc *DBConnectionPoolWithMetrics) DSN() string { + return dbc.dbConnectionPool.DSN() +} diff --git a/internal/db/db_connection_pool_with_metrics_test.go b/db/db_connection_pool_with_metrics_test.go similarity index 96% rename from internal/db/db_connection_pool_with_metrics_test.go rename to db/db_connection_pool_with_metrics_test.go index 161563d9e..9214f2d14 100644 --- a/internal/db/db_connection_pool_with_metrics_test.go +++ b/db/db_connection_pool_with_metrics_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/jmoiron/sqlx" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/stellar-auth/internal/db/db_test.go b/db/db_test.go similarity index 100% rename from stellar-auth/internal/db/db_test.go rename to db/db_test.go diff --git a/internal/db/db_transaction_with_metrics.go b/db/db_transaction_with_metrics.go similarity index 100% rename from internal/db/db_transaction_with_metrics.go rename to db/db_transaction_with_metrics.go diff --git a/internal/db/db_transaction_with_metrics_test.go b/db/db_transaction_with_metrics_test.go similarity index 94% rename from internal/db/db_transaction_with_metrics_test.go rename to db/db_transaction_with_metrics_test.go index c892b65c4..b2ad8d469 100644 --- a/internal/db/db_transaction_with_metrics_test.go +++ b/db/db_transaction_with_metrics_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stretchr/testify/require" ) diff --git a/db/dbtest/dbtest.go b/db/dbtest/dbtest.go new file mode 100644 index 000000000..53dc15dec --- /dev/null +++ b/db/dbtest/dbtest.go @@ -0,0 +1,96 @@ +package dbtest + +import ( + "net/http" + "testing" + + migrate "github.com/rubenv/sql-migrate" + "github.com/stellar/go/support/db/dbtest" + "github.com/stellar/go/support/db/schema" + authmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/auth-migrations" + sdpmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/sdp-migrations" + tenantmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/tenant-migrations" +) + +func OpenWithoutMigrations(t *testing.T) *dbtest.DB { + db := dbtest.Postgres(t) + return db +} + +func Open(t *testing.T) *dbtest.DB { + db := OpenWithoutMigrations(t) + + conn := db.Open() + defer conn.Close() + + // Tenant migrations + ms := migrate.MigrationSet{TableName: "migrations"} + migrateDirection := migrate.Up + m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(tenantmigrations.FS)} + _, err := ms.ExecMax(conn.DB, "postgres", m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + + // SDP migrations + ms = migrate.MigrationSet{} + m = migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(sdpmigrations.FS)} + _, err = ms.ExecMax(conn.DB, "postgres", m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + + // Auth migrations + ms = migrate.MigrationSet{TableName: "auth_migrations"} + m = migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(authmigrations.FS)} + _, err = ms.ExecMax(conn.DB, "postgres", m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + return db +} + +func OpenWithTenantMigrationsOnly(t *testing.T) *dbtest.DB { + db := OpenWithoutMigrations(t) + + conn := db.Open() + defer conn.Close() + + migrateDirection := schema.MigrateUp + m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(tenantmigrations.FS)} + _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + return db +} + +func OpenWithSDPMigrationsOnly(t *testing.T) *dbtest.DB { + db := OpenWithoutMigrations(t) + + conn := db.Open() + defer conn.Close() + + migrateDirection := schema.MigrateUp + m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(sdpmigrations.FS)} + _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + return db +} + +func OpenWithAuthMigrationsOnly(t *testing.T) *dbtest.DB { + db := OpenWithoutMigrations(t) + + conn := db.Open() + defer conn.Close() + + migrateDirection := schema.MigrateUp + m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(authmigrations.FS)} + _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) + if err != nil { + t.Fatal(err) + } + return db +} diff --git a/db/dbtest/dbtest_test.go b/db/dbtest/dbtest_test.go new file mode 100644 index 000000000..c7ea19a4d --- /dev/null +++ b/db/dbtest/dbtest_test.go @@ -0,0 +1,33 @@ +package dbtest + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestOpen(t *testing.T) { + db := Open(t) + defer db.Close() + + session := db.Open() + defer session.Close() + + count := 0 + + // Tenant migrations + err := session.Get(&count, `SELECT COUNT(*) FROM migrations`) + require.NoError(t, err) + assert.Greater(t, count, 0) + + // SDP migrations + err = session.Get(&count, `SELECT COUNT(*) FROM gorp_migrations`) + require.NoError(t, err) + assert.Greater(t, count, 0) + + // Auth Migrations + err = session.Get(&count, `SELECT COUNT(*) FROM auth_migrations`) + require.NoError(t, err) + assert.Greater(t, count, 0) +} diff --git a/stellar-multitenant/internal/db/migrate.go b/db/migrate.go similarity index 64% rename from stellar-multitenant/internal/db/migrate.go rename to db/migrate.go index 936bff476..9335ad68a 100644 --- a/stellar-multitenant/internal/db/migrate.go +++ b/db/migrate.go @@ -1,18 +1,23 @@ package db import ( + "embed" "fmt" "net/http" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/migrations" - migrate "github.com/rubenv/sql-migrate" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" ) -const StellarMultitenantMigrationsTableName = "migrations" +type MigrationTableName string + +const ( + StellarMultitenantMigrationsTableName = "migrations" + StellarSDPMigrationsTableName = "gorp_migrations" + StellarAuthMigrationsTableName = "auth_migrations" +) -func Migrate(dbURL string, dir migrate.MigrationDirection, count int) (int, error) { +func Migrate(dbURL string, dir migrate.MigrationDirection, count int, migrationFiles embed.FS, tableName MigrationTableName) (int, error) { dbConnectionPool, err := OpenDBConnectionPool(dbURL) if err != nil { return 0, fmt.Errorf("database URL '%s': %w", utils.TruncateString(dbURL, len(dbURL)/4), err) @@ -20,9 +25,9 @@ func Migrate(dbURL string, dir migrate.MigrationDirection, count int) (int, erro defer dbConnectionPool.Close() ms := migrate.MigrationSet{ - TableName: StellarMultitenantMigrationsTableName, + TableName: string(tableName), } - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} + m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrationFiles)} return ms.ExecMax(dbConnectionPool.SqlDB(), dbConnectionPool.DriverName(), m, dir, count) } diff --git a/db/migrate_test.go b/db/migrate_test.go new file mode 100644 index 000000000..f3ab1d3f1 --- /dev/null +++ b/db/migrate_test.go @@ -0,0 +1,253 @@ +package db + +import ( + "context" + "fmt" + "io/fs" + "testing" + + migrate "github.com/rubenv/sql-migrate" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" + authmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/auth-migrations" + sdpmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/sdp-migrations" + tenantmigrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/tenant-migrations" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestMigrate_upApplyOne_SDP_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 1, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + assert.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarSDPMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{"2023-01-20.0-initial.sql"} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_downApplyOne_SDP_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 2, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 2, n) + + n, err = Migrate(db.DSN, migrate.Down, 1, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarSDPMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{"2023-01-20.0-initial.sql"} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_upAndDownAllTheWayTwice_SDP_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + // Get number of files in the migrations directory: + var count int + err = fs.WalkDir(sdpmigrations.FS, ".", func(path string, d fs.DirEntry, err error) error { + require.NoError(t, err) + if !d.IsDir() { + count++ + } + return nil + }) + require.NoError(t, err) + + n, err := Migrate(db.DSN, migrate.Up, count, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Up, count, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, sdpmigrations.FS, StellarSDPMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) +} + +func TestMigrate_upApplyOne_Tenant_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 1, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + assert.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarMultitenantMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{"2023-10-16.0.add-tenants-table.sql"} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_downApplyOne_Tenant_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 2, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 1, n) + + n, err = Migrate(db.DSN, migrate.Down, 1, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarMultitenantMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_upAndDownAllTheWayTwice_Tenant_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + // Get number of files in the migrations directory: + var count int + err = fs.WalkDir(tenantmigrations.FS, ".", func(path string, d fs.DirEntry, err error) error { + require.NoError(t, err) + if !d.IsDir() { + count++ + } + return nil + }) + require.NoError(t, err) + + n, err := Migrate(db.DSN, migrate.Up, count, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Up, count, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, tenantmigrations.FS, StellarMultitenantMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) +} + +func TestMigrate_upApplyOne_Auth_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 1, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + assert.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarAuthMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{"2023-02-09.0.add-users-table.sql"} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_downApplyOne_Auth_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + ctx := context.Background() + + n, err := Migrate(db.DSN, migrate.Up, 2, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 2, n) + + n, err = Migrate(db.DSN, migrate.Down, 1, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, 1, n) + + ids := []string{} + err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarAuthMigrationsTableName)) + require.NoError(t, err) + wantIDs := []string{"2023-02-09.0.add-users-table.sql"} + assert.Equal(t, wantIDs, ids) +} + +func TestMigrate_upAndDownAllTheWayTwice_Auth_migrations(t *testing.T) { + db := dbtest.OpenWithoutMigrations(t) + defer db.Close() + dbConnectionPool, err := OpenDBConnectionPool(db.DSN) + require.NoError(t, err) + defer dbConnectionPool.Close() + + // Get number of files in the migrations directory: + var count int + err = fs.WalkDir(authmigrations.FS, ".", func(path string, d fs.DirEntry, err error) error { + require.NoError(t, err) + if !d.IsDir() { + count++ + } + return nil + }) + require.NoError(t, err) + + n, err := Migrate(db.DSN, migrate.Up, count, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Up, count, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) + + n, err = Migrate(db.DSN, migrate.Down, count, authmigrations.FS, StellarAuthMigrationsTableName) + require.NoError(t, err) + require.Equal(t, count, n) +} diff --git a/stellar-auth/internal/db/migrations/2023-02-09.0.add-users-table.sql b/db/migrations/auth-migrations/2023-02-09.0.add-users-table.sql similarity index 77% rename from stellar-auth/internal/db/migrations/2023-02-09.0.add-users-table.sql rename to db/migrations/auth-migrations/2023-02-09.0.add-users-table.sql index 981f420da..89192cfb1 100644 --- a/stellar-auth/internal/db/migrations/2023-02-09.0.add-users-table.sql +++ b/db/migrations/auth-migrations/2023-02-09.0.add-users-table.sql @@ -3,8 +3,8 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE - public.auth_users ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), + auth_users ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), username text NOT NULL, encrypted_password text NOT NULL, email text NOT NULL, @@ -18,4 +18,4 @@ CREATE TABLE -- +migrate Down -DROP TABLE public.auth_users; +DROP TABLE auth_users; diff --git a/stellar-auth/internal/db/migrations/2023-03-07.0.add-password-reset-table.sql b/db/migrations/auth-migrations/2023-03-07.0.add-password-reset-table.sql similarity index 93% rename from stellar-auth/internal/db/migrations/2023-03-07.0.add-password-reset-table.sql rename to db/migrations/auth-migrations/2023-03-07.0.add-password-reset-table.sql index 6e3b8df35..ee790ac91 100644 --- a/stellar-auth/internal/db/migrations/2023-03-07.0.add-password-reset-table.sql +++ b/db/migrations/auth-migrations/2023-03-07.0.add-password-reset-table.sql @@ -1,7 +1,7 @@ -- +migrate Up CREATE TABLE - public.auth_user_password_reset ( + auth_user_password_reset ( token text NOT NULL UNIQUE, auth_user_id VARCHAR(36) NOT NULL, is_valid boolean NOT NULL DEFAULT true, @@ -41,4 +41,4 @@ EXECUTE PROCEDURE auth_user_password_reset_before_insert(); DROP TRIGGER auth_user_password_reset_before_insert_trigger ON auth_user_password_reset; DROP FUNCTION IF EXISTS auth_user_password_reset_before_insert; DROP INDEX IF EXISTS unique_user_valid_token; -DROP TABLE public.auth_user_password_reset; +DROP TABLE auth_user_password_reset; diff --git a/stellar-auth/internal/db/migrations/2023-03-10.0.alter-users-table-add-roles-column.sql b/db/migrations/auth-migrations/2023-03-10.0.alter-users-table-add-roles-column.sql similarity index 100% rename from stellar-auth/internal/db/migrations/2023-03-10.0.alter-users-table-add-roles-column.sql rename to db/migrations/auth-migrations/2023-03-10.0.alter-users-table-add-roles-column.sql diff --git a/db/migrations/auth-migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql b/db/migrations/auth-migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql new file mode 100644 index 000000000..3247e64ad --- /dev/null +++ b/db/migrations/auth-migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql @@ -0,0 +1,7 @@ +-- +migrate Up + +ALTER TABLE auth_users ADD COLUMN is_active boolean DEFAULT true; + +-- +migrate Down + +ALTER TABLE auth_users DROP COLUMN is_active; diff --git a/stellar-auth/internal/db/migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql b/db/migrations/auth-migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql similarity index 64% rename from stellar-auth/internal/db/migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql rename to db/migrations/auth-migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql index c4e661740..bc231c516 100644 --- a/stellar-auth/internal/db/migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql +++ b/db/migrations/auth-migrations/2023-03-28.0.alter-users-table-add-new-columns-and-drop-username-column.sql @@ -1,16 +1,16 @@ -- +migrate Up -ALTER TABLE public.auth_users +ALTER TABLE auth_users ADD COLUMN first_name VARCHAR(128) NOT NULL DEFAULT '', ADD COLUMN last_name VARCHAR(128) NOT NULL DEFAULT ''; -ALTER TABLE public.auth_users DROP COLUMN username; +ALTER TABLE auth_users DROP COLUMN username; -- +migrate Down -ALTER TABLE public.auth_users +ALTER TABLE auth_users DROP COLUMN first_name, DROP COLUMN last_name; -ALTER TABLE public.auth_users +ALTER TABLE auth_users ADD COLUMN username VARCHAR(128) UNIQUE; diff --git a/stellar-auth/internal/db/migrations/2023-07-20.0-create-auth_user_mfa_codes_table.sql b/db/migrations/auth-migrations/2023-07-20.0-create-auth_user_mfa_codes_table.sql similarity index 100% rename from stellar-auth/internal/db/migrations/2023-07-20.0-create-auth_user_mfa_codes_table.sql rename to db/migrations/auth-migrations/2023-07-20.0-create-auth_user_mfa_codes_table.sql diff --git a/internal/db/migrations/main.go b/db/migrations/auth-migrations/main.go similarity index 100% rename from internal/db/migrations/main.go rename to db/migrations/auth-migrations/main.go diff --git a/internal/db/migrations/2023-01-20.0-initial.sql b/db/migrations/sdp-migrations/2023-01-20.0-initial.sql similarity index 100% rename from internal/db/migrations/2023-01-20.0-initial.sql rename to db/migrations/sdp-migrations/2023-01-20.0-initial.sql diff --git a/db/migrations/sdp-migrations/2023-01-23.0-dump-from-sdp-v1.sql b/db/migrations/sdp-migrations/2023-01-23.0-dump-from-sdp-v1.sql new file mode 100644 index 000000000..76826694b --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-23.0-dump-from-sdp-v1.sql @@ -0,0 +1,372 @@ +-- This migration file is meant to reproduce the database schema from the SDP v1, so we can support users that +-- are on SDP v1 to migrate to SDP v2. + +-- +migrate Up + + +------------------------------------------------- START DJANGO MODELS ------------------------------------------------- + +-- TABLE: auth_group +CREATE TABLE IF NOT EXISTS auth_group ( + id SERIAL PRIMARY KEY, + name character varying(150) NOT NULL +); +CREATE UNIQUE INDEX IF NOT EXISTS auth_group_name_a6ea08ec_like ON auth_group (name varchar_pattern_ops); +ALTER INDEX auth_group_name_a6ea08ec_like RENAME TO auth_group_name_idx; + + +-- TABLE: django_content_type +CREATE TABLE IF NOT EXISTS django_content_type ( + id SERIAL PRIMARY KEY, + app_label character varying(100) NOT NULL, + model character varying(100) NOT NULL, + UNIQUE (app_label, model) +); + +INSERT INTO django_content_type VALUES (1, 'admin', 'logentry') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (2, 'auth', 'permission') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (3, 'auth', 'group') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (4, 'auth', 'user') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (5, 'contenttypes', 'contenttype') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (6, 'sessions', 'session') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (7, 'payments', 'account') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (8, 'payments', 'disbursement') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (9, 'payments', 'heartbeat') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (10, 'payments', 'payment') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (11, 'payments', 'activation') ON CONFLICT (id) DO NOTHING; +INSERT INTO django_content_type VALUES (12, 'payments', 'withdrawal') ON CONFLICT (id) DO NOTHING; + + +-- TABLE: auth_permission +CREATE TABLE IF NOT EXISTS auth_permission ( + id SERIAL PRIMARY KEY, + name character varying(255) NOT NULL, + content_type_id integer NOT NULL REFERENCES django_content_type (id) DEFERRABLE INITIALLY DEFERRED, + codename character varying(100) NOT NULL, + UNIQUE (content_type_id, codename) +); +CREATE INDEX IF NOT EXISTS auth_permission_content_type_id_2f476e4b ON auth_permission USING btree (content_type_id); +ALTER INDEX auth_permission_content_type_id_2f476e4b RENAME TO auth_permission_content_type_id_idx; + +INSERT INTO auth_permission VALUES (1, 'Can add log entry', 1, 'add_logentry') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (2, 'Can change log entry', 1, 'change_logentry') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (3, 'Can delete log entry', 1, 'delete_logentry') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (4, 'Can view log entry', 1, 'view_logentry') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (5, 'Can add permission', 2, 'add_permission') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (6, 'Can change permission', 2, 'change_permission') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (7, 'Can delete permission', 2, 'delete_permission') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (8, 'Can view permission', 2, 'view_permission') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (9, 'Can add group', 3, 'add_group') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (10, 'Can change group', 3, 'change_group') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (11, 'Can delete group', 3, 'delete_group') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (12, 'Can view group', 3, 'view_group') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (13, 'Can add user', 4, 'add_user') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (14, 'Can change user', 4, 'change_user') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (15, 'Can delete user', 4, 'delete_user') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (16, 'Can view user', 4, 'view_user') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (17, 'Can add content type', 5, 'add_contenttype') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (18, 'Can change content type', 5, 'change_contenttype') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (19, 'Can delete content type', 5, 'delete_contenttype') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (20, 'Can view content type', 5, 'view_contenttype') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (21, 'Can add session', 6, 'add_session') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (22, 'Can change session', 6, 'change_session') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (23, 'Can delete session', 6, 'delete_session') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (24, 'Can view session', 6, 'view_session') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (25, 'Can add account', 7, 'add_account') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (26, 'Can change account', 7, 'change_account') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (27, 'Can delete account', 7, 'delete_account') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (28, 'Can view account', 7, 'view_account') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (29, 'Can add disbursement', 8, 'add_disbursement') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (30, 'Can change disbursement', 8, 'change_disbursement') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (31, 'Can delete disbursement', 8, 'delete_disbursement') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (32, 'Can view disbursement', 8, 'view_disbursement') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (33, 'Can add heart beat', 9, 'add_heartbeat') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (34, 'Can change heart beat', 9, 'change_heartbeat') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (35, 'Can delete heart beat', 9, 'delete_heartbeat') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (36, 'Can view heart beat', 9, 'view_heartbeat') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (37, 'Can add payment', 10, 'add_payment') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (38, 'Can change payment', 10, 'change_payment') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (39, 'Can delete payment', 10, 'delete_payment') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (40, 'Can view payment', 10, 'view_payment') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (41, 'Can add activation', 11, 'add_activation') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (42, 'Can change activation', 11, 'change_activation') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (43, 'Can delete activation', 11, 'delete_activation') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (44, 'Can view activation', 11, 'view_activation') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (45, 'Can add withdrawal', 12, 'add_withdrawal') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (46, 'Can change withdrawal', 12, 'change_withdrawal') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (47, 'Can delete withdrawal', 12, 'delete_withdrawal') ON CONFLICT DO NOTHING; +INSERT INTO auth_permission VALUES (48, 'Can view withdrawal', 12, 'view_withdrawal') ON CONFLICT DO NOTHING; + + +-- TABLE: auth_group_permissions +CREATE TABLE IF NOT EXISTS auth_group_permissions ( + id BIGSERIAL PRIMARY KEY, + group_id integer NOT NULL REFERENCES auth_group (id) DEFERRABLE INITIALLY DEFERRED, + permission_id integer NOT NULL REFERENCES auth_permission (id) DEFERRABLE INITIALLY DEFERRED, + UNIQUE (group_id, permission_id) +); +CREATE INDEX IF NOT EXISTS auth_group_permissions_group_id_b120cbf9 ON auth_group_permissions USING btree (group_id); +ALTER INDEX auth_group_permissions_group_id_b120cbf9 RENAME TO auth_group_permissions_group_id_idx; + +CREATE INDEX IF NOT EXISTS auth_group_permissions_permission_id_84c5c92e ON auth_group_permissions USING btree (permission_id); +ALTER INDEX auth_group_permissions_permission_id_84c5c92e RENAME TO auth_group_permissions_permission_id_idx; + + +-- TABLE: auth_user +CREATE TABLE IF NOT EXISTS auth_user ( + id SERIAL PRIMARY KEY, + password character varying(128) NOT NULL, + last_login timestamp with time zone, + is_superuser boolean NOT NULL, + username character varying(150) NOT NULL, + first_name character varying(150) NOT NULL, + last_name character varying(150) NOT NULL, + email character varying(254) NOT NULL, + is_staff boolean NOT NULL, + is_active boolean NOT NULL, + date_joined timestamp with time zone NOT NULL, + UNIQUE (username) +); +CREATE INDEX IF NOT EXISTS auth_user_username_6821ab7c_like ON auth_user USING btree (username varchar_pattern_ops); +ALTER INDEX auth_user_username_6821ab7c_like RENAME TO auth_user_username_idx; + + +-- TABLE: auth_user_groups +CREATE TABLE IF NOT EXISTS auth_user_groups ( + id BIGSERIAL PRIMARY KEY, + user_id integer NOT NULL REFERENCES auth_user (id) DEFERRABLE INITIALLY DEFERRED, + group_id integer NOT NULL REFERENCES auth_group (id) DEFERRABLE INITIALLY DEFERRED, + UNIQUE (user_id, group_id) +); +CREATE INDEX IF NOT EXISTS auth_user_groups_group_id_97559544 ON auth_user_groups USING btree (group_id); +ALTER INDEX auth_user_groups_group_id_97559544 RENAME TO auth_user_groups_group_id_idx; + +CREATE INDEX IF NOT EXISTS auth_user_groups_user_id_6a12ed8b ON auth_user_groups USING btree (user_id); +ALTER INDEX auth_user_groups_user_id_6a12ed8b RENAME TO auth_user_groups_user_id_idx; + + +-- TABLE: auth_user_user_permissions +CREATE TABLE IF NOT EXISTS auth_user_user_permissions ( + id BIGSERIAL PRIMARY KEY, + user_id integer NOT NULL REFERENCES auth_user (id) DEFERRABLE INITIALLY DEFERRED, + permission_id integer NOT NULL REFERENCES auth_permission (id) DEFERRABLE INITIALLY DEFERRED, + UNIQUE (user_id, permission_id) +); +CREATE INDEX IF NOT EXISTS auth_user_user_permissions_permission_id_1fbb5f2c ON auth_user_user_permissions USING btree (permission_id); +ALTER INDEX auth_user_user_permissions_permission_id_1fbb5f2c RENAME TO auth_user_user_permissions_permission_id_idx; + +CREATE INDEX IF NOT EXISTS auth_user_user_permissions_user_id_a95ead1b ON auth_user_user_permissions USING btree (user_id); +ALTER INDEX auth_user_user_permissions_user_id_a95ead1b RENAME TO auth_user_user_permissions_user_id_idx; + + +-- TABLE: django_admin_log +CREATE TABLE IF NOT EXISTS django_admin_log ( + id SERIAL PRIMARY KEY, + action_time timestamp with time zone NOT NULL, + object_id text, + object_repr character varying(200) NOT NULL, + action_flag smallint NOT NULL, + change_message text NOT NULL, + content_type_id integer REFERENCES django_content_type(id) DEFERRABLE INITIALLY DEFERRED, + user_id integer NOT NULL REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED, + CONSTRAINT django_admin_log_action_flag_check CHECK ((action_flag >= 0)) +); +CREATE INDEX IF NOT EXISTS django_admin_log_content_type_id_c4bce8eb ON django_admin_log USING btree (content_type_id); +ALTER INDEX django_admin_log_content_type_id_c4bce8eb RENAME TO django_admin_log_content_type_id_idx; + +CREATE INDEX IF NOT EXISTS django_admin_log_user_id_c564eba6 ON django_admin_log USING btree (user_id); +ALTER INDEX django_admin_log_user_id_c564eba6 RENAME TO django_admin_log_user_id_idx; + + +-- TABLE: django_content_type +CREATE TABLE IF NOT EXISTS django_migrations ( + id BIGSERIAL PRIMARY KEY, + app character varying(255) NOT NULL, + name character varying(255) NOT NULL, + applied timestamp with time zone NOT NULL +); + +INSERT INTO django_migrations VALUES (1, 'contenttypes', '0001_initial', '2023-01-04 16:05:52.644099-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (2, 'auth', '0001_initial', '2023-01-04 16:05:52.711348-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (3, 'admin', '0001_initial', '2023-01-04 16:05:52.731795-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (4, 'admin', '0002_logentry_remove_auto_add', '2023-01-04 16:05:52.742003-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (5, 'admin', '0003_logentry_add_action_flag_choices', '2023-01-04 16:05:52.752853-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (6, 'contenttypes', '0002_remove_content_type_name', '2023-01-04 16:05:52.770614-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (7, 'auth', '0002_alter_permission_name_max_length', '2023-01-04 16:05:52.780492-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (8, 'auth', '0003_alter_user_email_max_length', '2023-01-04 16:05:52.791342-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (9, 'auth', '0004_alter_user_username_opts', '2023-01-04 16:05:52.802137-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (10, 'auth', '0005_alter_user_last_login_null', '2023-01-04 16:05:52.811967-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (11, 'auth', '0006_require_contenttypes_0002', '2023-01-04 16:05:52.814286-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (12, 'auth', '0007_alter_validators_add_error_messages', '2023-01-04 16:05:52.824612-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (13, 'auth', '0008_alter_user_username_max_length', '2023-01-04 16:05:52.835405-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (14, 'auth', '0009_alter_user_last_name_max_length', '2023-01-04 16:05:52.846608-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (15, 'auth', '0010_alter_group_name_max_length', '2023-01-04 16:05:52.858149-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (16, 'auth', '0011_update_proxy_permissions', '2023-01-04 16:05:52.867694-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (17, 'auth', '0012_alter_user_first_name_max_length', '2023-01-04 16:05:52.879894-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (18, 'payments', '0001_initial', '2023-01-04 16:05:52.947015-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (19, 'payments', '0002_remove_disbursement_requested_by_and_more', '2023-01-04 16:05:52.985496-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (20, 'payments', '0003_remove_disbursement_amount_and_more', '2023-01-04 16:05:53.040818-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (21, 'payments', '0004_account_link_last_sent_at', '2023-01-04 16:05:53.051175-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (22, 'payments', '0005_account_date_of_birth_account_email_and_more', '2023-01-04 16:05:53.079481-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (23, 'payments', '0006_payment_idempotency_key_alter_account_status', '2023-01-04 16:05:53.09219-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (24, 'payments', '0007_rename_hashed_date_of_birth_account_hashed_extra_info_and_more', '2023-01-04 16:05:53.108973-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (25, 'payments', '0008_activation', '2023-01-04 16:05:53.132048-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (26, 'payments', '0009_add_yubikey_validation_service', '2023-01-04 16:05:53.146663-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (27, 'payments', '0010_alter_account_phone_number', '2023-01-04 16:05:53.155158-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (28, 'payments', '0011_alter_payment_status', '2023-01-04 16:05:53.160529-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (29, 'payments', '0012_alter_payment_amount', '2023-01-04 16:05:53.173929-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (30, 'payments', '0013_withdrawal_alter_account_status_and_more', '2023-01-04 16:05:53.211413-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (31, 'payments', '0014_payment_withdrawal_amount_payment_withdrawal_status', '2023-01-04 16:05:53.228509-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (32, 'payments', '0015_rename_stellar_transaction_id_withdrawal_sep24_transaction_id', '2023-01-04 16:05:53.237819-08') ON CONFLICT DO NOTHING; +INSERT INTO django_migrations VALUES (33, 'sessions', '0001_initial', '2023-01-04 16:05:53.247677-08') ON CONFLICT DO NOTHING; + + +-- TABLE: django_session +CREATE TABLE IF NOT EXISTS django_session ( + session_key character varying(40) NOT NULL PRIMARY KEY, + session_data text NOT NULL, + expire_date timestamp with time zone NOT NULL +); +CREATE INDEX IF NOT EXISTS django_session_expire_date_a5c62663 ON django_session USING btree (expire_date); +ALTER INDEX django_session_expire_date_a5c62663 RENAME TO django_session_expire_date_idx; + +CREATE INDEX IF NOT EXISTS django_session_session_key_c0390e0f_like ON django_session USING btree (session_key varchar_pattern_ops); +ALTER INDEX django_session_session_key_c0390e0f_like RENAME TO django_session_session_key_idx; + +------------------------------------------------- FINISH DJANGO MODELS ------------------------------------------------- + + +------------------------------------------------- START OF SDP MODELS ------------------------------------------------- + +-- TABLE: receiver (previously known as payments_account) +CREATE TABLE IF NOT EXISTS payments_account ( + id character varying(64) NOT NULL PRIMARY KEY, + public_key character varying(128), + registered_at timestamp with time zone NOT NULL, + phone_number character varying(32) NOT NULL, + public_key_registered_at timestamp with time zone, + status character varying(32) NOT NULL, + link_last_sent_at timestamp with time zone, + email character varying(254), + email_registered_at timestamp with time zone, + hashed_extra_info character varying(64) NOT NULL, + hashed_phone_number character varying(64) NOT NULL, + extra_info character varying(64) NOT NULL, + UNIQUE (phone_number) +); +CREATE INDEX IF NOT EXISTS payments_ac_hashed__f9420c_idx ON payments_account USING btree (hashed_phone_number, hashed_extra_info); +ALTER INDEX payments_ac_hashed__f9420c_idx RENAME TO receiver_hashed_phone_and_hashed_extra_info_idx; + +CREATE INDEX IF NOT EXISTS payments_account_phone_number_221a9f17_like ON payments_account USING btree (phone_number varchar_pattern_ops); +ALTER INDEX payments_account_phone_number_221a9f17_like RENAME TO receiver_phone_number_idx; + +CREATE INDEX IF NOT EXISTS payments_ac_registe_104353_idx ON payments_account USING btree (registered_at DESC); +ALTER INDEX payments_ac_registe_104353_idx RENAME TO receiver_registered_at_idx; + +ALTER TABLE payments_account RENAME TO receivers; + + +-- TABLE: on_off_switch (previously known as payments_activation) +CREATE TABLE IF NOT EXISTS payments_activation ( + id BIGSERIAL PRIMARY KEY, + is_active boolean NOT NULL, + last_set_at timestamp with time zone NOT NULL DEFAULT NOW() +); +INSERT INTO payments_activation VALUES (1, true, NOW()) ON CONFLICT DO NOTHING; + +ALTER TABLE payments_activation RENAME TO on_off_switch; + + +-- TABLE: disbursement (previously known as payments_disbursement) +CREATE TABLE IF NOT EXISTS payments_disbursement ( + id character varying(64) NOT NULL PRIMARY KEY, + requested_at timestamp with time zone NOT NULL +); +CREATE INDEX IF NOT EXISTS payments_di_request_16523d_idx ON payments_disbursement USING btree (requested_at DESC); +ALTER INDEX payments_di_request_16523d_idx RENAME TO disbursement_request_16523d_idx; + +ALTER TABLE payments_disbursement RENAME TO disbursements; + + +-- TABLE: payments_semaphore (previously known as payments_heartbeat) +CREATE TABLE IF NOT EXISTS payments_heartbeat ( + id BIGSERIAL PRIMARY KEY, + name character varying(128) NOT NULL, + last_beat timestamp with time zone NOT NULL +); +ALTER TABLE payments_heartbeat RENAME TO payments_semaphore; + + +-- TABLE: payment (previously known as payments_payment) +CREATE TABLE IF NOT EXISTS payments_payment ( + id character varying(64) NOT NULL PRIMARY KEY, + stellar_transaction_id character varying(64), + custodial_payment_id text, + status character varying(32) NOT NULL, + status_message text, + requested_at timestamp with time zone NOT NULL, + started_at timestamp with time zone, + completed_at timestamp with time zone, + account_id character varying(64) NOT NULL REFERENCES receivers(id) DEFERRABLE INITIALLY DEFERRED, + disbursement_id character varying(64) NOT NULL REFERENCES disbursements(id) DEFERRABLE INITIALLY DEFERRED, + amount numeric(7,2) NOT NULL, + idempotency_key character varying(64) NOT NULL, + withdrawal_amount numeric(7,2) NOT NULL, + withdrawal_status character varying(32) NOT NULL +); +CREATE INDEX IF NOT EXISTS payments_pa_request_4ce797_idx ON payments_payment USING btree (requested_at DESC); +ALTER INDEX payments_pa_request_4ce797_idx RENAME TO payment_requested_at_idx; + +CREATE INDEX IF NOT EXISTS payments_payment_account_id_af225a32 ON payments_payment USING btree (account_id); +ALTER INDEX payments_payment_account_id_af225a32 RENAME TO payment_account_id_idx; + +CREATE INDEX IF NOT EXISTS payments_payment_account_id_af225a32_like ON payments_payment USING btree (account_id varchar_pattern_ops); +ALTER INDEX payments_payment_account_id_af225a32_like RENAME TO payment_account_id_like_idx; + +CREATE INDEX IF NOT EXISTS payments_payment_disbursement_id_2a817b83 ON payments_payment USING btree (disbursement_id); +ALTER INDEX payments_payment_disbursement_id_2a817b83 RENAME TO payment_disbursement_id_idx; + +ALTER TABLE payments_payment RENAME TO payments; + + +-- TABLE: payments_withdrawal +CREATE TABLE IF NOT EXISTS payments_withdrawal ( + sep24_transaction_id character varying(64) NOT NULL PRIMARY KEY, + anchor_id character varying(64) NOT NULL, + amount numeric(7,2) NOT NULL, + started_at timestamp with time zone NOT NULL, + completed_at timestamp with time zone NOT NULL, + created_at timestamp with time zone NOT NULL, + account_id character varying(64) NOT NULL REFERENCES receivers (id) DEFERRABLE INITIALLY DEFERRED +); +CREATE INDEX IF NOT EXISTS payments_wi_created_18b04a_idx ON payments_withdrawal USING btree (created_at DESC); +ALTER INDEX payments_wi_created_18b04a_idx RENAME TO withdrawal_created_at_idx; + +CREATE INDEX IF NOT EXISTS payments_withdrawal_account_id_ec0819dd ON payments_withdrawal USING btree (account_id); +ALTER INDEX payments_withdrawal_account_id_ec0819dd RENAME TO withdrawal_account_id_idx; + +CREATE INDEX IF NOT EXISTS payments_withdrawal_account_id_ec0819dd_like ON payments_withdrawal USING btree (account_id varchar_pattern_ops); +ALTER INDEX payments_withdrawal_account_id_ec0819dd_like RENAME TO withdrawal_account_id_like_idx; + +ALTER TABLE payments_withdrawal RENAME TO withdrawal; + + +-- +migrate Down + +DROP TABLE IF EXISTS withdrawal CASCADE; -- Called 'payments_withdrawal' in SDP-v1 +DROP TABLE IF EXISTS payments CASCADE; -- Called 'payments_payment' in SDP-v1 +DROP TABLE IF EXISTS payments_semaphore CASCADE; -- Called 'payments_heartbeat' in SDP-v1 +DROP TABLE IF EXISTS disbursements CASCADE; -- Called 'payments_disbursement' in SDP-v1 +DROP TABLE IF EXISTS on_off_switch CASCADE; -- Called 'payments_activation' in SDP-v1 +DROP TABLE IF EXISTS receivers CASCADE; -- Called 'payments_account' in SDP-v1 + +DROP TABLE IF EXISTS django_session CASCADE; +DROP TABLE IF EXISTS django_migrations CASCADE; +DROP TABLE IF EXISTS django_admin_log CASCADE; +DROP TABLE IF EXISTS auth_user_user_permissions CASCADE; +DROP TABLE IF EXISTS auth_user_groups CASCADE; +DROP TABLE IF EXISTS auth_user CASCADE; +DROP TABLE IF EXISTS auth_group_permissions CASCADE; +DROP TABLE IF EXISTS auth_permission CASCADE; +DROP TABLE IF EXISTS django_content_type CASCADE; +DROP TABLE IF EXISTS auth_group CASCADE; diff --git a/db/migrations/sdp-migrations/2023-01-26.0-delete-all-django-stuff.sql b/db/migrations/sdp-migrations/2023-01-26.0-delete-all-django-stuff.sql new file mode 100644 index 000000000..ba86c1fa1 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-26.0-delete-all-django-stuff.sql @@ -0,0 +1,33 @@ +-- This migration dumps all django-related stuff that was in the database of the SDP v1. + + +-- +migrate Up + +DROP TABLE IF EXISTS django_session CASCADE; +DROP TABLE IF EXISTS django_migrations CASCADE; +DROP TABLE IF EXISTS django_admin_log CASCADE; +DROP TABLE IF EXISTS auth_user_user_permissions CASCADE; +DROP TABLE IF EXISTS auth_user_groups CASCADE; +DROP TABLE IF EXISTS auth_user CASCADE; +DROP TABLE IF EXISTS auth_group_permissions CASCADE; +DROP TABLE IF EXISTS auth_permission CASCADE; +DROP TABLE IF EXISTS django_content_type CASCADE; +DROP TABLE IF EXISTS auth_group CASCADE; +DROP TABLE IF EXISTS otp_static_staticdevice CASCADE; +DROP TABLE IF EXISTS otp_static_statictoken CASCADE; +DROP TABLE IF EXISTS otp_totp_totpdevice CASCADE; +DROP TABLE IF EXISTS otp_yubikey_remoteyubikeydevice CASCADE; +DROP TABLE IF EXISTS otp_yubikey_validationservice CASCADE; +DROP TABLE IF EXISTS otp_yubikey_yubikeydevice CASCADE; +DROP TABLE IF EXISTS two_factor_phonedevice CASCADE; + +DROP SEQUENCE IF EXISTS otp_static_staticdevice_id_seq CASCADE; +DROP SEQUENCE IF EXISTS otp_static_statictoken_id_seq CASCADE; +DROP SEQUENCE IF EXISTS otp_totp_totpdevice_id_seq CASCADE; +DROP SEQUENCE IF EXISTS otp_yubikey_remoteyubikeydevice_id_seq CASCADE; +DROP SEQUENCE IF EXISTS otp_yubikey_validationservice_id_seq CASCADE; +DROP SEQUENCE IF EXISTS otp_yubikey_yubikeydevice_id_seq CASCADE; + + +-- +migrate Down + diff --git a/db/migrations/sdp-migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql b/db/migrations/sdp-migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql new file mode 100644 index 000000000..2decdd553 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql @@ -0,0 +1,21 @@ +-- This migration dumps all django-related stuff that was in the database of the SDP v1. + + +-- +migrate Up + +DROP TABLE IF EXISTS on_off_switch CASCADE; +DROP TABLE IF EXISTS payments_semaphore CASCADE; +ALTER TABLE withdrawal RENAME COLUMN account_id TO receiver_id; + +-- +migrate StatementBegin +-- Delete withdrawal table if it is empty +DO $$ +BEGIN + IF (SELECT COUNT(*) FROM withdrawal) = 0 THEN + EXECUTE 'DROP TABLE withdrawal'; + END IF; +END $$; +-- +migrate StatementEnd + + +-- +migrate Down diff --git a/internal/db/migrations/2023-01-26.2-updated-at-trigger.sql b/db/migrations/sdp-migrations/2023-01-26.2-updated-at-trigger.sql similarity index 100% rename from internal/db/migrations/2023-01-26.2-updated-at-trigger.sql rename to db/migrations/sdp-migrations/2023-01-26.2-updated-at-trigger.sql diff --git a/db/migrations/sdp-migrations/2023-01-27.0-create-assets-table.sql b/db/migrations/sdp-migrations/2023-01-27.0-create-assets-table.sql new file mode 100644 index 000000000..d21a34f39 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-27.0-create-assets-table.sql @@ -0,0 +1,43 @@ +-- This creates the assets table and updates the other tables that depend on it. + +-- +migrate Up + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + +CREATE TABLE assets ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), + code VARCHAR(12) NOT NULL, + issuer VARCHAR(56) NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + deleted_at TIMESTAMP WITH TIME ZONE, + UNIQUE (code, issuer), + CONSTRAINT asset_issuer_length_check CHECK (char_length(issuer) = 56) +); +INSERT INTO assets (code, issuer) VALUES ('USDC', 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); + +ALTER TABLE disbursements + ADD COLUMN asset_id VARCHAR(36), + ADD CONSTRAINT fk_disbursement_asset_id FOREIGN KEY (asset_id) REFERENCES assets (id); +UPDATE disbursements SET asset_id = (SELECT id FROM assets WHERE code = 'USDC' AND issuer = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); +ALTER TABLE disbursements ALTER COLUMN asset_id SET NOT NULL; + +ALTER TABLE payments + ADD COLUMN asset_id VARCHAR(36), + ADD CONSTRAINT fk_payment_asset_id FOREIGN KEY (asset_id) REFERENCES assets (id); +UPDATE payments SET asset_id = (SELECT id FROM assets WHERE code = 'USDC' AND issuer = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); +ALTER TABLE payments ALTER COLUMN asset_id SET NOT NULL; + +-- TRIGGER: updated_at +CREATE TRIGGER refresh_asset_updated_at BEFORE UPDATE ON assets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); + + +-- +migrate Down + +DROP TRIGGER refresh_asset_updated_at ON assets; + +ALTER TABLE payments DROP COLUMN asset_id; + +ALTER TABLE disbursements DROP COLUMN asset_id; + +DROP TABLE assets CASCADE; diff --git a/db/migrations/sdp-migrations/2023-01-27.1-create-countries-table.sql b/db/migrations/sdp-migrations/2023-01-27.1-create-countries-table.sql new file mode 100644 index 000000000..df68ba86b --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-27.1-create-countries-table.sql @@ -0,0 +1,29 @@ +-- This creates the countries table and updates the other tables that depend on it. + +-- +migrate Up + +CREATE TABLE countries ( + code VARCHAR(3) PRIMARY KEY, + name VARCHAR(100) NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + deleted_at TIMESTAMP WITH TIME ZONE, + UNIQUE (name), + CONSTRAINT country_code_length_check CHECK (char_length(code) = 3) +); +INSERT INTO countries (code, name) VALUES ('UKR', 'Ukraine'); + +ALTER TABLE disbursements + ADD COLUMN country_code VARCHAR(3), + ADD CONSTRAINT fk_disbursement_country_code FOREIGN KEY (country_code) REFERENCES countries (code); +UPDATE disbursements SET country_code = 'UKR'; +ALTER TABLE disbursements ALTER COLUMN country_code SET NOT NULL; + +CREATE TRIGGER refresh_country_updated_at BEFORE UPDATE ON countries FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); + +-- +migrate Down +DROP TRIGGER refresh_country_updated_at ON countries; + +ALTER TABLE disbursements DROP COLUMN country_code; + +DROP TABLE countries CASCADE; diff --git a/db/migrations/sdp-migrations/2023-01-27.2-create-wallets-table.sql b/db/migrations/sdp-migrations/2023-01-27.2-create-wallets-table.sql new file mode 100644 index 000000000..bda548269 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-27.2-create-wallets-table.sql @@ -0,0 +1,34 @@ +-- This creates the wallets table and updates the other tables that depend on it. + +-- +migrate Up + +CREATE TABLE wallets ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), + name VARCHAR(30) NOT NULL, + homepage VARCHAR(255) NOT NULL, + deep_link_schema VARCHAR(30) NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + deleted_at TIMESTAMP WITH TIME ZONE, + UNIQUE (name), + UNIQUE (homepage), + UNIQUE (deep_link_schema) +); +-- TODO: keep in mind that the deep link `vibrantapp://` is not confirmed yet and is subject to change. +INSERT INTO wallets (name, homepage, deep_link_schema) VALUES ('Vibrant Assist', 'https://vibrantapp.com', 'https://vibrantapp.com/sdp-dev'); + +ALTER TABLE disbursements + ADD COLUMN wallet_id VARCHAR(36), + ADD CONSTRAINT fk_disbursement_wallet_id FOREIGN KEY (wallet_id) REFERENCES wallets (id); +UPDATE disbursements SET wallet_id = (SELECT id FROM wallets WHERE name = 'Vibrant Assist'); +ALTER TABLE disbursements ALTER COLUMN wallet_id SET NOT NULL; + +CREATE TRIGGER refresh_wallet_updated_at BEFORE UPDATE ON wallets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); + + +-- +migrate Down +DROP TRIGGER refresh_wallet_updated_at ON wallets; + +ALTER TABLE disbursements DROP COLUMN wallet_id; + +DROP TABLE wallets CASCADE; diff --git a/db/migrations/sdp-migrations/2023-01-27.3-create-receiver-wallets-table.sql b/db/migrations/sdp-migrations/2023-01-27.3-create-receiver-wallets-table.sql new file mode 100644 index 000000000..f4308aa60 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-01-27.3-create-receiver-wallets-table.sql @@ -0,0 +1,37 @@ +-- This creates the receiver_wallets table and updates the other tables that depend on it. + +-- +migrate Up + +-- Table: receiver_wallets +CREATE TABLE receiver_wallets ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), + receiver_id VARCHAR(36) NOT NULL REFERENCES receivers (id), + wallet_id VARCHAR(36) REFERENCES wallets (id), + stellar_address VARCHAR(56), + stellar_memo VARCHAR(56), + stellar_memo_type VARCHAR(56), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), + UNIQUE (receiver_id, wallet_id) +); +INSERT + INTO receiver_wallets (receiver_id, stellar_address) + (SELECT id, public_key FROM receivers); +UPDATE receiver_wallets SET wallet_id = (SELECT id FROM wallets WHERE name = 'Vibrant Assist'); +ALTER TABLE receiver_wallets ALTER COLUMN wallet_id SET NOT NULL; + +-- Table: receivers +ALTER TABLE receivers DROP COLUMN public_key; + +CREATE TRIGGER refresh_receiver_wallet_updated_at BEFORE UPDATE ON receiver_wallets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); + + +-- +migrate Down +DROP TRIGGER refresh_receiver_wallet_updated_at ON receiver_wallets; + +-- Table: receivers +ALTER TABLE receivers ADD COLUMN public_key VARCHAR(128); +UPDATE receivers SET public_key = (SELECT stellar_address FROM receiver_wallets WHERE receiver_id = receivers.id); + +-- Table: receiver_wallets +DROP TABLE receiver_wallets CASCADE; diff --git a/internal/db/migrations/2023-01-27.4-create-messages-table.sql b/db/migrations/sdp-migrations/2023-01-27.4-create-messages-table.sql similarity index 60% rename from internal/db/migrations/2023-01-27.4-create-messages-table.sql rename to db/migrations/sdp-migrations/2023-01-27.4-create-messages-table.sql index c03e2133b..91bbbf296 100644 --- a/internal/db/migrations/2023-01-27.4-create-messages-table.sql +++ b/db/migrations/sdp-migrations/2023-01-27.4-create-messages-table.sql @@ -9,12 +9,12 @@ CREATE TYPE message_type AS ENUM( ); -- Table: messages -CREATE TABLE public.messages ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), +CREATE TABLE messages ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), type message_type NOT NULL, - asset_id VARCHAR(36) NOT NULL REFERENCES public.assets (id), - wallet_id VARCHAR(36) NOT NULL REFERENCES public.wallets (id), - receiver_id VARCHAR(36) NOT NULL REFERENCES public.receivers (id), + asset_id VARCHAR(36) NOT NULL REFERENCES assets (id), + wallet_id VARCHAR(36) NOT NULL REFERENCES wallets (id), + receiver_id VARCHAR(36) NOT NULL REFERENCES receivers (id), text_encrypted VARCHAR(1024) NOT NULL, title_encrypted VARCHAR(128), created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW() @@ -24,8 +24,8 @@ CREATE TABLE public.messages ( -- Insert messages if there is pre-existing data, so to prevent SMSs from being re-triggered. DO $$ BEGIN - IF (SELECT COUNT(*) FROM public.receivers WHERE status <> ALL(ARRAY['READY', 'PAID', 'PARTIALLY_CASHED_OUT', 'FULLY_CASHED_OUT'])) > 0 THEN - INSERT INTO public.messages ( + IF (SELECT COUNT(*) FROM receivers WHERE status <> ALL(ARRAY['READY', 'PAID', 'PARTIALLY_CASHED_OUT', 'FULLY_CASHED_OUT'])) > 0 THEN + INSERT INTO messages ( type, asset_id, wallet_id, @@ -36,13 +36,13 @@ BEGIN ) SELECT 'AWS_SMS', - (SELECT id FROM public.assets WHERE code = 'USDC' LIMIT 1), - (SELECT id FROM public.wallets WHERE name ILIKE '%Vibrant%' LIMIT 1), + (SELECT id FROM assets WHERE code = 'USDC' LIMIT 1), + (SELECT id FROM wallets WHERE name ILIKE '%Vibrant%' LIMIT 1), r.id, 'text omitted during initial migration', 'title omitted during initial migration', NOW() - FROM public.receivers r + FROM receivers r WHERE r.status <> ALL(ARRAY['READY', 'PAID', 'PARTIALLY_CASHED_OUT', 'FULLY_CASHED_OUT']); END IF; END $$; @@ -51,5 +51,5 @@ END $$; -- +migrate Down -- Table: messages -DROP TABLE public.messages CASCADE; +DROP TABLE messages CASCADE; DROP TYPE message_type; diff --git a/internal/db/migrations/2023-01-30.0-update-disbursements-table.sql b/db/migrations/sdp-migrations/2023-01-30.0-update-disbursements-table.sql similarity index 65% rename from internal/db/migrations/2023-01-30.0-update-disbursements-table.sql rename to db/migrations/sdp-migrations/2023-01-30.0-update-disbursements-table.sql index 077544b4a..9f9bef6d7 100644 --- a/internal/db/migrations/2023-01-30.0-update-disbursements-table.sql +++ b/db/migrations/sdp-migrations/2023-01-30.0-update-disbursements-table.sql @@ -23,50 +23,50 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.disbursements - ALTER COLUMN id SET DEFAULT uuid_generate_v4(), +ALTER TABLE disbursements + ALTER COLUMN id SET DEFAULT public.uuid_generate_v4(), ADD COLUMN name VARCHAR(128), ADD COLUMN status disbursement_status NOT NULL DEFAULT disbursement_status('DRAFT'), ADD COLUMN status_history jsonb[] NOT NULL DEFAULT ARRAY[create_disbursement_status_history(NOW(), disbursement_status('DRAFT'), NULL)], ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); -- TODO: Add column `uploaded_by_user_id` to disbursement table -ALTER TABLE public.disbursements RENAME COLUMN requested_at TO created_at; +ALTER TABLE disbursements RENAME COLUMN requested_at TO created_at; -- columns name & id -UPDATE public.disbursements SET name = id; -ALTER TABLE public.disbursements +UPDATE disbursements SET name = id; +ALTER TABLE disbursements ALTER COLUMN created_at SET DEFAULT NOW(), ALTER COLUMN name SET NOT NULL, ADD CONSTRAINT disbursement_name_unique UNIQUE (name); -- column status -UPDATE public.disbursements AS d +UPDATE disbursements AS d SET status = (CASE WHEN EXISTS(SELECT 1 FROM payments WHERE disbursement_id = d.id AND status != 'SUCCESS') THEN disbursement_status('STARTED') ELSE disbursement_status('COMPLETED') END); -- column updated_at -CREATE TRIGGER refresh_disbursement_updated_at BEFORE UPDATE ON public.disbursements FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_disbursement_updated_at BEFORE UPDATE ON disbursements FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- column status_history -UPDATE public.disbursements SET status_history = ARRAY[create_disbursement_status_history(created_at::TIMESTAMP, disbursement_status('STARTED'), NULL)]; -UPDATE public.disbursements SET status_history = array_prepend(create_disbursement_status_history(NOW(), disbursement_status('COMPLETED'), NULL), status_history) WHERE status = disbursement_status('COMPLETED'); +UPDATE disbursements SET status_history = ARRAY[create_disbursement_status_history(created_at::TIMESTAMP, disbursement_status('STARTED'), NULL)]; +UPDATE disbursements SET status_history = array_prepend(create_disbursement_status_history(NOW(), disbursement_status('COMPLETED'), NULL), status_history) WHERE status = disbursement_status('COMPLETED'); -- +migrate Down -DROP TRIGGER refresh_disbursement_updated_at ON public.disbursements; +DROP TRIGGER refresh_disbursement_updated_at ON disbursements; -ALTER TABLE public.disbursements +ALTER TABLE disbursements DROP CONSTRAINT disbursement_name_unique, DROP COLUMN name, DROP COLUMN status, DROP COLUMN status_history, DROP COLUMN updated_at; -ALTER TABLE public.disbursements RENAME COLUMN created_at TO requested_at; +ALTER TABLE disbursements RENAME COLUMN created_at TO requested_at; DROP FUNCTION create_disbursement_status_history; -DROP TYPE disbursement_status; \ No newline at end of file +DROP TYPE disbursement_status; diff --git a/internal/db/migrations/2023-01-30.1-update-payments-table.sql b/db/migrations/sdp-migrations/2023-01-30.1-update-payments-table.sql similarity index 55% rename from internal/db/migrations/2023-01-30.1-update-payments-table.sql rename to db/migrations/sdp-migrations/2023-01-30.1-update-payments-table.sql index 4496858c5..e86a37b28 100644 --- a/internal/db/migrations/2023-01-30.1-update-payments-table.sql +++ b/db/migrations/sdp-migrations/2023-01-30.1-update-payments-table.sql @@ -24,11 +24,11 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.payments RENAME COLUMN requested_at TO created_at; -ALTER TABLE public.payments RENAME COLUMN account_id TO receiver_id; -ALTER TABLE public.payments RENAME COLUMN status TO old_status; -ALTER TABLE public.payments - ALTER COLUMN id SET DEFAULT uuid_generate_v4(), +ALTER TABLE payments RENAME COLUMN requested_at TO created_at; +ALTER TABLE payments RENAME COLUMN account_id TO receiver_id; +ALTER TABLE payments RENAME COLUMN status TO old_status; +ALTER TABLE payments + ALTER COLUMN id SET DEFAULT public.uuid_generate_v4(), ALTER COLUMN amount TYPE numeric(19, 7), ALTER COLUMN status_message TYPE VARCHAR(256), ALTER COLUMN created_at SET DEFAULT NOW(), @@ -43,7 +43,7 @@ ALTER TABLE public.payments ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); -- column status -UPDATE public.payments AS d +UPDATE payments AS d SET status = (CASE WHEN old_status='REQUESTED' THEN payment_status('READY') WHEN old_status='PENDING' THEN payment_status('PENDING') @@ -53,20 +53,20 @@ UPDATE public.payments AS d END); -- column status_history -UPDATE public.payments SET status_history = ARRAY[create_payment_status_history(created_at::TIMESTAMP, payment_status('READY'), NULL)]; -UPDATE public.payments SET status_history = array_prepend(create_payment_status_history(started_at::TIMESTAMP, payment_status('PENDING'), NULL), status_history) WHERE started_at IS NOT NULL; -UPDATE public.payments SET status_history = array_prepend(create_payment_status_history(NOW(), payment_status('FAILURE'), status_message::VARCHAR), status_history) WHERE old_status='PENDING_FUNDS'; -UPDATE public.payments SET status_history = array_prepend(create_payment_status_history(completed_at::TIMESTAMP, payment_status('SUCCESS'), NULL), status_history) WHERE old_status='SUCCESS'; -UPDATE public.payments SET status_history = array_prepend(create_payment_status_history(completed_at::TIMESTAMP, payment_status('FAILURE'), status_message::VARCHAR), status_history) WHERE old_status='FAILURE'; +UPDATE payments SET status_history = ARRAY[create_payment_status_history(created_at::TIMESTAMP, payment_status('READY'), NULL)]; +UPDATE payments SET status_history = array_prepend(create_payment_status_history(started_at::TIMESTAMP, payment_status('PENDING'), NULL), status_history) WHERE started_at IS NOT NULL; +UPDATE payments SET status_history = array_prepend(create_payment_status_history(NOW(), payment_status('FAILURE'), status_message::VARCHAR), status_history) WHERE old_status='PENDING_FUNDS'; +UPDATE payments SET status_history = array_prepend(create_payment_status_history(completed_at::TIMESTAMP, payment_status('SUCCESS'), NULL), status_history) WHERE old_status='SUCCESS'; +UPDATE payments SET status_history = array_prepend(create_payment_status_history(completed_at::TIMESTAMP, payment_status('FAILURE'), status_message::VARCHAR), status_history) WHERE old_status='FAILURE'; -- column updated_at -CREATE TRIGGER refresh_payment_updated_at BEFORE UPDATE ON public.payments FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_payment_updated_at BEFORE UPDATE ON payments FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- +migrate Down -DROP TRIGGER refresh_payment_updated_at ON public.payments; +DROP TRIGGER refresh_payment_updated_at ON payments; -ALTER TABLE public.payments +ALTER TABLE payments ADD COLUMN custodial_payment_id VARCHAR(36), ADD COLUMN idempotency_key VARCHAR(64), ADD COLUMN withdrawal_amount NUMERIC(7,2) NOT NULL DEFAULT 0, @@ -77,10 +77,10 @@ ALTER TABLE public.payments DROP COLUMN stellar_operation_id, DROP COLUMN blockchain_sender_id; -ALTER TABLE public.payments RENAME COLUMN old_status TO status; -ALTER TABLE public.payments RENAME COLUMN created_at TO requested_at; -ALTER TABLE public.payments RENAME COLUMN receiver_id TO account_id; +ALTER TABLE payments RENAME COLUMN old_status TO status; +ALTER TABLE payments RENAME COLUMN created_at TO requested_at; +ALTER TABLE payments RENAME COLUMN receiver_id TO account_id; DROP FUNCTION create_payment_status_history; -DROP TYPE payment_status; \ No newline at end of file +DROP TYPE payment_status; diff --git a/internal/db/migrations/2023-01-30.2-drop-unused-payments-columns.sql b/db/migrations/sdp-migrations/2023-01-30.2-drop-unused-payments-columns.sql similarity index 76% rename from internal/db/migrations/2023-01-30.2-drop-unused-payments-columns.sql rename to db/migrations/sdp-migrations/2023-01-30.2-drop-unused-payments-columns.sql index 060a5db44..5db889899 100644 --- a/internal/db/migrations/2023-01-30.2-drop-unused-payments-columns.sql +++ b/db/migrations/sdp-migrations/2023-01-30.2-drop-unused-payments-columns.sql @@ -2,7 +2,7 @@ -- +migrate Up -ALTER TABLE public.payments +ALTER TABLE payments DROP COLUMN started_at, DROP COLUMN completed_at, DROP COLUMN old_status, @@ -11,8 +11,8 @@ ALTER TABLE public.payments -- +migrate Down -ALTER TABLE public.payments +ALTER TABLE payments ADD COLUMN started_at TIMESTAMP WITH TIME ZONE, ADD COLUMN completed_at TIMESTAMP WITH TIME ZONE, ADD COLUMN old_status VARCHAR(16), - ADD COLUMN status_message VARCHAR(256); \ No newline at end of file + ADD COLUMN status_message VARCHAR(256); diff --git a/internal/db/migrations/2023-01-30.3-update-receivers-table.sql b/db/migrations/sdp-migrations/2023-01-30.3-update-receivers-table.sql similarity index 61% rename from internal/db/migrations/2023-01-30.3-update-receivers-table.sql rename to db/migrations/sdp-migrations/2023-01-30.3-update-receivers-table.sql index aaea697f5..fd8b64708 100644 --- a/internal/db/migrations/2023-01-30.3-update-receivers-table.sql +++ b/db/migrations/sdp-migrations/2023-01-30.3-update-receivers-table.sql @@ -2,9 +2,9 @@ -- +migrate Up -ALTER TABLE public.receivers RENAME COLUMN registered_at TO created_at; -ALTER TABLE public.receivers - ALTER COLUMN id SET DEFAULT uuid_generate_v4(), +ALTER TABLE receivers RENAME COLUMN registered_at TO created_at; +ALTER TABLE receivers + ALTER COLUMN id SET DEFAULT public.uuid_generate_v4(), ALTER COLUMN created_at SET DEFAULT NOW(), DROP COLUMN link_last_sent_at, DROP COLUMN email_registered_at, @@ -14,13 +14,13 @@ ALTER TABLE public.receivers ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); -- column updated_at -CREATE TRIGGER refresh_receiver_updated_at BEFORE UPDATE ON public.receivers FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_receiver_updated_at BEFORE UPDATE ON receivers FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- +migrate Down -DROP TRIGGER refresh_receiver_updated_at ON public.receivers; +DROP TRIGGER refresh_receiver_updated_at ON receivers; -ALTER TABLE public.receivers +ALTER TABLE receivers ADD COLUMN link_last_sent_at TIMESTAMP WITH TIME ZONE, ADD COLUMN email_registered_at TIMESTAMP WITH TIME ZONE, ADD COLUMN public_key_registered_at TIMESTAMP WITH TIME ZONE, @@ -28,4 +28,4 @@ ALTER TABLE public.receivers ADD COLUMN hashed_phone_number VARCHAR(64), DROP COLUMN updated_at; -ALTER TABLE public.receivers RENAME COLUMN created_at TO registered_at; +ALTER TABLE receivers RENAME COLUMN created_at TO registered_at; diff --git a/internal/db/migrations/2023-01-30.4-receiver-wallets-status.sql b/db/migrations/sdp-migrations/2023-01-30.4-receiver-wallets-status.sql similarity index 80% rename from internal/db/migrations/2023-01-30.4-receiver-wallets-status.sql rename to db/migrations/sdp-migrations/2023-01-30.4-receiver-wallets-status.sql index 9fed78f62..b2753b314 100644 --- a/internal/db/migrations/2023-01-30.4-receiver-wallets-status.sql +++ b/db/migrations/sdp-migrations/2023-01-30.4-receiver-wallets-status.sql @@ -22,40 +22,40 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN status receiver_wallet_status NOT NULL DEFAULT receiver_wallet_status('DRAFT'), ADD COLUMN status_history jsonb[] NOT NULL DEFAULT ARRAY[create_receiver_wallet_status_history(NOW(), receiver_wallet_status('DRAFT'))]; -- COLUMN: status -UPDATE public.receiver_wallets rwOriginal +UPDATE receiver_wallets rwOriginal SET status = ( CASE WHEN UPPER(r.status) IN ('READY', 'PAID', 'PARTIALLY_CASHED_OUT', 'FULLY_CASHED_OUT') THEN receiver_wallet_status('REGISTERED') ELSE receiver_wallet_status('READY') END ) - FROM public.receiver_wallets rw LEFT JOIN public.receivers r ON rw.receiver_id = r.id + FROM receiver_wallets rw LEFT JOIN receivers r ON rw.receiver_id = r.id WHERE rwOriginal.id = rw.id; -- COLUMN: status_history -UPDATE public.receiver_wallets rwOriginal +UPDATE receiver_wallets rwOriginal SET status_history = ( CASE WHEN rwOriginal.status = receiver_wallet_status('REGISTERED') THEN ARRAY[create_receiver_wallet_status_history(NOW(), receiver_wallet_status('REGISTERED'))] ELSE ARRAY[create_receiver_wallet_status_history(NOW(), receiver_wallet_status('READY'))] END ) - FROM public.receiver_wallets rw LEFT JOIN public.receivers r ON rw.receiver_id = r.id + FROM receiver_wallets rw LEFT JOIN receivers r ON rw.receiver_id = r.id WHERE rwOriginal.id = rw.id; -- TABLE: receiver -ALTER TABLE public.receivers DROP COLUMN status; +ALTER TABLE receivers DROP COLUMN status; -- +migrate Down -- TABLE: receiver -ALTER TABLE public.receivers ADD COLUMN status VARCHAR(32); +ALTER TABLE receivers ADD COLUMN status VARCHAR(32); -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN status, DROP COLUMN status_history; diff --git a/internal/db/migrations/2023-02-03.0-update-messages-add-new-columns.sql b/db/migrations/sdp-migrations/2023-02-03.0-update-messages-add-new-columns.sql similarity index 80% rename from internal/db/migrations/2023-02-03.0-update-messages-add-new-columns.sql rename to db/migrations/sdp-migrations/2023-02-03.0-update-messages-add-new-columns.sql index bfc0a4bc3..dd23d78bb 100644 --- a/internal/db/migrations/2023-02-03.0-update-messages-add-new-columns.sql +++ b/db/migrations/sdp-migrations/2023-02-03.0-update-messages-add-new-columns.sql @@ -21,19 +21,19 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.messages +ALTER TABLE messages ADD COLUMN status message_status NOT NULL DEFAULT message_status('PENDING'), ADD COLUMN status_history jsonb[] NOT NULL DEFAULT ARRAY[create_message_status_history(NOW(), message_status('PENDING'), NULL)], ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(); -- column updated_at -CREATE TRIGGER refresh_message_updated_at BEFORE UPDATE ON public.messages FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_message_updated_at BEFORE UPDATE ON messages FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- +migrate Down -DROP TRIGGER refresh_message_updated_at ON public.messages; +DROP TRIGGER refresh_message_updated_at ON messages; -ALTER TABLE public.messages +ALTER TABLE messages DROP COLUMN status, DROP COLUMN status_history, DROP COLUMN updated_at; diff --git a/internal/db/migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql b/db/migrations/sdp-migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql similarity index 86% rename from internal/db/migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql rename to db/migrations/sdp-migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql index 633f965da..718b49dad 100644 --- a/internal/db/migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql +++ b/db/migrations/sdp-migrations/2023-03-09.0-populate-static-data-countries-assets-wallets.sql @@ -4,7 +4,7 @@ -- Add USA, BRA and COL to the countries table INSERT INTO - public.countries (code, name) + countries (code, name) VALUES ('BRA', 'Brazil'), ('USA', 'United States of America'), @@ -14,6 +14,6 @@ VALUES -- Remove USA, BRA and COL from the countries table DELETE FROM - public.countries + countries WHERE code IN ('BRA', 'USA', 'COL'); diff --git a/internal/db/migrations/2023-03-16.0-create-organization-table.sql b/db/migrations/sdp-migrations/2023-03-16.0-create-organization-table.sql similarity index 72% rename from internal/db/migrations/2023-03-16.0-create-organization-table.sql rename to db/migrations/sdp-migrations/2023-03-16.0-create-organization-table.sql index 63e1f11cd..696c02e7c 100644 --- a/internal/db/migrations/2023-03-16.0-create-organization-table.sql +++ b/db/migrations/sdp-migrations/2023-03-16.0-create-organization-table.sql @@ -3,8 +3,8 @@ -- +migrate Up -- Table: organizations -CREATE TABLE public.organizations ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), +CREATE TABLE organizations ( + id VARCHAR(36) PRIMARY KEY DEFAULT public.uuid_generate_v4(), name VARCHAR(64) NOT NULL, stellar_main_address VARCHAR(56) NOT NULL, timezone_utc_offset VARCHAR(6) NOT NULL DEFAULT '+00:00', @@ -20,14 +20,14 @@ CREATE TABLE public.organizations ( CONSTRAINT organization_sms_registration_message_template_contains_tags_check CHECK (sms_registration_message_template LIKE '%{{.OrganizationName}}%' AND sms_registration_message_template LIKE '%{{.RegistrationLink}}%') ); -INSERT INTO public.organizations (name, stellar_main_address) VALUES ('MyCustomAid', 'GDA34JZ26FZY64XCSY46CUNSHLX762LHJXQHWWHGL5HSFRWSGBVHUFNI'); +INSERT INTO organizations (name, stellar_main_address) VALUES ('MyCustomAid', 'GDA34JZ26FZY64XCSY46CUNSHLX762LHJXQHWWHGL5HSFRWSGBVHUFNI'); -CREATE TRIGGER refresh_organization_updated_at BEFORE UPDATE ON public.organizations FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_organization_updated_at BEFORE UPDATE ON organizations FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- +migrate Down -- Table: organizations -DROP TRIGGER refresh_organization_updated_at ON public.organizations; +DROP TRIGGER refresh_organization_updated_at ON organizations; -DROP TABLE public.organizations CASCADE; +DROP TABLE organizations CASCADE; diff --git a/internal/db/migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql b/db/migrations/sdp-migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql similarity index 74% rename from internal/db/migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql rename to db/migrations/sdp-migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql index 7bd1af41b..452b5f8a8 100644 --- a/internal/db/migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql +++ b/db/migrations/sdp-migrations/2023-03-22.0-enforce-one-row-for-organizations-table.sql @@ -6,8 +6,8 @@ CREATE OR REPLACE FUNCTION enforce_single_row_for_organizations() RETURNS TRIGGER AS $$ BEGIN - IF (SELECT COUNT(*) FROM public.organizations) != 0 THEN - RAISE EXCEPTION 'public.organizations can must contain exactly one row'; + IF (SELECT COUNT(*) FROM organizations) != 0 THEN + RAISE EXCEPTION 'organizations can must contain exactly one row'; END IF; RETURN NEW; END; @@ -15,20 +15,20 @@ $$ LANGUAGE plpgsql; -- +migrate StatementEnd CREATE TRIGGER enforce_single_row_for_organizations_insert_trigger - BEFORE INSERT ON public.organizations + BEFORE INSERT ON organizations FOR EACH ROW EXECUTE FUNCTION enforce_single_row_for_organizations(); CREATE TRIGGER enforce_single_row_for_organizations_delete_trigger - BEFORE DELETE ON public.organizations + BEFORE DELETE ON organizations FOR EACH ROW EXECUTE FUNCTION enforce_single_row_for_organizations(); -- +migrate Down -DROP TRIGGER enforce_single_row_for_organizations_delete_trigger ON public.organizations; +DROP TRIGGER enforce_single_row_for_organizations_delete_trigger ON organizations; -DROP TRIGGER enforce_single_row_for_organizations_insert_trigger ON public.organizations; +DROP TRIGGER enforce_single_row_for_organizations_insert_trigger ON organizations; DROP FUNCTION enforce_single_row_for_organizations; diff --git a/internal/db/migrations/2023-04-12.0-create-submitter-transactions-table.sql b/db/migrations/sdp-migrations/2023-04-12.0-create-submitter-transactions-table.sql similarity index 84% rename from internal/db/migrations/2023-04-12.0-create-submitter-transactions-table.sql rename to db/migrations/sdp-migrations/2023-04-12.0-create-submitter-transactions-table.sql index 9d1bbc80e..44bf7dfbb 100644 --- a/internal/db/migrations/2023-04-12.0-create-submitter-transactions-table.sql +++ b/db/migrations/sdp-migrations/2023-04-12.0-create-submitter-transactions-table.sql @@ -3,8 +3,8 @@ CREATE TYPE transaction_status as enum ('PENDING', 'PROCESSING', 'SENT', 'SUCCESS', 'ERROR'); -CREATE TABLE public.submitter_transactions ( - id VARCHAR(64) NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(), +CREATE TABLE submitter_transactions ( + id VARCHAR(64) NOT NULL PRIMARY KEY DEFAULT public.uuid_generate_v4(), external_id VARCHAR(64), status transaction_status NOT NULL, status_message TEXT, @@ -22,7 +22,7 @@ CREATE TABLE public.submitter_transactions ( retry_count INT DEFAULT 0 ); -CREATE TABLE public.channel_accounts ( +CREATE TABLE channel_accounts ( public_key VARCHAR(64) NOT NULL PRIMARY KEY, private_key VARCHAR(64), heartbeat TIMESTAMP WITH TIME ZONE, @@ -33,4 +33,4 @@ CREATE TABLE public.channel_accounts ( DROP TABLE submitter_transactions; DROP TABLE channel_accounts; -DROP TYPE transaction_status; \ No newline at end of file +DROP TYPE transaction_status; diff --git a/internal/db/migrations/2023-04-17.0-create-receiver_verifications-table.sql b/db/migrations/sdp-migrations/2023-04-17.0-create-receiver_verifications-table.sql similarity index 54% rename from internal/db/migrations/2023-04-17.0-create-receiver_verifications-table.sql rename to db/migrations/sdp-migrations/2023-04-17.0-create-receiver_verifications-table.sql index 5059c40d2..16ee060a2 100644 --- a/internal/db/migrations/2023-04-17.0-create-receiver_verifications-table.sql +++ b/db/migrations/sdp-migrations/2023-04-17.0-create-receiver_verifications-table.sql @@ -5,8 +5,8 @@ CREATE TYPE verification_type AS ENUM ( 'PIN', 'NATIONAL_ID_NUMBER'); -CREATE TABLE public.receiver_verifications ( - receiver_id VARCHAR(64) NOT NULL REFERENCES public.receivers (id) ON DELETE CASCADE, +CREATE TABLE receiver_verifications ( + receiver_id VARCHAR(64) NOT NULL REFERENCES receivers (id) ON DELETE CASCADE, verification_field verification_type NOT NULL, hashed_value TEXT NOT NULL, attempts SMALLINT DEFAULT 0 NOT NULL, @@ -19,65 +19,64 @@ CREATE TABLE public.receiver_verifications ( -- TRIGGER: updated_at CREATE TRIGGER refresh_receiver_verifications_updated_at - BEFORE UPDATE ON public.receiver_verifications + BEFORE UPDATE ON receiver_verifications FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- Add verification_field to disbursements -ALTER TABLE public.disbursements +ALTER TABLE disbursements ADD COLUMN verification_field verification_type NOT NULL DEFAULT 'DATE_OF_BIRTH'; -- Add external_id field -ALTER TABLE public.receivers +ALTER TABLE receivers ADD COLUMN external_id VARCHAR(64); -UPDATE public.receivers SET external_id = id; -ALTER TABLE public.receivers ALTER COLUMN external_id SET NOT NULL; +UPDATE receivers SET external_id = id; +ALTER TABLE receivers ALTER COLUMN external_id SET NOT NULL; -- Add receiver_wallet_id to payments table -ALTER TABLE public.payments +ALTER TABLE payments ADD COLUMN receiver_wallet_id VARCHAR(64), - ADD CONSTRAINT fk_payments_receiver_wallet_id FOREIGN KEY (receiver_wallet_id) REFERENCES public.receiver_wallets (id); + ADD CONSTRAINT fk_payments_receiver_wallet_id FOREIGN KEY (receiver_wallet_id) REFERENCES receiver_wallets (id); UPDATE - public.payments p + payments p SET receiver_wallet_id = ( SELECT rw.id - FROM public.receiver_wallets rw + FROM receiver_wallets rw WHERE rw.receiver_id = p.receiver_id LIMIT 1 ); -ALTER TABLE public.payments ALTER COLUMN receiver_wallet_id SET NOT NULL; +ALTER TABLE payments ALTER COLUMN receiver_wallet_id SET NOT NULL; -- Migrate existing receivers.extra_info into a new receiver_verifications row. This cannot be reverted. CREATE EXTENSION IF NOT EXISTS pgcrypto; INSERT - INTO public.receiver_verifications (receiver_id, verification_field, confirmed_at, hashed_value) - (SELECT r.id, 'DATE_OF_BIRTH', r.created_at, crypt(TO_CHAR(TO_DATE(r.extra_info, 'MM-YY'), 'YYYY-MM-01'), gen_salt('bf', 4)) FROM public.receivers r); -ALTER TABLE public.receivers DROP COLUMN extra_info; + INTO receiver_verifications (receiver_id, verification_field, confirmed_at, hashed_value) + (SELECT r.id, 'DATE_OF_BIRTH', r.created_at, public.crypt(TO_CHAR(TO_DATE(r.extra_info, 'MM-YY'), 'YYYY-MM-01'), public.gen_salt('bf', 4)) FROM receivers r); +ALTER TABLE receivers DROP COLUMN extra_info; -- +migrate Down -ALTER TABLE public.receivers ADD COLUMN extra_info TEXT; +ALTER TABLE receivers ADD COLUMN extra_info TEXT; UPDATE - public.receivers r + receivers r SET extra_info = ( SELECT rv.hashed_value - FROM public.receiver_verifications rv + FROM receiver_verifications rv WHERE rv.receiver_id = r.id AND rv.verification_field = 'DATE_OF_BIRTH' LIMIT 1 ); -DROP EXTENSION IF EXISTS pgcrypto; -ALTER TABLE public.payments DROP COLUMN receiver_wallet_id; +ALTER TABLE payments DROP COLUMN receiver_wallet_id; -ALTER TABLE public.receivers DROP COLUMN external_id; +ALTER TABLE receivers DROP COLUMN external_id; -ALTER TABLE public.disbursements DROP COLUMN verification_field; +ALTER TABLE disbursements DROP COLUMN verification_field; -DROP TRIGGER refresh_receiver_verifications_updated_at ON public.receiver_verifications; +DROP TRIGGER refresh_receiver_verifications_updated_at ON receiver_verifications; -DROP TABLE public.receiver_verifications; +DROP TABLE receiver_verifications; DROP TYPE verification_type; diff --git a/internal/db/migrations/2023-04-21.0-add-receiver-wallets-otp.sql b/db/migrations/sdp-migrations/2023-04-21.0-add-receiver-wallets-otp.sql similarity index 56% rename from internal/db/migrations/2023-04-21.0-add-receiver-wallets-otp.sql rename to db/migrations/sdp-migrations/2023-04-21.0-add-receiver-wallets-otp.sql index 5a36bfdd3..0e19004f3 100644 --- a/internal/db/migrations/2023-04-21.0-add-receiver-wallets-otp.sql +++ b/db/migrations/sdp-migrations/2023-04-21.0-add-receiver-wallets-otp.sql @@ -1,17 +1,17 @@ -- +migrate Up -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN otp TEXT NULL; -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN otp_created_at TIMESTAMP WITH TIME ZONE NULL; -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN otp_confirmed_at TIMESTAMP WITH TIME ZONE NULL; -- +migrate Down -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN otp; -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN otp_created_at; -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN otp_confirmed_at; diff --git a/internal/db/migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql b/db/migrations/sdp-migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql similarity index 80% rename from internal/db/migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql rename to db/migrations/sdp-migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql index 22beffd5a..e0ab2597f 100644 --- a/internal/db/migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql +++ b/db/migrations/sdp-migrations/2023-04-25.0.alter-messages-table-add-receiver-wallet-id.sql @@ -13,18 +13,18 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.messages - ADD COLUMN receiver_wallet_id VARCHAR(36) NULL REFERENCES public.receiver_wallets (id), +ALTER TABLE messages + ADD COLUMN receiver_wallet_id VARCHAR(36) NULL REFERENCES receiver_wallets (id), ALTER COLUMN asset_id DROP NOT NULL; -- Update the receiver_wallet of the messages if we have pre-existing data. UPDATE - public.messages + messages SET receiver_wallet_id = rw.id FROM ( SELECT DISTINCT ON (receiver_id) id, receiver_id - FROM public.receiver_wallets + FROM receiver_wallets ORDER BY receiver_id, id ) AS rw WHERE @@ -32,6 +32,6 @@ WHERE -- +migrate Down -ALTER TABLE public.messages +ALTER TABLE messages DROP COLUMN receiver_wallet_id, ALTER COLUMN asset_id SET NOT NULL; diff --git a/db/migrations/sdp-migrations/2023-04-26.0-add-demo-wallet.sql b/db/migrations/sdp-migrations/2023-04-26.0-add-demo-wallet.sql new file mode 100644 index 000000000..559bacdf2 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-04-26.0-add-demo-wallet.sql @@ -0,0 +1,12 @@ +-- This migration creates the sep_10_client_domain column in the wallets table and inserts the demo-wallet in the DB. + +-- +migrate Up + +ALTER TABLE wallets ADD COLUMN sep_10_client_domain VARCHAR(255) DEFAULT '' NOT NULL; + +UPDATE wallets SET sep_10_client_domain = substring(homepage from 'https?://([^/]+)'); +UPDATE wallets SET sep_10_client_domain = 'api-dev.vibrantapp.com' WHERE name = 'Vibrant Assist'; +ALTER TABLE wallets ALTER COLUMN deep_link_schema TYPE VARCHAR(255); + +-- +migrate Down +ALTER TABLE wallets DROP COLUMN sep_10_client_domain; diff --git a/internal/db/migrations/2023-05-01.0-add-sync-column-tss.sql b/db/migrations/sdp-migrations/2023-05-01.0-add-sync-column-tss.sql similarity index 56% rename from internal/db/migrations/2023-05-01.0-add-sync-column-tss.sql rename to db/migrations/sdp-migrations/2023-05-01.0-add-sync-column-tss.sql index 930f105fd..dbebeb141 100644 --- a/internal/db/migrations/2023-05-01.0-add-sync-column-tss.sql +++ b/db/migrations/sdp-migrations/2023-05-01.0-add-sync-column-tss.sql @@ -3,7 +3,7 @@ -- +migrate Up -ALTER TABLE public.submitter_transactions ADD COLUMN synced_at TIMESTAMP WITH TIME ZONE NULL; +ALTER TABLE submitter_transactions ADD COLUMN synced_at TIMESTAMP WITH TIME ZONE NULL; -- +migrate Down -ALTER TABLE public.submitter_transactions DROP COLUMN synced_at; +ALTER TABLE submitter_transactions DROP COLUMN synced_at; diff --git a/internal/db/migrations/2023-05-02.0-alter-organizations-table-add-logo.sql b/db/migrations/sdp-migrations/2023-05-02.0-alter-organizations-table-add-logo.sql similarity index 57% rename from internal/db/migrations/2023-05-02.0-alter-organizations-table-add-logo.sql rename to db/migrations/sdp-migrations/2023-05-02.0-alter-organizations-table-add-logo.sql index 66a0bc1e4..459bd8f83 100644 --- a/internal/db/migrations/2023-05-02.0-alter-organizations-table-add-logo.sql +++ b/db/migrations/sdp-migrations/2023-05-02.0-alter-organizations-table-add-logo.sql @@ -1,9 +1,9 @@ -- +migrate Up -ALTER TABLE public.organizations +ALTER TABLE organizations ADD COLUMN logo BYTEA NULL; -- +migrate Down -ALTER TABLE public.organizations +ALTER TABLE organizations DROP COLUMN logo; diff --git a/internal/db/migrations/2023-05-23.0-alter-channel-accounts-pk-type.sql b/db/migrations/sdp-migrations/2023-05-23.0-alter-channel-accounts-pk-type.sql similarity index 100% rename from internal/db/migrations/2023-05-23.0-alter-channel-accounts-pk-type.sql rename to db/migrations/sdp-migrations/2023-05-23.0-alter-channel-accounts-pk-type.sql diff --git a/internal/db/migrations/2023-05-31.0-replace-payment-status-enum.sql b/db/migrations/sdp-migrations/2023-05-31.0-replace-payment-status-enum.sql similarity index 100% rename from internal/db/migrations/2023-05-31.0-replace-payment-status-enum.sql rename to db/migrations/sdp-migrations/2023-05-31.0-replace-payment-status-enum.sql diff --git a/internal/db/migrations/2023-06-01.0-add-file-fields-to-disbursements.sql b/db/migrations/sdp-migrations/2023-06-01.0-add-file-fields-to-disbursements.sql similarity index 100% rename from internal/db/migrations/2023-06-01.0-add-file-fields-to-disbursements.sql rename to db/migrations/sdp-migrations/2023-06-01.0-add-file-fields-to-disbursements.sql diff --git a/internal/db/migrations/2023-06-07.0-add-retry-after-column.sql b/db/migrations/sdp-migrations/2023-06-07.0-add-retry-after-column.sql similarity index 64% rename from internal/db/migrations/2023-06-07.0-add-retry-after-column.sql rename to db/migrations/sdp-migrations/2023-06-07.0-add-retry-after-column.sql index 184670281..d277f9ee0 100644 --- a/internal/db/migrations/2023-06-07.0-add-retry-after-column.sql +++ b/db/migrations/sdp-migrations/2023-06-07.0-add-retry-after-column.sql @@ -3,7 +3,7 @@ -- +migrate Up -ALTER TABLE public.submitter_transactions ADD COLUMN retry_after TIMESTAMP; +ALTER TABLE submitter_transactions ADD COLUMN retry_after TIMESTAMP; -- +migrate Down -ALTER TABLE public.submitter_transactions DROP COLUMN retry_after; \ No newline at end of file +ALTER TABLE submitter_transactions DROP COLUMN retry_after; diff --git a/internal/db/migrations/2023-06-08.0-add-dryrun-message-type.sql b/db/migrations/sdp-migrations/2023-06-08.0-add-dryrun-message-type.sql similarity index 100% rename from internal/db/migrations/2023-06-08.0-add-dryrun-message-type.sql rename to db/migrations/sdp-migrations/2023-06-08.0-add-dryrun-message-type.sql diff --git a/db/migrations/sdp-migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql b/db/migrations/sdp-migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql new file mode 100644 index 000000000..070ca1a21 --- /dev/null +++ b/db/migrations/sdp-migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql @@ -0,0 +1,7 @@ +-- +migrate Up + +CREATE UNIQUE INDEX unique_wallets_index ON wallets(name, homepage, deep_link_schema); + +-- +migrate Down + +DROP INDEX IF EXISTS unique_wallets_index; diff --git a/internal/db/migrations/2023-07-05.0-tss-transactions-table-constraints.sql b/db/migrations/sdp-migrations/2023-07-05.0-tss-transactions-table-constraints.sql similarity index 70% rename from internal/db/migrations/2023-07-05.0-tss-transactions-table-constraints.sql rename to db/migrations/sdp-migrations/2023-07-05.0-tss-transactions-table-constraints.sql index 855b26361..b35d5dc5a 100644 --- a/internal/db/migrations/2023-07-05.0-tss-transactions-table-constraints.sql +++ b/db/migrations/sdp-migrations/2023-07-05.0-tss-transactions-table-constraints.sql @@ -1,6 +1,6 @@ -- +migrate Up -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), ADD COLUMN xdr_sent TEXT UNIQUE, ADD COLUMN xdr_received TEXT UNIQUE, @@ -10,20 +10,20 @@ ALTER TABLE public.submitter_transactions ADD CONSTRAINT unique_stellar_transaction_hash UNIQUE (stellar_transaction_hash), ADD CONSTRAINT check_retry_count CHECK (retry_count >= 0); -CREATE UNIQUE INDEX idx_unique_external_id ON public.submitter_transactions (external_id) WHERE status != 'ERROR'; +CREATE UNIQUE INDEX idx_unique_external_id ON submitter_transactions (external_id) WHERE status != 'ERROR'; -- TRIGGER: updated_at -CREATE TRIGGER refresh_submitter_transactions_updated_at BEFORE UPDATE ON public.submitter_transactions FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_submitter_transactions_updated_at BEFORE UPDATE ON submitter_transactions FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -- +migrate Down -- TRIGGER: updated_at -DROP TRIGGER refresh_submitter_transactions_updated_at ON public.submitter_transactions; +DROP TRIGGER refresh_submitter_transactions_updated_at ON submitter_transactions; DROP INDEX idx_unique_external_id; -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions DROP COLUMN updated_at, DROP COLUMN xdr_sent, DROP COLUMN xdr_received, diff --git a/internal/db/migrations/2023-07-17.0-channel-accounts-management-locks.sql b/db/migrations/sdp-migrations/2023-07-17.0-channel-accounts-management-locks.sql similarity index 75% rename from internal/db/migrations/2023-07-17.0-channel-accounts-management-locks.sql rename to db/migrations/sdp-migrations/2023-07-17.0-channel-accounts-management-locks.sql index 6f98fee52..d80782ec1 100644 --- a/internal/db/migrations/2023-07-17.0-channel-accounts-management-locks.sql +++ b/db/migrations/sdp-migrations/2023-07-17.0-channel-accounts-management-locks.sql @@ -2,31 +2,31 @@ -- It also deletes the unused heartbeat column and add updated_at and locked_at for improved debuggability. -- +migrate Up -ALTER TABLE public.channel_accounts +ALTER TABLE channel_accounts DROP COLUMN heartbeat, ADD COLUMN updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), ADD COLUMN locked_at TIMESTAMP WITH TIME ZONE, ADD COLUMN locked_until_ledger_number INTEGER; -- column updated_at -CREATE TRIGGER refresh_channel_accounts_updated_at BEFORE UPDATE ON public.channel_accounts FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); +CREATE TRIGGER refresh_channel_accounts_updated_at BEFORE UPDATE ON channel_accounts FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ADD COLUMN locked_at TIMESTAMP WITH TIME ZONE, ADD COLUMN locked_until_ledger_number INTEGER, DROP COLUMN memo, DROP COLUMN memo_type; -- +migrate Down -DROP TRIGGER refresh_channel_accounts_updated_at ON public.channel_accounts; +DROP TRIGGER refresh_channel_accounts_updated_at ON channel_accounts; -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions DROP COLUMN locked_at, DROP COLUMN locked_until_ledger_number, ADD COLUMN memo VARCHAR(64), ADD COLUMN memo_type VARCHAR(12); -ALTER TABLE public.channel_accounts +ALTER TABLE channel_accounts ADD COLUMN heartbeat TIMESTAMP WITH TIME ZONE, DROP COLUMN updated_at, DROP COLUMN locked_at, diff --git a/internal/db/migrations/2023-07-17.1-tss-remove-SENT-status.sql b/db/migrations/sdp-migrations/2023-07-17.1-tss-remove-SENT-status.sql similarity index 55% rename from internal/db/migrations/2023-07-17.1-tss-remove-SENT-status.sql rename to db/migrations/sdp-migrations/2023-07-17.1-tss-remove-SENT-status.sql index 5be524fdf..e54ed200e 100644 --- a/internal/db/migrations/2023-07-17.1-tss-remove-SENT-status.sql +++ b/db/migrations/sdp-migrations/2023-07-17.1-tss-remove-SENT-status.sql @@ -5,20 +5,20 @@ CREATE TYPE transaction_status_new AS ENUM ('PENDING', 'PROCESSING', 'SUCCESS', 'ERROR'); -- Add a new column with the new type -ALTER TABLE public.submitter_transactions ADD COLUMN status_new transaction_status_new; +ALTER TABLE submitter_transactions ADD COLUMN status_new transaction_status_new; -- Copy & transform data -UPDATE public.submitter_transactions SET status_new = +UPDATE submitter_transactions SET status_new = CASE WHEN status = 'SENT' THEN 'PROCESSING'::transaction_status_new ELSE status::text::transaction_status_new END; -- Drop the old column -ALTER TABLE public.submitter_transactions DROP COLUMN status; +ALTER TABLE submitter_transactions DROP COLUMN status; -- Rename the new column -ALTER TABLE public.submitter_transactions RENAME COLUMN status_new TO status; +ALTER TABLE submitter_transactions RENAME COLUMN status_new TO status; -- Drop old type DROP TYPE transaction_status; @@ -27,7 +27,7 @@ DROP TYPE transaction_status; ALTER TYPE transaction_status_new RENAME TO transaction_status; -- Restore index that was when we changed the enum type -CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_external_id ON public.submitter_transactions (external_id) WHERE status != 'ERROR'; +CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_external_id ON submitter_transactions (external_id) WHERE status != 'ERROR'; -- +migrate Down @@ -35,16 +35,16 @@ CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_external_id ON public.submitter_tra CREATE TYPE transaction_status_old AS ENUM ('PENDING', 'PROCESSING', 'SENT', 'SUCCESS', 'ERROR'); -- Add a new column with the old type -ALTER TABLE public.submitter_transactions ADD COLUMN status_old transaction_status_old; +ALTER TABLE submitter_transactions ADD COLUMN status_old transaction_status_old; -- Copy data to new column -UPDATE public.submitter_transactions SET status_old = status::text::transaction_status_old; +UPDATE submitter_transactions SET status_old = status::text::transaction_status_old; -- Drop the new column -ALTER TABLE public.submitter_transactions DROP COLUMN status; +ALTER TABLE submitter_transactions DROP COLUMN status; -- Rename the old column -ALTER TABLE public.submitter_transactions RENAME COLUMN status_old TO status; +ALTER TABLE submitter_transactions RENAME COLUMN status_old TO status; -- Drop new type DROP TYPE transaction_status; @@ -53,4 +53,4 @@ DROP TYPE transaction_status; ALTER TYPE transaction_status_old RENAME TO transaction_status; -- Restore index that was when we changed the enum type -CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_external_id ON public.submitter_transactions (external_id) WHERE status != 'ERROR'; +CREATE UNIQUE INDEX IF NOT EXISTS idx_unique_external_id ON submitter_transactions (external_id) WHERE status != 'ERROR'; diff --git a/internal/db/migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql b/db/migrations/sdp-migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql similarity index 92% rename from internal/db/migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql rename to db/migrations/sdp-migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql index 2cab0f39f..0466b4975 100644 --- a/internal/db/migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql +++ b/db/migrations/sdp-migrations/2023-07-17.2-add-status-history-column-submitter-transactions-table.sql @@ -18,13 +18,13 @@ RETURNS jsonb AS $$ $$ LANGUAGE plpgsql; -- +migrate StatementEnd -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ADD COLUMN status_history jsonb[] NULL DEFAULT ARRAY[create_submitter_transactions_status_history(NOW(), 'PENDING', NULL, NULL, NULL, NULL)]; -- +migrate Down -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions DROP COLUMN status_history; DROP FUNCTION IF EXISTS create_submitter_transactions_status_history; diff --git a/internal/db/migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql b/db/migrations/sdp-migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql similarity index 50% rename from internal/db/migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql rename to db/migrations/sdp-migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql index 03fac8593..6c818f372 100644 --- a/internal/db/migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql +++ b/db/migrations/sdp-migrations/2023-07-20.0-tss-remove-retry_after-and-rename-retry_count.sql @@ -3,28 +3,28 @@ -- +migrate Up -ALTER TABLE public.submitter_transactions DROP COLUMN retry_after; +ALTER TABLE submitter_transactions DROP COLUMN retry_after; -ALTER TABLE public.submitter_transactions RENAME COLUMN retry_count TO attempts_count; +ALTER TABLE submitter_transactions RENAME COLUMN retry_count TO attempts_count; -UPDATE public.submitter_transactions SET attempts_count = attempts_count + 1 WHERE status != 'PENDING'; +UPDATE submitter_transactions SET attempts_count = attempts_count + 1 WHERE status != 'PENDING'; --configuring the columns that were not properly configured: -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ALTER COLUMN destination TYPE VARCHAR(56), ALTER COLUMN status SET DEFAULT 'PENDING', ALTER COLUMN status SET NOT NULL; -- +migrate Down -ALTER TABLE public.submitter_transactions ADD COLUMN retry_after TIMESTAMPTZ; +ALTER TABLE submitter_transactions ADD COLUMN retry_after TIMESTAMPTZ; -ALTER TABLE public.submitter_transactions RENAME COLUMN attempts_count TO retry_count; +ALTER TABLE submitter_transactions RENAME COLUMN attempts_count TO retry_count; -UPDATE public.submitter_transactions SET retry_count = retry_count - 1 WHERE status != 'PENDING' AND retry_count > 0; +UPDATE submitter_transactions SET retry_count = retry_count - 1 WHERE status != 'PENDING' AND retry_count > 0; --reverting configuration for the columns that were not properly configured: -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ALTER COLUMN destination TYPE VARCHAR(64), ALTER COLUMN status DROP DEFAULT, ALTER COLUMN status DROP NOT NULL; diff --git a/internal/db/migrations/2023-08-02.0-organizations-table-add-approver-function.sql b/db/migrations/sdp-migrations/2023-08-02.0-organizations-table-add-approver-function.sql similarity index 67% rename from internal/db/migrations/2023-08-02.0-organizations-table-add-approver-function.sql rename to db/migrations/sdp-migrations/2023-08-02.0-organizations-table-add-approver-function.sql index 93ae0d640..0761e5af0 100644 --- a/internal/db/migrations/2023-08-02.0-organizations-table-add-approver-function.sql +++ b/db/migrations/sdp-migrations/2023-08-02.0-organizations-table-add-approver-function.sql @@ -1,12 +1,12 @@ -- +migrate Up -ALTER TABLE public.organizations +ALTER TABLE organizations ADD COLUMN is_approval_required boolean NOT NULL DEFAULT false; -COMMENT ON COLUMN public.organizations.is_approval_required +COMMENT ON COLUMN organizations.is_approval_required IS 'Column used to enable disbursement approval for organizations, requiring multiple users to start a disbursement.'; -- +migrate Down -ALTER TABLE public.organizations +ALTER TABLE organizations DROP COLUMN is_approval_required; diff --git a/internal/db/migrations/2023-08-10.0-countries-seed.sql b/db/migrations/sdp-migrations/2023-08-10.0-countries-seed.sql similarity index 99% rename from internal/db/migrations/2023-08-10.0-countries-seed.sql rename to db/migrations/sdp-migrations/2023-08-10.0-countries-seed.sql index 1b4bed857..34f18a034 100644 --- a/internal/db/migrations/2023-08-10.0-countries-seed.sql +++ b/db/migrations/sdp-migrations/2023-08-10.0-countries-seed.sql @@ -1,6 +1,6 @@ -- +migrate Up -INSERT INTO public.countries +INSERT INTO countries (code, name) VALUES ('AFG', 'Afghanistan'), @@ -216,6 +216,6 @@ ON CONFLICT DO NOTHING; -- +migrate Down DELETE FROM - public.countries + countries WHERE code NOT IN ('UKR', 'BRA', 'COL', 'USA'); diff --git a/internal/db/migrations/2023-08-15.0-alter-issuer-constraints.sql b/db/migrations/sdp-migrations/2023-08-15.0-alter-issuer-constraints.sql similarity index 80% rename from internal/db/migrations/2023-08-15.0-alter-issuer-constraints.sql rename to db/migrations/sdp-migrations/2023-08-15.0-alter-issuer-constraints.sql index 95b9d3057..7f7cdd70a 100644 --- a/internal/db/migrations/2023-08-15.0-alter-issuer-constraints.sql +++ b/db/migrations/sdp-migrations/2023-08-15.0-alter-issuer-constraints.sql @@ -1,17 +1,17 @@ -- +migrate Up -ALTER TABLE public.assets +ALTER TABLE assets DROP CONSTRAINT asset_issuer_length_check RESTRICT, ADD CONSTRAINT asset_issuer_length_check CHECK ((code = 'XLM' AND char_length(issuer) = 0) OR char_length(issuer) = 56); -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions ADD CONSTRAINT asset_issuer_length_check CHECK ((asset_code = 'XLM' AND char_length(asset_issuer) = 0) OR char_length(asset_issuer) = 56); -- +migrate Down -ALTER TABLE public.assets +ALTER TABLE assets DROP CONSTRAINT asset_issuer_length_check RESTRICT, ADD CONSTRAINT asset_issuer_length_check CHECK (char_length(issuer) = 56); -ALTER TABLE public.submitter_transactions +ALTER TABLE submitter_transactions DROP CONSTRAINT asset_issuer_length_check RESTRICT; diff --git a/db/migrations/sdp-migrations/2023-08-28.0-wallets-countries-and-assets.sql b/db/migrations/sdp-migrations/2023-08-28.0-wallets-countries-and-assets.sql new file mode 100644 index 000000000..31263ea3e --- /dev/null +++ b/db/migrations/sdp-migrations/2023-08-28.0-wallets-countries-and-assets.sql @@ -0,0 +1,11 @@ +-- +migrate Up + +CREATE TABLE wallets_assets ( + wallet_id VARCHAR(36) REFERENCES wallets (id), + asset_id VARCHAR(36) REFERENCES assets (id), + UNIQUE(wallet_id, asset_id) +); + +-- +migrate Down + +DROP TABLE wallets_assets; diff --git a/internal/db/migrations/2023-09-17.0-add-anchor-platform-tx-id.sql b/db/migrations/sdp-migrations/2023-09-17.0-add-anchor-platform-tx-id.sql similarity index 79% rename from internal/db/migrations/2023-09-17.0-add-anchor-platform-tx-id.sql rename to db/migrations/sdp-migrations/2023-09-17.0-add-anchor-platform-tx-id.sql index 64bbe0bc2..f37af8434 100644 --- a/internal/db/migrations/2023-09-17.0-add-anchor-platform-tx-id.sql +++ b/db/migrations/sdp-migrations/2023-09-17.0-add-anchor-platform-tx-id.sql @@ -2,11 +2,11 @@ -- +migrate Up -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN anchor_platform_transaction_id text; -- +migrate Down -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN anchor_platform_transaction_id; diff --git a/internal/db/migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql b/db/migrations/sdp-migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql similarity index 67% rename from internal/db/migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql rename to db/migrations/sdp-migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql index ea286b1f6..0760badee 100644 --- a/internal/db/migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql +++ b/db/migrations/sdp-migrations/2023-09-20.0-alter-wallets-add-enabled-column.sql @@ -1,9 +1,9 @@ -- +migrate Up -ALTER TABLE public.wallets +ALTER TABLE wallets ADD COLUMN enabled boolean NOT NULL DEFAULT true; -- +migrate Down -ALTER TABLE public.wallets +ALTER TABLE wallets DROP COLUMN enabled; diff --git a/internal/db/migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql b/db/migrations/sdp-migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql similarity index 88% rename from internal/db/migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql rename to db/migrations/sdp-migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql index c448238bd..1c8858fb3 100644 --- a/internal/db/migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql +++ b/db/migrations/sdp-migrations/2023-09-21.0-alter-organizations-table-invite-and-otp-messages.sql @@ -1,11 +1,11 @@ -- +migrate Up -ALTER TABLE public.organizations +ALTER TABLE organizations DROP CONSTRAINT organization_sms_registration_message_template_contains_tags_check, ADD COLUMN otp_message_template VARCHAR(255) NOT NULL DEFAULT '{{.OTP}} is your {{.OrganizationName}} phone verification code.'; -- +migrate Down -ALTER TABLE public.organizations +ALTER TABLE organizations DROP COLUMN otp_message_template, ADD CONSTRAINT organization_sms_registration_message_template_contains_tags_check CHECK (sms_registration_message_template LIKE '%{{.OrganizationName}}%' AND sms_registration_message_template LIKE '%{{.RegistrationLink}}%'); diff --git a/internal/db/migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql b/db/migrations/sdp-migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql similarity index 96% rename from internal/db/migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql rename to db/migrations/sdp-migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql index ccfa76f66..0db42c6dd 100644 --- a/internal/db/migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql +++ b/db/migrations/sdp-migrations/2023-09-26.0-fix-payment-status-history-and-remove-unused-org-columns.sql @@ -6,7 +6,7 @@ -- +migrate Up -- Remove unused column -ALTER TABLE public.organizations +ALTER TABLE organizations DROP COLUMN stellar_main_address, DROP COLUMN are_payments_enabled; @@ -62,6 +62,6 @@ FROM replaced WHERE payments.id = replaced.id; -- Add back the unused stellar_main_address column -ALTER TABLE public.organizations +ALTER TABLE organizations ADD COLUMN stellar_main_address VARCHAR(56), ADD COLUMN are_payments_enabled BOOLEAN NOT NULL DEFAULT FALSE; diff --git a/internal/db/migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql b/db/migrations/sdp-migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql similarity index 63% rename from internal/db/migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql rename to db/migrations/sdp-migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql index 315980924..c4545f78e 100644 --- a/internal/db/migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql +++ b/db/migrations/sdp-migrations/2023-10-05.0-alter-receiver_wallets-add-invitation_sent_at-column.sql @@ -1,11 +1,11 @@ -- +migrate Up ALTER TABLE - public.receiver_wallets + receiver_wallets ADD COLUMN invitation_sent_at timestamp with time zone; UPDATE - public.receiver_wallets + receiver_wallets SET invitation_sent_at = NOW() WHERE @@ -13,5 +13,5 @@ WHERE -- +migrate Down ALTER TABLE - public.receiver_wallets DROP COLUMN invitation_sent_at; + receiver_wallets DROP COLUMN invitation_sent_at; \ No newline at end of file diff --git a/internal/db/migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql b/db/migrations/sdp-migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql similarity index 70% rename from internal/db/migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql rename to db/migrations/sdp-migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql index 468ee20de..250e2bb70 100644 --- a/internal/db/migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql +++ b/db/migrations/sdp-migrations/2023-10-05.1-alter-receiver-wallets-add-anchor-platform-transaction-synced-at.sql @@ -1,9 +1,9 @@ -- +migrate Up -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets ADD COLUMN anchor_platform_transaction_synced_at TIMESTAMP WITH TIME ZONE NULL; -- +migrate Down -ALTER TABLE public.receiver_wallets +ALTER TABLE receiver_wallets DROP COLUMN anchor_platform_transaction_synced_at; diff --git a/internal/db/migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql b/db/migrations/sdp-migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql similarity index 84% rename from internal/db/migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql rename to db/migrations/sdp-migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql index 0f42dfbb1..cee23947b 100644 --- a/internal/db/migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql +++ b/db/migrations/sdp-migrations/2023-10-12.0.alter-organizations-table-add-sms-resend-interval.sql @@ -1,11 +1,11 @@ -- +migrate Up -ALTER TABLE public.organizations +ALTER TABLE organizations ADD COLUMN sms_resend_interval INTEGER NULL, ADD CONSTRAINT organization_sms_resend_interval_valid_value_check CHECK ((sms_resend_interval IS NOT NULL AND sms_resend_interval > 0) OR sms_resend_interval IS NULL); -- +migrate Down -ALTER TABLE public.organizations +ALTER TABLE organizations DROP CONSTRAINT organization_sms_resend_interval_valid_value_check, DROP COLUMN sms_resend_interval; diff --git a/stellar-auth/internal/db/migrations/main.go b/db/migrations/sdp-migrations/main.go similarity index 100% rename from stellar-auth/internal/db/migrations/main.go rename to db/migrations/sdp-migrations/main.go diff --git a/stellar-multitenant/internal/db/migrations/2023-10-16.0.add-tenants-table.sql b/db/migrations/tenant-migrations/2023-10-16.0.add-tenants-table.sql similarity index 87% rename from stellar-multitenant/internal/db/migrations/2023-10-16.0.add-tenants-table.sql rename to db/migrations/tenant-migrations/2023-10-16.0.add-tenants-table.sql index e71e24c8b..713970565 100644 --- a/stellar-multitenant/internal/db/migrations/2023-10-16.0.add-tenants-table.sql +++ b/db/migrations/tenant-migrations/2023-10-16.0.add-tenants-table.sql @@ -1,6 +1,7 @@ -- +migrate Up CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; +CREATE EXTENSION IF NOT EXISTS pgcrypto; -- +migrate StatementBegin CREATE OR REPLACE FUNCTION update_at_refresh() @@ -35,8 +36,8 @@ CREATE TABLE public.tenants CREATE UNIQUE INDEX idx_unique_name ON public.tenants (LOWER(name)); CREATE TRIGGER refresh_tenants_updated_at BEFORE UPDATE ON public.tenants FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); -COMMENT ON COLUMN tenants.base_url IS 'The SDP backend server''s base URL'; -COMMENT ON COLUMN tenants.sdp_ui_base_url IS 'The SDP UI/dashboard Base URL.'; +COMMENT ON COLUMN public.tenants.base_url IS 'The SDP backend server''s base URL'; +COMMENT ON COLUMN public.tenants.sdp_ui_base_url IS 'The SDP UI/dashboard Base URL.'; -- +migrate Down diff --git a/stellar-multitenant/internal/db/migrations/main.go b/db/migrations/tenant-migrations/main.go similarity index 100% rename from stellar-multitenant/internal/db/migrations/main.go rename to db/migrations/tenant-migrations/main.go diff --git a/internal/db/sql_exec_with_metrics.go b/db/sql_exec_with_metrics.go similarity index 100% rename from internal/db/sql_exec_with_metrics.go rename to db/sql_exec_with_metrics.go diff --git a/internal/db/sql_exec_with_metrics_test.go b/db/sql_exec_with_metrics_test.go similarity index 99% rename from internal/db/sql_exec_with_metrics_test.go rename to db/sql_exec_with_metrics_test.go index b2a38603a..aa97dd420 100644 --- a/internal/db/sql_exec_with_metrics_test.go +++ b/db/sql_exec_with_metrics_test.go @@ -5,7 +5,7 @@ import ( "fmt" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/internal/data/assets.go b/internal/data/assets.go index 9f3af6217..b36471f50 100644 --- a/internal/data/assets.go +++ b/internal/data/assets.go @@ -8,7 +8,7 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type Asset struct { diff --git a/internal/data/assets_test.go b/internal/data/assets_test.go index 962ceedcb..650b7d551 100644 --- a/internal/data/assets_test.go +++ b/internal/data/assets_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/data/countries.go b/internal/data/countries.go index 56adb420b..d05eed75a 100644 --- a/internal/data/countries.go +++ b/internal/data/countries.go @@ -7,7 +7,7 @@ import ( "fmt" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type Country struct { diff --git a/internal/data/countries_test.go b/internal/data/countries_test.go index d688ae0a7..21f79e848 100644 --- a/internal/data/countries_test.go +++ b/internal/data/countries_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/data/disbursement_instructions.go b/internal/data/disbursement_instructions.go index 1fd794772..b0b5aa780 100644 --- a/internal/data/disbursement_instructions.go +++ b/internal/data/disbursement_instructions.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type DisbursementInstruction struct { diff --git a/internal/data/disbursement_instructions_test.go b/internal/data/disbursement_instructions_test.go index 21ab1d2e8..7f81f8095 100644 --- a/internal/data/disbursement_instructions_test.go +++ b/internal/data/disbursement_instructions_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/data/disbursement_receivers.go b/internal/data/disbursement_receivers.go index 4d450e875..b6cfa6353 100644 --- a/internal/data/disbursement_receivers.go +++ b/internal/data/disbursement_receivers.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type DisbursementReceiver struct { diff --git a/internal/data/disbursement_receivers_test.go b/internal/data/disbursement_receivers_test.go index dbf0d1df5..ee3c830b5 100644 --- a/internal/data/disbursement_receivers_test.go +++ b/internal/data/disbursement_receivers_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/internal/data/disbursements.go b/internal/data/disbursements.go index 0f45264d0..4d31aa3e1 100644 --- a/internal/data/disbursements.go +++ b/internal/data/disbursements.go @@ -12,7 +12,7 @@ import ( "github.com/lib/pq" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type Disbursement struct { diff --git a/internal/data/disbursements_test.go b/internal/data/disbursements_test.go index 012da6fa7..7fdc8ccfb 100644 --- a/internal/data/disbursements_test.go +++ b/internal/data/disbursements_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/data/fixtures.go b/internal/data/fixtures.go index cff9c5e4b..035dcf56c 100644 --- a/internal/data/fixtures.go +++ b/internal/data/fixtures.go @@ -15,7 +15,7 @@ import ( "github.com/lib/pq" "github.com/stellar/go/keypair" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/require" diff --git a/internal/data/fixtures_test.go b/internal/data/fixtures_test.go index f48136f00..e29ead1a5 100644 --- a/internal/data/fixtures_test.go +++ b/internal/data/fixtures_test.go @@ -5,8 +5,8 @@ import ( "strings" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/internal/data/messages.go b/internal/data/messages.go index fed5c3473..4c1a384ea 100644 --- a/internal/data/messages.go +++ b/internal/data/messages.go @@ -9,7 +9,7 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" ) diff --git a/internal/data/messages_test.go b/internal/data/messages_test.go index cfd65fa43..edd6fc33b 100644 --- a/internal/data/messages_test.go +++ b/internal/data/messages_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/data/models.go b/internal/data/models.go index e8946829c..20a552a79 100644 --- a/internal/data/models.go +++ b/internal/data/models.go @@ -3,7 +3,7 @@ package data import ( "errors" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ( diff --git a/internal/data/models_test.go b/internal/data/models_test.go index 6f8b00830..f5570771c 100644 --- a/internal/data/models_test.go +++ b/internal/data/models_test.go @@ -3,8 +3,8 @@ package data import ( "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/internal/data/organizations.go b/internal/data/organizations.go index 20cdcb956..728fbf856 100644 --- a/internal/data/organizations.go +++ b/internal/data/organizations.go @@ -18,7 +18,7 @@ import ( "strings" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) const ( diff --git a/internal/data/organizations_test.go b/internal/data/organizations_test.go index 688f9a611..41aca2106 100644 --- a/internal/data/organizations_test.go +++ b/internal/data/organizations_test.go @@ -9,8 +9,8 @@ import ( "image/png" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/data/payments.go b/internal/data/payments.go index 070f69a59..1b990371d 100644 --- a/internal/data/payments.go +++ b/internal/data/payments.go @@ -13,7 +13,7 @@ import ( "github.com/stellar/go/support/log" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/data/payments_test.go b/internal/data/payments_test.go index 9ef564cf3..451d69a2a 100644 --- a/internal/data/payments_test.go +++ b/internal/data/payments_test.go @@ -6,8 +6,8 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/data/receiver_verification.go b/internal/data/receiver_verification.go index d85a25502..026fc24aa 100644 --- a/internal/data/receiver_verification.go +++ b/internal/data/receiver_verification.go @@ -10,7 +10,7 @@ import ( "github.com/stellar/go/support/log" "golang.org/x/crypto/bcrypt" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type ReceiverVerification struct { diff --git a/internal/data/receiver_verification_test.go b/internal/data/receiver_verification_test.go index 9e1238c51..8b4f997de 100644 --- a/internal/data/receiver_verification_test.go +++ b/internal/data/receiver_verification_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/data/receivers.go b/internal/data/receivers.go index 3e77b5418..1fabdd831 100644 --- a/internal/data/receivers.go +++ b/internal/data/receivers.go @@ -11,7 +11,7 @@ import ( "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/data/receivers_test.go b/internal/data/receivers_test.go index a43162c0c..af4ff6ab8 100644 --- a/internal/data/receivers_test.go +++ b/internal/data/receivers_test.go @@ -8,8 +8,8 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" diff --git a/internal/data/receivers_wallet.go b/internal/data/receivers_wallet.go index f7b2c8aa7..aec018161 100644 --- a/internal/data/receivers_wallet.go +++ b/internal/data/receivers_wallet.go @@ -13,7 +13,7 @@ import ( "github.com/stellar/go/network" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) const OTPExpirationTimeMinutes = 30 diff --git a/internal/data/receivers_wallet_test.go b/internal/data/receivers_wallet_test.go index d7c4db953..4764456c5 100644 --- a/internal/data/receivers_wallet_test.go +++ b/internal/data/receivers_wallet_test.go @@ -7,8 +7,8 @@ import ( "time" "github.com/stellar/go/network" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" diff --git a/internal/data/wallets.go b/internal/data/wallets.go index 588b9837f..0d220111d 100644 --- a/internal/data/wallets.go +++ b/internal/data/wallets.go @@ -9,7 +9,7 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ( diff --git a/internal/data/wallets_test.go b/internal/data/wallets_test.go index 0f25b1c3a..6121dd5ec 100644 --- a/internal/data/wallets_test.go +++ b/internal/data/wallets_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/db/db_test.go b/internal/db/db_test.go deleted file mode 100644 index ef4fa41fd..000000000 --- a/internal/db/db_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package db - -import ( - "testing" - - "github.com/stellar/go/support/db/dbtest" - "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOpen_OpenDBConnectionPool(t *testing.T) { - db := dbtest.Postgres(t) - defer db.Close() - - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - assert.Equal(t, "postgres", dbConnectionPool.DriverName()) - - err = dbConnectionPool.Ping() - require.NoError(t, err) -} - -func TestOpen_OpenDBConnectionPoolWithMetrics(t *testing.T) { - db := dbtest.Postgres(t) - defer db.Close() - - mMonitorService := &monitor.MockMonitorService{} - - dbConnectionPoolWithMetrics, err := OpenDBConnectionPoolWithMetrics(db.DSN, mMonitorService) - require.NoError(t, err) - defer dbConnectionPoolWithMetrics.Close() - - assert.Equal(t, "postgres", dbConnectionPoolWithMetrics.DriverName()) - - err = dbConnectionPoolWithMetrics.Ping() - require.NoError(t, err) -} diff --git a/internal/db/dbtest/dbtest.go b/internal/db/dbtest/dbtest.go deleted file mode 100644 index 0042fd9ac..000000000 --- a/internal/db/dbtest/dbtest.go +++ /dev/null @@ -1,31 +0,0 @@ -package dbtest - -import ( - "net/http" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/go/support/db/dbtest" - "github.com/stellar/go/support/db/schema" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/migrations" -) - -func OpenWithoutMigrations(t *testing.T) *dbtest.DB { - db := dbtest.Postgres(t) - return db -} - -func Open(t *testing.T) *dbtest.DB { - db := OpenWithoutMigrations(t) - - conn := db.Open() - defer conn.Close() - - migrateDirection := schema.MigrateUp - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} - _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) - if err != nil { - t.Fatal(err) - } - return db -} diff --git a/internal/db/dbtest/dbtest_test.go b/internal/db/dbtest/dbtest_test.go deleted file mode 100644 index 95f6213b1..000000000 --- a/internal/db/dbtest/dbtest_test.go +++ /dev/null @@ -1,18 +0,0 @@ -package dbtest - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOpen(t *testing.T) { - db := Open(t) - session := db.Open() - - count := 0 - err := session.Get(&count, `SELECT COUNT(*) FROM gorp_migrations`) - require.NoError(t, err) - assert.Greater(t, count, 0) -} diff --git a/internal/db/migrate.go b/internal/db/migrate.go deleted file mode 100644 index ae00e2b6d..000000000 --- a/internal/db/migrate.go +++ /dev/null @@ -1,22 +0,0 @@ -package db - -import ( - "fmt" - "net/http" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/migrations" - "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" -) - -func Migrate(dbURL string, dir migrate.MigrationDirection, count int) (int, error) { - dbConnectionPool, err := OpenDBConnectionPool(dbURL) - if err != nil { - return 0, fmt.Errorf("database URL '%s': %w", utils.TruncateString(dbURL, len(dbURL)/4), err) - } - defer dbConnectionPool.Close() - - ms := migrate.MigrationSet{} - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} - return ms.ExecMax(dbConnectionPool.SqlDB(), dbConnectionPool.DriverName(), m, dir, count) -} diff --git a/internal/db/migrate_test.go b/internal/db/migrate_test.go deleted file mode 100644 index 476383684..000000000 --- a/internal/db/migrate_test.go +++ /dev/null @@ -1,86 +0,0 @@ -package db - -import ( - "context" - "io/fs" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/migrations" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMigrate_upApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 1) - require.NoError(t, err) - assert.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, `SELECT id FROM gorp_migrations`) - require.NoError(t, err) - wantIDs := []string{"2023-01-20.0-initial.sql"} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_downApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 2) - require.NoError(t, err) - require.Equal(t, 2, n) - - n, err = Migrate(db.DSN, migrate.Down, 1) - require.NoError(t, err) - require.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, `SELECT id FROM gorp_migrations`) - require.NoError(t, err) - wantIDs := []string{"2023-01-20.0-initial.sql"} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_upDownAll(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - // Get number of files in the migrations directory: - var count int - err = fs.WalkDir(migrations.FS, ".", func(path string, d fs.DirEntry, err error) error { - require.NoError(t, err) - if !d.IsDir() { - count++ - } - return nil - }) - require.NoError(t, err) - - n, err := Migrate(db.DSN, migrate.Up, count) - require.NoError(t, err) - require.Equal(t, count, n) - - // TODO: fix DB transactions to make sure we can migrate down all the way - migrateDownCount := count - 6 - n, err = Migrate(db.DSN, migrate.Down, migrateDownCount) - require.NoError(t, err) - require.Equal(t, migrateDownCount, n) -} diff --git a/internal/db/migrations/2023-01-23.0-dump-from-sdp-v1.sql b/internal/db/migrations/2023-01-23.0-dump-from-sdp-v1.sql deleted file mode 100644 index 2e4f7f0f1..000000000 --- a/internal/db/migrations/2023-01-23.0-dump-from-sdp-v1.sql +++ /dev/null @@ -1,372 +0,0 @@ --- This migration file is meant to reproduce the database schema from the SDP v1, so we can support users that --- are on SDP v1 to migrate to SDP v2. - --- +migrate Up - - -------------------------------------------------- START DJANGO MODELS ------------------------------------------------- - --- TABLE: auth_group -CREATE TABLE IF NOT EXISTS public.auth_group ( - id SERIAL PRIMARY KEY, - name character varying(150) NOT NULL -); -CREATE UNIQUE INDEX IF NOT EXISTS auth_group_name_a6ea08ec_like ON public.auth_group (name varchar_pattern_ops); -ALTER INDEX auth_group_name_a6ea08ec_like RENAME TO auth_group_name_idx; - - --- TABLE: django_content_type -CREATE TABLE IF NOT EXISTS public.django_content_type ( - id SERIAL PRIMARY KEY, - app_label character varying(100) NOT NULL, - model character varying(100) NOT NULL, - UNIQUE (app_label, model) -); - -INSERT INTO public.django_content_type VALUES (1, 'admin', 'logentry') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (2, 'auth', 'permission') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (3, 'auth', 'group') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (4, 'auth', 'user') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (5, 'contenttypes', 'contenttype') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (6, 'sessions', 'session') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (7, 'payments', 'account') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (8, 'payments', 'disbursement') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (9, 'payments', 'heartbeat') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (10, 'payments', 'payment') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (11, 'payments', 'activation') ON CONFLICT (id) DO NOTHING; -INSERT INTO public.django_content_type VALUES (12, 'payments', 'withdrawal') ON CONFLICT (id) DO NOTHING; - - --- TABLE: auth_permission -CREATE TABLE IF NOT EXISTS public.auth_permission ( - id SERIAL PRIMARY KEY, - name character varying(255) NOT NULL, - content_type_id integer NOT NULL REFERENCES public.django_content_type (id) DEFERRABLE INITIALLY DEFERRED, - codename character varying(100) NOT NULL, - UNIQUE (content_type_id, codename) -); -CREATE INDEX IF NOT EXISTS auth_permission_content_type_id_2f476e4b ON public.auth_permission USING btree (content_type_id); -ALTER INDEX auth_permission_content_type_id_2f476e4b RENAME TO auth_permission_content_type_id_idx; - -INSERT INTO public.auth_permission VALUES (1, 'Can add log entry', 1, 'add_logentry') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (2, 'Can change log entry', 1, 'change_logentry') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (3, 'Can delete log entry', 1, 'delete_logentry') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (4, 'Can view log entry', 1, 'view_logentry') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (5, 'Can add permission', 2, 'add_permission') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (6, 'Can change permission', 2, 'change_permission') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (7, 'Can delete permission', 2, 'delete_permission') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (8, 'Can view permission', 2, 'view_permission') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (9, 'Can add group', 3, 'add_group') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (10, 'Can change group', 3, 'change_group') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (11, 'Can delete group', 3, 'delete_group') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (12, 'Can view group', 3, 'view_group') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (13, 'Can add user', 4, 'add_user') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (14, 'Can change user', 4, 'change_user') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (15, 'Can delete user', 4, 'delete_user') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (16, 'Can view user', 4, 'view_user') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (17, 'Can add content type', 5, 'add_contenttype') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (18, 'Can change content type', 5, 'change_contenttype') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (19, 'Can delete content type', 5, 'delete_contenttype') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (20, 'Can view content type', 5, 'view_contenttype') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (21, 'Can add session', 6, 'add_session') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (22, 'Can change session', 6, 'change_session') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (23, 'Can delete session', 6, 'delete_session') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (24, 'Can view session', 6, 'view_session') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (25, 'Can add account', 7, 'add_account') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (26, 'Can change account', 7, 'change_account') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (27, 'Can delete account', 7, 'delete_account') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (28, 'Can view account', 7, 'view_account') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (29, 'Can add disbursement', 8, 'add_disbursement') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (30, 'Can change disbursement', 8, 'change_disbursement') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (31, 'Can delete disbursement', 8, 'delete_disbursement') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (32, 'Can view disbursement', 8, 'view_disbursement') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (33, 'Can add heart beat', 9, 'add_heartbeat') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (34, 'Can change heart beat', 9, 'change_heartbeat') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (35, 'Can delete heart beat', 9, 'delete_heartbeat') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (36, 'Can view heart beat', 9, 'view_heartbeat') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (37, 'Can add payment', 10, 'add_payment') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (38, 'Can change payment', 10, 'change_payment') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (39, 'Can delete payment', 10, 'delete_payment') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (40, 'Can view payment', 10, 'view_payment') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (41, 'Can add activation', 11, 'add_activation') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (42, 'Can change activation', 11, 'change_activation') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (43, 'Can delete activation', 11, 'delete_activation') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (44, 'Can view activation', 11, 'view_activation') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (45, 'Can add withdrawal', 12, 'add_withdrawal') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (46, 'Can change withdrawal', 12, 'change_withdrawal') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (47, 'Can delete withdrawal', 12, 'delete_withdrawal') ON CONFLICT DO NOTHING; -INSERT INTO public.auth_permission VALUES (48, 'Can view withdrawal', 12, 'view_withdrawal') ON CONFLICT DO NOTHING; - - --- TABLE: auth_group_permissions -CREATE TABLE IF NOT EXISTS public.auth_group_permissions ( - id BIGSERIAL PRIMARY KEY, - group_id integer NOT NULL REFERENCES public.auth_group (id) DEFERRABLE INITIALLY DEFERRED, - permission_id integer NOT NULL REFERENCES public.auth_permission (id) DEFERRABLE INITIALLY DEFERRED, - UNIQUE (group_id, permission_id) -); -CREATE INDEX IF NOT EXISTS auth_group_permissions_group_id_b120cbf9 ON public.auth_group_permissions USING btree (group_id); -ALTER INDEX auth_group_permissions_group_id_b120cbf9 RENAME TO auth_group_permissions_group_id_idx; - -CREATE INDEX IF NOT EXISTS auth_group_permissions_permission_id_84c5c92e ON public.auth_group_permissions USING btree (permission_id); -ALTER INDEX auth_group_permissions_permission_id_84c5c92e RENAME TO auth_group_permissions_permission_id_idx; - - --- TABLE: auth_user -CREATE TABLE IF NOT EXISTS public.auth_user ( - id SERIAL PRIMARY KEY, - password character varying(128) NOT NULL, - last_login timestamp with time zone, - is_superuser boolean NOT NULL, - username character varying(150) NOT NULL, - first_name character varying(150) NOT NULL, - last_name character varying(150) NOT NULL, - email character varying(254) NOT NULL, - is_staff boolean NOT NULL, - is_active boolean NOT NULL, - date_joined timestamp with time zone NOT NULL, - UNIQUE (username) -); -CREATE INDEX IF NOT EXISTS auth_user_username_6821ab7c_like ON public.auth_user USING btree (username varchar_pattern_ops); -ALTER INDEX auth_user_username_6821ab7c_like RENAME TO auth_user_username_idx; - - --- TABLE: auth_user_groups -CREATE TABLE IF NOT EXISTS public.auth_user_groups ( - id BIGSERIAL PRIMARY KEY, - user_id integer NOT NULL REFERENCES public.auth_user (id) DEFERRABLE INITIALLY DEFERRED, - group_id integer NOT NULL REFERENCES public.auth_group (id) DEFERRABLE INITIALLY DEFERRED, - UNIQUE (user_id, group_id) -); -CREATE INDEX IF NOT EXISTS auth_user_groups_group_id_97559544 ON public.auth_user_groups USING btree (group_id); -ALTER INDEX auth_user_groups_group_id_97559544 RENAME TO auth_user_groups_group_id_idx; - -CREATE INDEX IF NOT EXISTS auth_user_groups_user_id_6a12ed8b ON public.auth_user_groups USING btree (user_id); -ALTER INDEX auth_user_groups_user_id_6a12ed8b RENAME TO auth_user_groups_user_id_idx; - - --- TABLE: auth_user_user_permissions -CREATE TABLE IF NOT EXISTS public.auth_user_user_permissions ( - id BIGSERIAL PRIMARY KEY, - user_id integer NOT NULL REFERENCES public.auth_user (id) DEFERRABLE INITIALLY DEFERRED, - permission_id integer NOT NULL REFERENCES public.auth_permission (id) DEFERRABLE INITIALLY DEFERRED, - UNIQUE (user_id, permission_id) -); -CREATE INDEX IF NOT EXISTS auth_user_user_permissions_permission_id_1fbb5f2c ON public.auth_user_user_permissions USING btree (permission_id); -ALTER INDEX auth_user_user_permissions_permission_id_1fbb5f2c RENAME TO auth_user_user_permissions_permission_id_idx; - -CREATE INDEX IF NOT EXISTS auth_user_user_permissions_user_id_a95ead1b ON public.auth_user_user_permissions USING btree (user_id); -ALTER INDEX auth_user_user_permissions_user_id_a95ead1b RENAME TO auth_user_user_permissions_user_id_idx; - - --- TABLE: django_admin_log -CREATE TABLE IF NOT EXISTS public.django_admin_log ( - id SERIAL PRIMARY KEY, - action_time timestamp with time zone NOT NULL, - object_id text, - object_repr character varying(200) NOT NULL, - action_flag smallint NOT NULL, - change_message text NOT NULL, - content_type_id integer REFERENCES public.django_content_type(id) DEFERRABLE INITIALLY DEFERRED, - user_id integer NOT NULL REFERENCES public.auth_user(id) DEFERRABLE INITIALLY DEFERRED, - CONSTRAINT django_admin_log_action_flag_check CHECK ((action_flag >= 0)) -); -CREATE INDEX IF NOT EXISTS django_admin_log_content_type_id_c4bce8eb ON public.django_admin_log USING btree (content_type_id); -ALTER INDEX django_admin_log_content_type_id_c4bce8eb RENAME TO django_admin_log_content_type_id_idx; - -CREATE INDEX IF NOT EXISTS django_admin_log_user_id_c564eba6 ON public.django_admin_log USING btree (user_id); -ALTER INDEX django_admin_log_user_id_c564eba6 RENAME TO django_admin_log_user_id_idx; - - --- TABLE: django_content_type -CREATE TABLE IF NOT EXISTS public.django_migrations ( - id BIGSERIAL PRIMARY KEY, - app character varying(255) NOT NULL, - name character varying(255) NOT NULL, - applied timestamp with time zone NOT NULL -); - -INSERT INTO public.django_migrations VALUES (1, 'contenttypes', '0001_initial', '2023-01-04 16:05:52.644099-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (2, 'auth', '0001_initial', '2023-01-04 16:05:52.711348-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (3, 'admin', '0001_initial', '2023-01-04 16:05:52.731795-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (4, 'admin', '0002_logentry_remove_auto_add', '2023-01-04 16:05:52.742003-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (5, 'admin', '0003_logentry_add_action_flag_choices', '2023-01-04 16:05:52.752853-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (6, 'contenttypes', '0002_remove_content_type_name', '2023-01-04 16:05:52.770614-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (7, 'auth', '0002_alter_permission_name_max_length', '2023-01-04 16:05:52.780492-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (8, 'auth', '0003_alter_user_email_max_length', '2023-01-04 16:05:52.791342-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (9, 'auth', '0004_alter_user_username_opts', '2023-01-04 16:05:52.802137-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (10, 'auth', '0005_alter_user_last_login_null', '2023-01-04 16:05:52.811967-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (11, 'auth', '0006_require_contenttypes_0002', '2023-01-04 16:05:52.814286-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (12, 'auth', '0007_alter_validators_add_error_messages', '2023-01-04 16:05:52.824612-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (13, 'auth', '0008_alter_user_username_max_length', '2023-01-04 16:05:52.835405-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (14, 'auth', '0009_alter_user_last_name_max_length', '2023-01-04 16:05:52.846608-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (15, 'auth', '0010_alter_group_name_max_length', '2023-01-04 16:05:52.858149-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (16, 'auth', '0011_update_proxy_permissions', '2023-01-04 16:05:52.867694-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (17, 'auth', '0012_alter_user_first_name_max_length', '2023-01-04 16:05:52.879894-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (18, 'payments', '0001_initial', '2023-01-04 16:05:52.947015-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (19, 'payments', '0002_remove_disbursement_requested_by_and_more', '2023-01-04 16:05:52.985496-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (20, 'payments', '0003_remove_disbursement_amount_and_more', '2023-01-04 16:05:53.040818-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (21, 'payments', '0004_account_link_last_sent_at', '2023-01-04 16:05:53.051175-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (22, 'payments', '0005_account_date_of_birth_account_email_and_more', '2023-01-04 16:05:53.079481-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (23, 'payments', '0006_payment_idempotency_key_alter_account_status', '2023-01-04 16:05:53.09219-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (24, 'payments', '0007_rename_hashed_date_of_birth_account_hashed_extra_info_and_more', '2023-01-04 16:05:53.108973-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (25, 'payments', '0008_activation', '2023-01-04 16:05:53.132048-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (26, 'payments', '0009_add_yubikey_validation_service', '2023-01-04 16:05:53.146663-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (27, 'payments', '0010_alter_account_phone_number', '2023-01-04 16:05:53.155158-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (28, 'payments', '0011_alter_payment_status', '2023-01-04 16:05:53.160529-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (29, 'payments', '0012_alter_payment_amount', '2023-01-04 16:05:53.173929-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (30, 'payments', '0013_withdrawal_alter_account_status_and_more', '2023-01-04 16:05:53.211413-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (31, 'payments', '0014_payment_withdrawal_amount_payment_withdrawal_status', '2023-01-04 16:05:53.228509-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (32, 'payments', '0015_rename_stellar_transaction_id_withdrawal_sep24_transaction_id', '2023-01-04 16:05:53.237819-08') ON CONFLICT DO NOTHING; -INSERT INTO public.django_migrations VALUES (33, 'sessions', '0001_initial', '2023-01-04 16:05:53.247677-08') ON CONFLICT DO NOTHING; - - --- TABLE: django_session -CREATE TABLE IF NOT EXISTS public.django_session ( - session_key character varying(40) NOT NULL PRIMARY KEY, - session_data text NOT NULL, - expire_date timestamp with time zone NOT NULL -); -CREATE INDEX IF NOT EXISTS django_session_expire_date_a5c62663 ON public.django_session USING btree (expire_date); -ALTER INDEX django_session_expire_date_a5c62663 RENAME TO django_session_expire_date_idx; - -CREATE INDEX IF NOT EXISTS django_session_session_key_c0390e0f_like ON public.django_session USING btree (session_key varchar_pattern_ops); -ALTER INDEX django_session_session_key_c0390e0f_like RENAME TO django_session_session_key_idx; - -------------------------------------------------- FINISH DJANGO MODELS ------------------------------------------------- - - -------------------------------------------------- START OF SDP MODELS ------------------------------------------------- - --- TABLE: receiver (previously known as payments_account) -CREATE TABLE IF NOT EXISTS public.payments_account ( - id character varying(64) NOT NULL PRIMARY KEY, - public_key character varying(128), - registered_at timestamp with time zone NOT NULL, - phone_number character varying(32) NOT NULL, - public_key_registered_at timestamp with time zone, - status character varying(32) NOT NULL, - link_last_sent_at timestamp with time zone, - email character varying(254), - email_registered_at timestamp with time zone, - hashed_extra_info character varying(64) NOT NULL, - hashed_phone_number character varying(64) NOT NULL, - extra_info character varying(64) NOT NULL, - UNIQUE (phone_number) -); -CREATE INDEX IF NOT EXISTS payments_ac_hashed__f9420c_idx ON public.payments_account USING btree (hashed_phone_number, hashed_extra_info); -ALTER INDEX payments_ac_hashed__f9420c_idx RENAME TO receiver_hashed_phone_and_hashed_extra_info_idx; - -CREATE INDEX IF NOT EXISTS payments_account_phone_number_221a9f17_like ON public.payments_account USING btree (phone_number varchar_pattern_ops); -ALTER INDEX payments_account_phone_number_221a9f17_like RENAME TO receiver_phone_number_idx; - -CREATE INDEX IF NOT EXISTS payments_ac_registe_104353_idx ON public.payments_account USING btree (registered_at DESC); -ALTER INDEX payments_ac_registe_104353_idx RENAME TO receiver_registered_at_idx; - -ALTER TABLE payments_account RENAME TO receivers; - - --- TABLE: on_off_switch (previously known as payments_activation) -CREATE TABLE IF NOT EXISTS public.payments_activation ( - id BIGSERIAL PRIMARY KEY, - is_active boolean NOT NULL, - last_set_at timestamp with time zone NOT NULL DEFAULT NOW() -); -INSERT INTO public.payments_activation VALUES (1, true, NOW()) ON CONFLICT DO NOTHING; - -ALTER TABLE payments_activation RENAME TO on_off_switch; - - --- TABLE: disbursement (previously known as payments_disbursement) -CREATE TABLE IF NOT EXISTS public.payments_disbursement ( - id character varying(64) NOT NULL PRIMARY KEY, - requested_at timestamp with time zone NOT NULL -); -CREATE INDEX IF NOT EXISTS payments_di_request_16523d_idx ON public.payments_disbursement USING btree (requested_at DESC); -ALTER INDEX payments_di_request_16523d_idx RENAME TO disbursement_request_16523d_idx; - -ALTER TABLE payments_disbursement RENAME TO disbursements; - - --- TABLE: payments_semaphore (previously known as payments_heartbeat) -CREATE TABLE IF NOT EXISTS public.payments_heartbeat ( - id BIGSERIAL PRIMARY KEY, - name character varying(128) NOT NULL, - last_beat timestamp with time zone NOT NULL -); -ALTER TABLE payments_heartbeat RENAME TO payments_semaphore; - - --- TABLE: payment (previously known as payments_payment) -CREATE TABLE IF NOT EXISTS public.payments_payment ( - id character varying(64) NOT NULL PRIMARY KEY, - stellar_transaction_id character varying(64), - custodial_payment_id text, - status character varying(32) NOT NULL, - status_message text, - requested_at timestamp with time zone NOT NULL, - started_at timestamp with time zone, - completed_at timestamp with time zone, - account_id character varying(64) NOT NULL REFERENCES public.receivers(id) DEFERRABLE INITIALLY DEFERRED, - disbursement_id character varying(64) NOT NULL REFERENCES public.disbursements(id) DEFERRABLE INITIALLY DEFERRED, - amount numeric(7,2) NOT NULL, - idempotency_key character varying(64) NOT NULL, - withdrawal_amount numeric(7,2) NOT NULL, - withdrawal_status character varying(32) NOT NULL -); -CREATE INDEX IF NOT EXISTS payments_pa_request_4ce797_idx ON public.payments_payment USING btree (requested_at DESC); -ALTER INDEX payments_pa_request_4ce797_idx RENAME TO payment_requested_at_idx; - -CREATE INDEX IF NOT EXISTS payments_payment_account_id_af225a32 ON public.payments_payment USING btree (account_id); -ALTER INDEX payments_payment_account_id_af225a32 RENAME TO payment_account_id_idx; - -CREATE INDEX IF NOT EXISTS payments_payment_account_id_af225a32_like ON public.payments_payment USING btree (account_id varchar_pattern_ops); -ALTER INDEX payments_payment_account_id_af225a32_like RENAME TO payment_account_id_like_idx; - -CREATE INDEX IF NOT EXISTS payments_payment_disbursement_id_2a817b83 ON public.payments_payment USING btree (disbursement_id); -ALTER INDEX payments_payment_disbursement_id_2a817b83 RENAME TO payment_disbursement_id_idx; - -ALTER TABLE payments_payment RENAME TO payments; - - --- TABLE: payments_withdrawal -CREATE TABLE IF NOT EXISTS public.payments_withdrawal ( - sep24_transaction_id character varying(64) NOT NULL PRIMARY KEY, - anchor_id character varying(64) NOT NULL, - amount numeric(7,2) NOT NULL, - started_at timestamp with time zone NOT NULL, - completed_at timestamp with time zone NOT NULL, - created_at timestamp with time zone NOT NULL, - account_id character varying(64) NOT NULL REFERENCES public.receivers (id) DEFERRABLE INITIALLY DEFERRED -); -CREATE INDEX IF NOT EXISTS payments_wi_created_18b04a_idx ON public.payments_withdrawal USING btree (created_at DESC); -ALTER INDEX payments_wi_created_18b04a_idx RENAME TO withdrawal_created_at_idx; - -CREATE INDEX IF NOT EXISTS payments_withdrawal_account_id_ec0819dd ON public.payments_withdrawal USING btree (account_id); -ALTER INDEX payments_withdrawal_account_id_ec0819dd RENAME TO withdrawal_account_id_idx; - -CREATE INDEX IF NOT EXISTS payments_withdrawal_account_id_ec0819dd_like ON public.payments_withdrawal USING btree (account_id varchar_pattern_ops); -ALTER INDEX payments_withdrawal_account_id_ec0819dd_like RENAME TO withdrawal_account_id_like_idx; - -ALTER TABLE payments_withdrawal RENAME TO withdrawal; - - --- +migrate Down - -DROP TABLE IF EXISTS public.withdrawal CASCADE; -- Called 'payments_withdrawal' in SDP-v1 -DROP TABLE IF EXISTS public.payments CASCADE; -- Called 'payments_payment' in SDP-v1 -DROP TABLE IF EXISTS public.payments_semaphore CASCADE; -- Called 'payments_heartbeat' in SDP-v1 -DROP TABLE IF EXISTS public.disbursements CASCADE; -- Called 'payments_disbursement' in SDP-v1 -DROP TABLE IF EXISTS public.on_off_switch CASCADE; -- Called 'payments_activation' in SDP-v1 -DROP TABLE IF EXISTS public.receivers CASCADE; -- Called 'payments_account' in SDP-v1 - -DROP TABLE IF EXISTS public.django_session CASCADE; -DROP TABLE IF EXISTS public.django_migrations CASCADE; -DROP TABLE IF EXISTS public.django_admin_log CASCADE; -DROP TABLE IF EXISTS public.auth_user_user_permissions CASCADE; -DROP TABLE IF EXISTS public.auth_user_groups CASCADE; -DROP TABLE IF EXISTS public.auth_user CASCADE; -DROP TABLE IF EXISTS public.auth_group_permissions CASCADE; -DROP TABLE IF EXISTS public.auth_permission CASCADE; -DROP TABLE IF EXISTS public.django_content_type CASCADE; -DROP TABLE IF EXISTS public.auth_group CASCADE; diff --git a/internal/db/migrations/2023-01-26.0-delete-all-django-stuff.sql b/internal/db/migrations/2023-01-26.0-delete-all-django-stuff.sql deleted file mode 100644 index 54c57df6e..000000000 --- a/internal/db/migrations/2023-01-26.0-delete-all-django-stuff.sql +++ /dev/null @@ -1,33 +0,0 @@ --- This migration dumps all django-related stuff that was in the database of the SDP v1. - - --- +migrate Up - -DROP TABLE IF EXISTS public.django_session CASCADE; -DROP TABLE IF EXISTS public.django_migrations CASCADE; -DROP TABLE IF EXISTS public.django_admin_log CASCADE; -DROP TABLE IF EXISTS public.auth_user_user_permissions CASCADE; -DROP TABLE IF EXISTS public.auth_user_groups CASCADE; -DROP TABLE IF EXISTS public.auth_user CASCADE; -DROP TABLE IF EXISTS public.auth_group_permissions CASCADE; -DROP TABLE IF EXISTS public.auth_permission CASCADE; -DROP TABLE IF EXISTS public.django_content_type CASCADE; -DROP TABLE IF EXISTS public.auth_group CASCADE; -DROP TABLE IF EXISTS public.otp_static_staticdevice CASCADE; -DROP TABLE IF EXISTS public.otp_static_statictoken CASCADE; -DROP TABLE IF EXISTS public.otp_totp_totpdevice CASCADE; -DROP TABLE IF EXISTS public.otp_yubikey_remoteyubikeydevice CASCADE; -DROP TABLE IF EXISTS public.otp_yubikey_validationservice CASCADE; -DROP TABLE IF EXISTS public.otp_yubikey_yubikeydevice CASCADE; -DROP TABLE IF EXISTS public.two_factor_phonedevice CASCADE; - -DROP SEQUENCE IF EXISTS public.otp_static_staticdevice_id_seq CASCADE; -DROP SEQUENCE IF EXISTS public.otp_static_statictoken_id_seq CASCADE; -DROP SEQUENCE IF EXISTS public.otp_totp_totpdevice_id_seq CASCADE; -DROP SEQUENCE IF EXISTS public.otp_yubikey_remoteyubikeydevice_id_seq CASCADE; -DROP SEQUENCE IF EXISTS public.otp_yubikey_validationservice_id_seq CASCADE; -DROP SEQUENCE IF EXISTS public.otp_yubikey_yubikeydevice_id_seq CASCADE; - - --- +migrate Down - diff --git a/internal/db/migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql b/internal/db/migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql deleted file mode 100644 index 36832adec..000000000 --- a/internal/db/migrations/2023-01-26.1-drop-unused-sdp-v1-tables.sql +++ /dev/null @@ -1,21 +0,0 @@ --- This migration dumps all django-related stuff that was in the database of the SDP v1. - - --- +migrate Up - -DROP TABLE IF EXISTS public.on_off_switch CASCADE; -DROP TABLE IF EXISTS public.payments_semaphore CASCADE; -ALTER TABLE public.withdrawal RENAME COLUMN account_id TO receiver_id; - --- +migrate StatementBegin --- Delete withdrawal table if it is empty -DO $$ -BEGIN - IF (SELECT COUNT(*) FROM public.withdrawal) = 0 THEN - EXECUTE 'DROP TABLE public.withdrawal'; - END IF; -END $$; --- +migrate StatementEnd - - --- +migrate Down diff --git a/internal/db/migrations/2023-01-27.0-create-assets-table.sql b/internal/db/migrations/2023-01-27.0-create-assets-table.sql deleted file mode 100644 index 42da65ce6..000000000 --- a/internal/db/migrations/2023-01-27.0-create-assets-table.sql +++ /dev/null @@ -1,45 +0,0 @@ --- This creates the assets table and updates the other tables that depend on it. - --- +migrate Up - -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; - -CREATE TABLE public.assets ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), - code VARCHAR(12) NOT NULL, - issuer VARCHAR(56) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - deleted_at TIMESTAMP WITH TIME ZONE, - UNIQUE (code, issuer), - CONSTRAINT asset_issuer_length_check CHECK (char_length(issuer) = 56) -); -INSERT INTO public.assets (code, issuer) VALUES ('USDC', 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); - -ALTER TABLE public.disbursements - ADD COLUMN asset_id VARCHAR(36), - ADD CONSTRAINT fk_disbursement_asset_id FOREIGN KEY (asset_id) REFERENCES public.assets (id); -UPDATE public.disbursements SET asset_id = (SELECT id FROM public.assets WHERE code = 'USDC' AND issuer = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); -ALTER TABLE public.disbursements ALTER COLUMN asset_id SET NOT NULL; - -ALTER TABLE public.payments - ADD COLUMN asset_id VARCHAR(36), - ADD CONSTRAINT fk_payment_asset_id FOREIGN KEY (asset_id) REFERENCES public.assets (id); -UPDATE public.payments SET asset_id = (SELECT id FROM public.assets WHERE code = 'USDC' AND issuer = 'GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5'); -ALTER TABLE public.payments ALTER COLUMN asset_id SET NOT NULL; - --- TRIGGER: updated_at -CREATE TRIGGER refresh_asset_updated_at BEFORE UPDATE ON public.assets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); - - --- +migrate Down - -DROP TRIGGER refresh_asset_updated_at ON public.assets; - -ALTER TABLE public.payments DROP COLUMN asset_id; - -ALTER TABLE public.disbursements DROP COLUMN asset_id; - -DROP TABLE public.assets CASCADE; - -DROP EXTENSION IF EXISTS "uuid-ossp"; diff --git a/internal/db/migrations/2023-01-27.1-create-countries-table.sql b/internal/db/migrations/2023-01-27.1-create-countries-table.sql deleted file mode 100644 index 0b818532c..000000000 --- a/internal/db/migrations/2023-01-27.1-create-countries-table.sql +++ /dev/null @@ -1,29 +0,0 @@ --- This creates the countries table and updates the other tables that depend on it. - --- +migrate Up - -CREATE TABLE public.countries ( - code VARCHAR(3) PRIMARY KEY, - name VARCHAR(100) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - deleted_at TIMESTAMP WITH TIME ZONE, - UNIQUE (name), - CONSTRAINT country_code_length_check CHECK (char_length(code) = 3) -); -INSERT INTO public.countries (code, name) VALUES ('UKR', 'Ukraine'); - -ALTER TABLE public.disbursements - ADD COLUMN country_code VARCHAR(3), - ADD CONSTRAINT fk_disbursement_country_code FOREIGN KEY (country_code) REFERENCES public.countries (code); -UPDATE public.disbursements SET country_code = 'UKR'; -ALTER TABLE public.disbursements ALTER COLUMN country_code SET NOT NULL; - -CREATE TRIGGER refresh_country_updated_at BEFORE UPDATE ON public.countries FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); - --- +migrate Down -DROP TRIGGER refresh_country_updated_at ON public.countries; - -ALTER TABLE public.disbursements DROP COLUMN country_code; - -DROP TABLE public.countries CASCADE; diff --git a/internal/db/migrations/2023-01-27.2-create-wallets-table.sql b/internal/db/migrations/2023-01-27.2-create-wallets-table.sql deleted file mode 100644 index 5ad0a77e9..000000000 --- a/internal/db/migrations/2023-01-27.2-create-wallets-table.sql +++ /dev/null @@ -1,34 +0,0 @@ --- This creates the wallets table and updates the other tables that depend on it. - --- +migrate Up - -CREATE TABLE public.wallets ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), - name VARCHAR(30) NOT NULL, - homepage VARCHAR(255) NOT NULL, - deep_link_schema VARCHAR(30) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - deleted_at TIMESTAMP WITH TIME ZONE, - UNIQUE (name), - UNIQUE (homepage), - UNIQUE (deep_link_schema) -); --- TODO: keep in mind that the deep link `vibrantapp://` is not confirmed yet and is subject to change. -INSERT INTO public.wallets (name, homepage, deep_link_schema) VALUES ('Vibrant Assist', 'https://vibrantapp.com', 'https://vibrantapp.com/sdp-dev'); - -ALTER TABLE public.disbursements - ADD COLUMN wallet_id VARCHAR(36), - ADD CONSTRAINT fk_disbursement_wallet_id FOREIGN KEY (wallet_id) REFERENCES public.wallets (id); -UPDATE public.disbursements SET wallet_id = (SELECT id FROM public.wallets WHERE name = 'Vibrant Assist'); -ALTER TABLE public.disbursements ALTER COLUMN wallet_id SET NOT NULL; - -CREATE TRIGGER refresh_wallet_updated_at BEFORE UPDATE ON public.wallets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); - - --- +migrate Down -DROP TRIGGER refresh_wallet_updated_at ON public.wallets; - -ALTER TABLE public.disbursements DROP COLUMN wallet_id; - -DROP TABLE public.wallets CASCADE; diff --git a/internal/db/migrations/2023-01-27.3-create-receiver-wallets-table.sql b/internal/db/migrations/2023-01-27.3-create-receiver-wallets-table.sql deleted file mode 100644 index fdb6169ec..000000000 --- a/internal/db/migrations/2023-01-27.3-create-receiver-wallets-table.sql +++ /dev/null @@ -1,37 +0,0 @@ --- This creates the receiver_wallets table and updates the other tables that depend on it. - --- +migrate Up - --- Table: receiver_wallets -CREATE TABLE public.receiver_wallets ( - id VARCHAR(36) PRIMARY KEY DEFAULT uuid_generate_v4(), - receiver_id VARCHAR(36) NOT NULL REFERENCES public.receivers (id), - wallet_id VARCHAR(36) REFERENCES public.wallets (id), - stellar_address VARCHAR(56), - stellar_memo VARCHAR(56), - stellar_memo_type VARCHAR(56), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), - UNIQUE (receiver_id, wallet_id) -); -INSERT - INTO receiver_wallets (receiver_id, stellar_address) - (SELECT id, public_key FROM receivers); -UPDATE public.receiver_wallets SET wallet_id = (SELECT id FROM public.wallets WHERE name = 'Vibrant Assist'); -ALTER TABLE public.receiver_wallets ALTER COLUMN wallet_id SET NOT NULL; - --- Table: receivers -ALTER TABLE public.receivers DROP COLUMN public_key; - -CREATE TRIGGER refresh_receiver_wallet_updated_at BEFORE UPDATE ON public.receiver_wallets FOR EACH ROW EXECUTE PROCEDURE update_at_refresh(); - - --- +migrate Down -DROP TRIGGER refresh_receiver_wallet_updated_at ON public.receiver_wallets; - --- Table: receivers -ALTER TABLE public.receivers ADD COLUMN public_key VARCHAR(128); -UPDATE public.receivers SET public_key = (SELECT stellar_address FROM public.receiver_wallets WHERE receiver_id = public.receivers.id); - --- Table: receiver_wallets -DROP TABLE public.receiver_wallets CASCADE; diff --git a/internal/db/migrations/2023-04-26.0-add-demo-wallet.sql b/internal/db/migrations/2023-04-26.0-add-demo-wallet.sql deleted file mode 100644 index 806b4cd77..000000000 --- a/internal/db/migrations/2023-04-26.0-add-demo-wallet.sql +++ /dev/null @@ -1,12 +0,0 @@ --- This migration creates the sep_10_client_domain column in the public.wallets table and inserts the demo-wallet in the DB. - --- +migrate Up - -ALTER TABLE public.wallets ADD COLUMN sep_10_client_domain VARCHAR(255) DEFAULT '' NOT NULL; - -UPDATE public.wallets SET sep_10_client_domain = substring(homepage from 'https?://([^/]+)'); -UPDATE public.wallets SET sep_10_client_domain = 'api-dev.vibrantapp.com' WHERE name = 'Vibrant Assist'; -ALTER TABLE public.wallets ALTER COLUMN deep_link_schema TYPE VARCHAR(255); - --- +migrate Down -ALTER TABLE public.wallets DROP COLUMN sep_10_client_domain; diff --git a/internal/db/migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql b/internal/db/migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql deleted file mode 100644 index a5f03ae03..000000000 --- a/internal/db/migrations/2023-06-22.0-add-unique-constraint-wallet-table.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +migrate Up - -CREATE UNIQUE INDEX unique_wallets_index ON public.wallets(name, homepage, deep_link_schema); - --- +migrate Down - -DROP INDEX IF EXISTS unique_wallets_index; diff --git a/internal/db/migrations/2023-08-28.0-wallets-countries-and-assets.sql b/internal/db/migrations/2023-08-28.0-wallets-countries-and-assets.sql deleted file mode 100644 index 562f8fc38..000000000 --- a/internal/db/migrations/2023-08-28.0-wallets-countries-and-assets.sql +++ /dev/null @@ -1,11 +0,0 @@ --- +migrate Up - -CREATE TABLE public.wallets_assets ( - wallet_id VARCHAR(36) REFERENCES public.wallets (id), - asset_id VARCHAR(36) REFERENCES public.assets (id), - UNIQUE(wallet_id, asset_id) -); - --- +migrate Down - -DROP TABLE public.wallets_assets; diff --git a/internal/integrationtests/integration_tests.go b/internal/integrationtests/integration_tests.go index 477b537e6..7f95fcf73 100644 --- a/internal/integrationtests/integration_tests.go +++ b/internal/integrationtests/integration_tests.go @@ -7,8 +7,8 @@ import ( "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httphandler" tss "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" diff --git a/internal/integrationtests/validations.go b/internal/integrationtests/validations.go index 5adc1582f..6b980554a 100644 --- a/internal/integrationtests/validations.go +++ b/internal/integrationtests/validations.go @@ -4,8 +4,8 @@ import ( "context" "fmt" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" ) func validateExpectationsAfterProcessDisbursement(ctx context.Context, disbursementID string, models *data.Models, sqlExec db.SQLExecuter) error { diff --git a/internal/integrationtests/validations_test.go b/internal/integrationtests/validations_test.go index e272c7ece..c00e6d757 100644 --- a/internal/integrationtests/validations_test.go +++ b/internal/integrationtests/validations_test.go @@ -4,9 +4,9 @@ import ( "context" "testing" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/internal/scheduler/jobs/patch_anchor_platform_transactions_job_test.go b/internal/scheduler/jobs/patch_anchor_platform_transactions_job_test.go index f79fe4856..102926b03 100644 --- a/internal/scheduler/jobs/patch_anchor_platform_transactions_job_test.go +++ b/internal/scheduler/jobs/patch_anchor_platform_transactions_job_test.go @@ -10,10 +10,10 @@ import ( "github.com/lib/pq" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/scheduler/jobs/send_receiver_wallets_sms_invitation_job_test.go b/internal/scheduler/jobs/send_receiver_wallets_sms_invitation_job_test.go index 3c7e18f9f..2fc61b171 100644 --- a/internal/scheduler/jobs/send_receiver_wallets_sms_invitation_job_test.go +++ b/internal/scheduler/jobs/send_receiver_wallets_sms_invitation_job_test.go @@ -9,10 +9,10 @@ import ( "testing" "time" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/services" "github.com/stretchr/testify/assert" diff --git a/internal/serve/httphandler/assets_handler.go b/internal/serve/httphandler/assets_handler.go index 3a610c5d8..027a56519 100644 --- a/internal/serve/httphandler/assets_handler.go +++ b/internal/serve/httphandler/assets_handler.go @@ -18,8 +18,8 @@ import ( "github.com/stellar/go/support/render/httpjson" "github.com/stellar/go/txnbuild" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" diff --git a/internal/serve/httphandler/assets_handler_test.go b/internal/serve/httphandler/assets_handler_test.go index d39241e89..20a51bda9 100644 --- a/internal/serve/httphandler/assets_handler_test.go +++ b/internal/serve/httphandler/assets_handler_test.go @@ -27,9 +27,9 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine/mocks" ) diff --git a/internal/serve/httphandler/countries_handler_test.go b/internal/serve/httphandler/countries_handler_test.go index a7cb668fe..e390fc84b 100644 --- a/internal/serve/httphandler/countries_handler_test.go +++ b/internal/serve/httphandler/countries_handler_test.go @@ -8,9 +8,9 @@ import ( "net/http/httptest" "testing" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/httphandler/delete_phone_number_handler_test.go b/internal/serve/httphandler/delete_phone_number_handler_test.go index 27591ee76..67a8c895f 100644 --- a/internal/serve/httphandler/delete_phone_number_handler_test.go +++ b/internal/serve/httphandler/delete_phone_number_handler_test.go @@ -8,9 +8,9 @@ import ( "github.com/go-chi/chi/v5" "github.com/stellar/go/network" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/httphandler/disbursement_handler.go b/internal/serve/httphandler/disbursement_handler.go index 1b9af8a78..547b3de03 100644 --- a/internal/serve/httphandler/disbursement_handler.go +++ b/internal/serve/httphandler/disbursement_handler.go @@ -14,8 +14,8 @@ import ( "github.com/stellar/go/support/log" "github.com/stellar/go/support/render/httpjson" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpresponse" diff --git a/internal/serve/httphandler/disbursement_handler_test.go b/internal/serve/httphandler/disbursement_handler_test.go index 23d88159a..969dab43e 100644 --- a/internal/serve/httphandler/disbursement_handler_test.go +++ b/internal/serve/httphandler/disbursement_handler_test.go @@ -27,8 +27,8 @@ import ( "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpresponse" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" diff --git a/internal/serve/httphandler/forgot_password_handler_test.go b/internal/serve/httphandler/forgot_password_handler_test.go index 92fc8d934..808018760 100644 --- a/internal/serve/httphandler/forgot_password_handler_test.go +++ b/internal/serve/httphandler/forgot_password_handler_test.go @@ -12,9 +12,9 @@ import ( "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stretchr/testify/mock" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/htmltemplate" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" diff --git a/internal/serve/httphandler/login_handler_test.go b/internal/serve/httphandler/login_handler_test.go index caf2217a8..7b310c929 100644 --- a/internal/serve/httphandler/login_handler_test.go +++ b/internal/serve/httphandler/login_handler_test.go @@ -8,9 +8,9 @@ import ( "strings" "testing" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/htmltemplate" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" diff --git a/internal/serve/httphandler/mfa_handler_test.go b/internal/serve/httphandler/mfa_handler_test.go index a955388cc..098f911b6 100644 --- a/internal/serve/httphandler/mfa_handler_test.go +++ b/internal/serve/httphandler/mfa_handler_test.go @@ -12,9 +12,9 @@ import ( "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" "github.com/stretchr/testify/mock" diff --git a/internal/serve/httphandler/payments_handler.go b/internal/serve/httphandler/payments_handler.go index d3263ecfe..0d26652b4 100644 --- a/internal/serve/httphandler/payments_handler.go +++ b/internal/serve/httphandler/payments_handler.go @@ -10,8 +10,8 @@ import ( "github.com/stellar/go/support/http/httpdecode" "github.com/stellar/go/support/render/httpjson" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpresponse" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/middleware" diff --git a/internal/serve/httphandler/payments_handler_test.go b/internal/serve/httphandler/payments_handler_test.go index 617733fe5..d9240cd0c 100644 --- a/internal/serve/httphandler/payments_handler_test.go +++ b/internal/serve/httphandler/payments_handler_test.go @@ -13,9 +13,9 @@ import ( "time" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpresponse" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/middleware" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" diff --git a/internal/serve/httphandler/profile_handler_test.go b/internal/serve/httphandler/profile_handler_test.go index 78ae698ff..27cd250ba 100644 --- a/internal/serve/httphandler/profile_handler_test.go +++ b/internal/serve/httphandler/profile_handler_test.go @@ -19,9 +19,9 @@ import ( "github.com/stellar/go/keypair" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/middleware" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/publicfiles" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" diff --git a/internal/serve/httphandler/receiver_handler.go b/internal/serve/httphandler/receiver_handler.go index 3f6c3d896..666a68c03 100644 --- a/internal/serve/httphandler/receiver_handler.go +++ b/internal/serve/httphandler/receiver_handler.go @@ -7,8 +7,8 @@ import ( "github.com/go-chi/chi/v5" "github.com/stellar/go/support/render/httpjson" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpresponse" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" diff --git a/internal/serve/httphandler/receiver_handler_test.go b/internal/serve/httphandler/receiver_handler_test.go index eef3de650..fd4be22eb 100644 --- a/internal/serve/httphandler/receiver_handler_test.go +++ b/internal/serve/httphandler/receiver_handler_test.go @@ -11,9 +11,9 @@ import ( "time" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" diff --git a/internal/serve/httphandler/receiver_registration_test.go b/internal/serve/httphandler/receiver_registration_test.go index ccf05521c..d61d9968f 100644 --- a/internal/serve/httphandler/receiver_registration_test.go +++ b/internal/serve/httphandler/receiver_registration_test.go @@ -10,10 +10,10 @@ import ( "github.com/go-chi/chi/v5" "github.com/golang-jwt/jwt/v4" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/httphandler/receiver_send_otp_handler_test.go b/internal/serve/httphandler/receiver_send_otp_handler_test.go index 6be199eee..81b81d27d 100644 --- a/internal/serve/httphandler/receiver_send_otp_handler_test.go +++ b/internal/serve/httphandler/receiver_send_otp_handler_test.go @@ -14,10 +14,10 @@ import ( "github.com/go-chi/chi/v5" "github.com/golang-jwt/jwt/v4" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stretchr/testify/assert" diff --git a/internal/serve/httphandler/receiver_wallets_handler_test.go b/internal/serve/httphandler/receiver_wallets_handler_test.go index 9f18a07f5..7eb3523b0 100644 --- a/internal/serve/httphandler/receiver_wallets_handler_test.go +++ b/internal/serve/httphandler/receiver_wallets_handler_test.go @@ -9,9 +9,9 @@ import ( "time" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/httphandler/statistics_handler.go b/internal/serve/httphandler/statistics_handler.go index 3ebf6c8bb..dde6eb878 100644 --- a/internal/serve/httphandler/statistics_handler.go +++ b/internal/serve/httphandler/statistics_handler.go @@ -7,7 +7,7 @@ import ( "github.com/go-chi/chi/v5" "github.com/stellar/go/support/render/httpjson" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/statistics" ) diff --git a/internal/serve/httphandler/statistics_handler_test.go b/internal/serve/httphandler/statistics_handler_test.go index 597d3792e..b8b01278f 100644 --- a/internal/serve/httphandler/statistics_handler_test.go +++ b/internal/serve/httphandler/statistics_handler_test.go @@ -8,9 +8,9 @@ import ( "testing" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/serve/httphandler/stellar_toml_handler_test.go b/internal/serve/httphandler/stellar_toml_handler_test.go index 3bba23d43..cf3d27d78 100644 --- a/internal/serve/httphandler/stellar_toml_handler_test.go +++ b/internal/serve/httphandler/stellar_toml_handler_test.go @@ -10,9 +10,9 @@ import ( "github.com/go-chi/chi/v5" "github.com/stellar/go/network" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/httphandler/update_receiver_handler.go b/internal/serve/httphandler/update_receiver_handler.go index eabbbca72..4fc7a9715 100644 --- a/internal/serve/httphandler/update_receiver_handler.go +++ b/internal/serve/httphandler/update_receiver_handler.go @@ -8,8 +8,8 @@ import ( "github.com/stellar/go/support/http/httpdecode" "github.com/stellar/go/support/log" "github.com/stellar/go/support/render/httpjson" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" ) diff --git a/internal/serve/httphandler/update_receiver_handler_test.go b/internal/serve/httphandler/update_receiver_handler_test.go index 8fb14dd6c..d5c95964f 100644 --- a/internal/serve/httphandler/update_receiver_handler_test.go +++ b/internal/serve/httphandler/update_receiver_handler_test.go @@ -11,9 +11,9 @@ import ( "testing" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/serve/httphandler/user_handler_test.go b/internal/serve/httphandler/user_handler_test.go index ede35bd76..f287f7cc5 100644 --- a/internal/serve/httphandler/user_handler_test.go +++ b/internal/serve/httphandler/user_handler_test.go @@ -12,9 +12,9 @@ import ( "github.com/go-chi/chi/v5" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/htmltemplate" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" diff --git a/internal/serve/httphandler/verifiy_receiver_registration_handler.go b/internal/serve/httphandler/verifiy_receiver_registration_handler.go index 6acd64646..04e1ac303 100644 --- a/internal/serve/httphandler/verifiy_receiver_registration_handler.go +++ b/internal/serve/httphandler/verifiy_receiver_registration_handler.go @@ -10,9 +10,9 @@ import ( "github.com/stellar/go/support/log" "github.com/stellar/go/support/render/httpjson" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" diff --git a/internal/serve/httphandler/verifiy_receiver_registration_handler_test.go b/internal/serve/httphandler/verifiy_receiver_registration_handler_test.go index 17303dbdc..c2846228d 100644 --- a/internal/serve/httphandler/verifiy_receiver_registration_handler_test.go +++ b/internal/serve/httphandler/verifiy_receiver_registration_handler_test.go @@ -20,10 +20,10 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httperror" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/validators" ) diff --git a/internal/serve/httphandler/wallets_handler_test.go b/internal/serve/httphandler/wallets_handler_test.go index 0dd579330..bf0daf3dd 100644 --- a/internal/serve/httphandler/wallets_handler_test.go +++ b/internal/serve/httphandler/wallets_handler_test.go @@ -11,9 +11,9 @@ import ( "testing" "github.com/go-chi/chi/v5" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/serve/serve.go b/internal/serve/serve.go index afe12ccae..800d485c9 100644 --- a/internal/serve/serve.go +++ b/internal/serve/serve.go @@ -14,10 +14,10 @@ import ( supporthttp "github.com/stellar/go/support/http" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" @@ -31,6 +31,7 @@ import ( txnsubmitterutils "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/utils" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" + "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/tenant" ) const ServiceID = "serve" @@ -94,6 +95,8 @@ func (opts *ServeOptions) SetupDependencies() error { // Set crash tracker LogAndReportErrors as DefaultReportErrorFunc httperror.SetDefaultReportErrorFunc(opts.CrashTrackerClient.LogAndReportErrors) + _ = tenant.Tenant{} + // Setup Database: dbConnectionPool, err := db.OpenDBConnectionPoolWithMetrics(opts.DatabaseDSN, opts.MonitorService) if err != nil { diff --git a/internal/serve/serve_test.go b/internal/serve/serve_test.go index f4638e81a..9114ce67c 100644 --- a/internal/serve/serve_test.go +++ b/internal/serve/serve_test.go @@ -12,10 +12,10 @@ import ( "github.com/stellar/go/keypair" "github.com/stellar/go/network" supporthttp "github.com/stellar/go/support/http" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" publicfiles "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/publicfiles" diff --git a/internal/services/disbursement_management_service.go b/internal/services/disbursement_management_service.go index bfc3d4a42..3d91bea71 100644 --- a/internal/services/disbursement_management_service.go +++ b/internal/services/disbursement_management_service.go @@ -6,8 +6,8 @@ import ( "errors" "fmt" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/middleware" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" @@ -59,6 +59,7 @@ func (s *DisbursementManagementService) GetDisbursementsWithCount(ctx context.Co return utils.NewResultWithTotal(totalDisbursements, disbursements), nil }) + } func (s *DisbursementManagementService) GetDisbursementReceiversWithCount(ctx context.Context, disbursementID string, queryParams *data.QueryParams) (*utils.ResultWithTotal, error) { diff --git a/internal/services/disbursement_management_service_test.go b/internal/services/disbursement_management_service_test.go index 01fda0940..18b6c87db 100644 --- a/internal/services/disbursement_management_service_test.go +++ b/internal/services/disbursement_management_service_test.go @@ -7,9 +7,9 @@ import ( "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/middleware" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/internal/services/patch_anchor_platform_transactions_completion.go b/internal/services/patch_anchor_platform_transactions_completion.go index a7757c385..61efea74b 100644 --- a/internal/services/patch_anchor_platform_transactions_completion.go +++ b/internal/services/patch_anchor_platform_transactions_completion.go @@ -6,9 +6,9 @@ import ( "sort" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" ) type PatchAnchorPlatformTransactionCompletionService struct { diff --git a/internal/services/patch_anchor_platform_transactions_completion_test.go b/internal/services/patch_anchor_platform_transactions_completion_test.go index 2a2a7f9dc..626d076b0 100644 --- a/internal/services/patch_anchor_platform_transactions_completion_test.go +++ b/internal/services/patch_anchor_platform_transactions_completion_test.go @@ -8,10 +8,10 @@ import ( "github.com/lib/pq" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/anchorplatform" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/services/payment_from_submitter_service.go b/internal/services/payment_from_submitter_service.go index 05ee81b9c..069e38dbb 100644 --- a/internal/services/payment_from_submitter_service.go +++ b/internal/services/payment_from_submitter_service.go @@ -6,8 +6,8 @@ import ( "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" txSubStore "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" ) diff --git a/internal/services/payment_from_submitter_service_test.go b/internal/services/payment_from_submitter_service_test.go index 5386d2a96..93ec87b99 100644 --- a/internal/services/payment_from_submitter_service_test.go +++ b/internal/services/payment_from_submitter_service_test.go @@ -12,9 +12,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" txSubStore "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" ) diff --git a/internal/services/payment_to_submitter_service.go b/internal/services/payment_to_submitter_service.go index 56855f05b..339598ea1 100644 --- a/internal/services/payment_to_submitter_service.go +++ b/internal/services/payment_to_submitter_service.go @@ -8,8 +8,8 @@ import ( "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" txSubStore "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/services/payment_to_submitter_service_test.go b/internal/services/payment_to_submitter_service_test.go index e214b8918..9f4aba595 100644 --- a/internal/services/payment_to_submitter_service_test.go +++ b/internal/services/payment_to_submitter_service_test.go @@ -8,9 +8,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" txSubStore "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" ) diff --git a/internal/services/send_receiver_wallets_invite_service.go b/internal/services/send_receiver_wallets_invite_service.go index e8422b6aa..1b7b105f7 100644 --- a/internal/services/send_receiver_wallets_invite_service.go +++ b/internal/services/send_receiver_wallets_invite_service.go @@ -11,9 +11,9 @@ import ( "github.com/stellar/go/strkey" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "golang.org/x/exp/slices" diff --git a/internal/services/send_receiver_wallets_invite_service_test.go b/internal/services/send_receiver_wallets_invite_service_test.go index 719577a94..acb84a5b7 100644 --- a/internal/services/send_receiver_wallets_invite_service_test.go +++ b/internal/services/send_receiver_wallets_invite_service_test.go @@ -8,10 +8,10 @@ import ( "time" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/message" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" diff --git a/internal/services/setup_assets_for_network_service.go b/internal/services/setup_assets_for_network_service.go index b608b40d6..bbd8aecd6 100644 --- a/internal/services/setup_assets_for_network_service.go +++ b/internal/services/setup_assets_for_network_service.go @@ -7,8 +7,8 @@ import ( "github.com/lib/pq" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/services/setup_assets_for_network_service_test.go b/internal/services/setup_assets_for_network_service_test.go index 14bd3620f..f74c0ae93 100644 --- a/internal/services/setup_assets_for_network_service_test.go +++ b/internal/services/setup_assets_for_network_service_test.go @@ -8,9 +8,9 @@ import ( "github.com/stellar/go/keypair" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/services/setup_wallets_for_network_service.go b/internal/services/setup_wallets_for_network_service.go index 4a8e18807..75f9572a5 100644 --- a/internal/services/setup_wallets_for_network_service.go +++ b/internal/services/setup_wallets_for_network_service.go @@ -9,8 +9,8 @@ import ( "github.com/lib/pq" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/services/setup_wallets_for_network_service_test.go b/internal/services/setup_wallets_for_network_service_test.go index 708a51916..08fe109a9 100644 --- a/internal/services/setup_wallets_for_network_service_test.go +++ b/internal/services/setup_wallets_for_network_service_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/stellar/go/support/log" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/statistics/calculate_statistics.go b/internal/statistics/calculate_statistics.go index f06603f34..694ae70a5 100644 --- a/internal/statistics/calculate_statistics.go +++ b/internal/statistics/calculate_statistics.go @@ -7,8 +7,8 @@ import ( "strconv" "strings" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/statistics/calculate_statistics_test.go b/internal/statistics/calculate_statistics_test.go index cca1ee486..2965e789d 100644 --- a/internal/statistics/calculate_statistics_test.go +++ b/internal/statistics/calculate_statistics_test.go @@ -5,9 +5,9 @@ import ( "encoding/json" "testing" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/internal/transactionsubmission/engine/signature_service.go b/internal/transactionsubmission/engine/signature_service.go index 86ad12849..afa3bc513 100644 --- a/internal/transactionsubmission/engine/signature_service.go +++ b/internal/transactionsubmission/engine/signature_service.go @@ -9,7 +9,7 @@ import ( "github.com/stellar/go/strkey" "github.com/stellar/go/txnbuild" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/utils" ) diff --git a/internal/transactionsubmission/engine/signature_service_test.go b/internal/transactionsubmission/engine/signature_service_test.go index 7ddcfe337..9f368ef17 100644 --- a/internal/transactionsubmission/engine/signature_service_test.go +++ b/internal/transactionsubmission/engine/signature_service_test.go @@ -8,8 +8,8 @@ import ( "github.com/stellar/go/keypair" "github.com/stellar/go/network" "github.com/stellar/go/txnbuild" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/utils" "github.com/stretchr/testify/assert" diff --git a/internal/transactionsubmission/horizon_test.go b/internal/transactionsubmission/horizon_test.go index 481dbe3d4..0aa9f039d 100644 --- a/internal/transactionsubmission/horizon_test.go +++ b/internal/transactionsubmission/horizon_test.go @@ -15,8 +15,8 @@ import ( "github.com/stellar/go/strkey" "github.com/stellar/go/support/render/problem" "github.com/stellar/go/txnbuild" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" engineMocks "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine/mocks" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" diff --git a/internal/transactionsubmission/manager.go b/internal/transactionsubmission/manager.go index 7a4dc71e5..01fc0628f 100644 --- a/internal/transactionsubmission/manager.go +++ b/internal/transactionsubmission/manager.go @@ -15,8 +15,8 @@ import ( "github.com/stellar/go/support/log" "github.com/stellar/go/txnbuild" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" tssMonitor "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/monitor" diff --git a/internal/transactionsubmission/manager_test.go b/internal/transactionsubmission/manager_test.go index 63a5831f3..2a01bea05 100644 --- a/internal/transactionsubmission/manager_test.go +++ b/internal/transactionsubmission/manager_test.go @@ -13,9 +13,9 @@ import ( "github.com/stellar/go/protocols/horizon" "github.com/stellar/go/support/log" "github.com/stellar/go/txnbuild" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" monitorMocks "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor/mocks" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" diff --git a/internal/transactionsubmission/scripts/tss_payments_loadtest.go b/internal/transactionsubmission/scripts/tss_payments_loadtest.go index 2c60b4369..8d0fa1a96 100644 --- a/internal/transactionsubmission/scripts/tss_payments_loadtest.go +++ b/internal/transactionsubmission/scripts/tss_payments_loadtest.go @@ -11,7 +11,7 @@ import ( "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/protocols/horizon" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" ) diff --git a/internal/transactionsubmission/services/channel_account_service.go b/internal/transactionsubmission/services/channel_account_service.go index 3c5f1d330..543931417 100644 --- a/internal/transactionsubmission/services/channel_account_service.go +++ b/internal/transactionsubmission/services/channel_account_service.go @@ -7,7 +7,7 @@ import ( "github.com/stellar/go/clients/horizonclient" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" txSub "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" diff --git a/internal/transactionsubmission/services/channel_accounts_service_test.go b/internal/transactionsubmission/services/channel_accounts_service_test.go index b2ba4172b..85994d602 100644 --- a/internal/transactionsubmission/services/channel_accounts_service_test.go +++ b/internal/transactionsubmission/services/channel_accounts_service_test.go @@ -16,8 +16,8 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" engineMocks "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine/mocks" diff --git a/internal/transactionsubmission/store/channel_account.go b/internal/transactionsubmission/store/channel_account.go index f6a70817b..430505e0e 100644 --- a/internal/transactionsubmission/store/channel_account.go +++ b/internal/transactionsubmission/store/channel_account.go @@ -9,8 +9,8 @@ import ( "github.com/lib/pq" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/data" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" ) type ChannelAccount struct { diff --git a/internal/transactionsubmission/store/channel_account_test.go b/internal/transactionsubmission/store/channel_account_test.go index e5e2e615e..6d002b85c 100644 --- a/internal/transactionsubmission/store/channel_account_test.go +++ b/internal/transactionsubmission/store/channel_account_test.go @@ -8,8 +8,8 @@ import ( "time" "github.com/stellar/go/keypair" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/transactionsubmission/store/channel_transaction_bundle.go b/internal/transactionsubmission/store/channel_transaction_bundle.go index fbb439f86..2a57d8aee 100644 --- a/internal/transactionsubmission/store/channel_transaction_bundle.go +++ b/internal/transactionsubmission/store/channel_transaction_bundle.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ErrInsuficientChannelAccounts = fmt.Errorf("there are no channel accounts available to process transactions") diff --git a/internal/transactionsubmission/store/channel_transaction_bundle_test.go b/internal/transactionsubmission/store/channel_transaction_bundle_test.go index baa71247d..95593801a 100644 --- a/internal/transactionsubmission/store/channel_transaction_bundle_test.go +++ b/internal/transactionsubmission/store/channel_transaction_bundle_test.go @@ -5,8 +5,8 @@ import ( "fmt" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" sdpUtils "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" "github.com/stretchr/testify/require" ) diff --git a/internal/transactionsubmission/store/fixtures.go b/internal/transactionsubmission/store/fixtures.go index 310516faf..76fd5e80e 100644 --- a/internal/transactionsubmission/store/fixtures.go +++ b/internal/transactionsubmission/store/fixtures.go @@ -12,7 +12,7 @@ import ( "github.com/stellar/go/keypair" "github.com/stretchr/testify/require" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) // CreateTransactionFixtures creates count number submitter transactions diff --git a/internal/transactionsubmission/store/fixtures_test.go b/internal/transactionsubmission/store/fixtures_test.go index 983b660b3..58a547b65 100644 --- a/internal/transactionsubmission/store/fixtures_test.go +++ b/internal/transactionsubmission/store/fixtures_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/google/uuid" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/transactionsubmission/store/mocks/channel_account_store.go b/internal/transactionsubmission/store/mocks/channel_account_store.go index 2cc7be192..b807c589d 100644 --- a/internal/transactionsubmission/store/mocks/channel_account_store.go +++ b/internal/transactionsubmission/store/mocks/channel_account_store.go @@ -5,7 +5,7 @@ package mocks import ( context "context" - db "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + db "github.com/stellar/stellar-disbursement-platform-backend/db" mock "github.com/stretchr/testify/mock" store "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" diff --git a/internal/transactionsubmission/store/mocks/transaction_store.go b/internal/transactionsubmission/store/mocks/transaction_store.go index e2c7d4575..790f63d28 100644 --- a/internal/transactionsubmission/store/mocks/transaction_store.go +++ b/internal/transactionsubmission/store/mocks/transaction_store.go @@ -5,7 +5,7 @@ package mocks import ( context "context" - db "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + db "github.com/stellar/stellar-disbursement-platform-backend/db" mock "github.com/stretchr/testify/mock" store "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/store" diff --git a/internal/transactionsubmission/store/store.go b/internal/transactionsubmission/store/store.go index b86bee007..e099c1538 100644 --- a/internal/transactionsubmission/store/store.go +++ b/internal/transactionsubmission/store/store.go @@ -3,7 +3,7 @@ package store import ( "context" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) //go:generate mockery --name=ChannelAccountStore --case=underscore --structname=MockChannelAccountStore diff --git a/internal/transactionsubmission/store/transactions.go b/internal/transactionsubmission/store/transactions.go index c56937c5c..f37341b64 100644 --- a/internal/transactionsubmission/store/transactions.go +++ b/internal/transactionsubmission/store/transactions.go @@ -13,7 +13,7 @@ import ( "github.com/lib/pq" "github.com/stellar/go/strkey" "github.com/stellar/go/xdr" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ErrRecordNotFound = errors.New("record not found") diff --git a/internal/transactionsubmission/store/transactions_test.go b/internal/transactionsubmission/store/transactions_test.go index d0cc52373..243f72e7b 100644 --- a/internal/transactionsubmission/store/transactions_test.go +++ b/internal/transactionsubmission/store/transactions_test.go @@ -8,8 +8,8 @@ import ( "github.com/google/uuid" "github.com/stellar/go/keypair" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/internal/transactionsubmission/transaction_worker.go b/internal/transactionsubmission/transaction_worker.go index 5019b921d..e89a84e3a 100644 --- a/internal/transactionsubmission/transaction_worker.go +++ b/internal/transactionsubmission/transaction_worker.go @@ -14,8 +14,8 @@ import ( "github.com/stellar/go/txnbuild" "golang.org/x/exp/slices" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" sdpMonitor "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" tssMonitor "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/monitor" diff --git a/internal/transactionsubmission/transaction_worker_test.go b/internal/transactionsubmission/transaction_worker_test.go index 6f1936fee..49fce7afd 100644 --- a/internal/transactionsubmission/transaction_worker_test.go +++ b/internal/transactionsubmission/transaction_worker_test.go @@ -15,9 +15,9 @@ import ( "github.com/stellar/go/protocols/horizon" "github.com/stellar/go/support/render/problem" "github.com/stellar/go/txnbuild" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/crashtracker" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/internal/monitor" "github.com/stellar/stellar-disbursement-platform-backend/internal/serve/httpclient" "github.com/stellar/stellar-disbursement-platform-backend/internal/transactionsubmission/engine" diff --git a/internal/transactionsubmission/utils/utils.go b/internal/transactionsubmission/utils/utils.go index 0e8ac724f..9c4a282bc 100644 --- a/internal/transactionsubmission/utils/utils.go +++ b/internal/transactionsubmission/utils/utils.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" sdpUtils "github.com/stellar/stellar-disbursement-platform-backend/internal/utils" ) diff --git a/internal/transactionsubmission/utils/utils_test.go b/internal/transactionsubmission/utils/utils_test.go index 4725aee5c..71ac352eb 100644 --- a/internal/transactionsubmission/utils/utils_test.go +++ b/internal/transactionsubmission/utils/utils_test.go @@ -5,8 +5,8 @@ import ( "math/rand" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/require" ) diff --git a/stellar-auth/internal/db/db.go b/stellar-auth/internal/db/db.go deleted file mode 100644 index adce8beb1..000000000 --- a/stellar-auth/internal/db/db.go +++ /dev/null @@ -1,151 +0,0 @@ -package db - -import ( - "context" - "database/sql" - "fmt" - "time" - - "github.com/jmoiron/sqlx" - "github.com/stellar/go/support/log" -) - -const ( - MaxDBConnIdleTime = 10 * time.Second - MaxOpenDBConns = 30 -) - -// DBConnectionPoolFromSqlDB returns a new DBConnectionPool wrapper for a PRE-EXISTING *sql.DB. The driverName of the -// original database is required for named query support. ATTENTION: this will not start a new connection pool, just -// create a wrap aroung the pre-existing connection pool. -func DBConnectionPoolFromSqlDB(sqlDB *sql.DB, driverName string) DBConnectionPool { - return &DBConnectionPoolImplementation{DB: sqlx.NewDb(sqlDB, driverName)} -} - -// DBConnectionPool is an interface that wraps the sqlx.DB structs methods and includes the RunInTransaction helper. -type DBConnectionPool interface { - SQLExecuter - BeginTxx(ctx context.Context, opts *sql.TxOptions) (DBTransaction, error) - Close() error - Ping() error - SqlDB() *sql.DB - SqlxDB() *sqlx.DB -} - -// DBConnectionPoolImplementation is a wrapper around sqlx.DB that implements DBConnectionPool. -type DBConnectionPoolImplementation struct { - *sqlx.DB -} - -func (db *DBConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (DBTransaction, error) { - return db.DB.BeginTxx(ctx, opts) -} - -func (db *DBConnectionPoolImplementation) SqlDB() *sql.DB { - return db.DB.DB -} - -func (db *DBConnectionPoolImplementation) SqlxDB() *sqlx.DB { - return db.DB -} - -// RunInTransactionWithResult runs the given atomic function in an atomic database transaction and returns a result and -// an error. Boilerplate code for database transactions. -func RunInTransactionWithResult[T any](ctx context.Context, dbConnectionPool DBConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx DBTransaction) (T, error)) (result T, err error) { - dbTx, err := dbConnectionPool.BeginTxx(ctx, opts) - if err != nil { - return *new(T), fmt.Errorf("creating db transaction for RunInTransactionWithResult: %w", err) - } - - defer func() { - DBTxRollback(ctx, dbTx, err, "rolling back transaction due to error") - }() - - result, err = atomicFunction(dbTx) - if err != nil { - return *new(T), fmt.Errorf("running atomic function in RunInTransactionWithResult: %w", err) - } - - err = dbTx.Commit() - if err != nil { - return *new(T), fmt.Errorf("committing transaction in RunInTransactionWithResult: %w", err) - } - - return result, nil -} - -// RunInTransaction runs the given atomic function in an atomic database transaction and returns an error. Boilerplate -// code for database transactions. -func RunInTransaction(ctx context.Context, dbConnectionPool DBConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx DBTransaction) error) error { - // wrap the atomic function with a function that returns nil and an error so we can call RunInTransactionWithResult - wrappedFunction := func(dbTx DBTransaction) (interface{}, error) { - return nil, atomicFunction(dbTx) - } - - _, err := RunInTransactionWithResult(ctx, dbConnectionPool, opts, wrappedFunction) - return err -} - -// make sure *DBConnectionPoolImplementation implements DBConnectionPool: -var _ DBConnectionPool = (*DBConnectionPoolImplementation)(nil) - -// DBTransaction is an interface that wraps the sqlx.Tx structs methods. -type DBTransaction interface { - SQLExecuter - Rollback() error - Commit() error -} - -// make sure *sqlx.Tx implements DBTransaction: -var _ DBTransaction = (*sqlx.Tx)(nil) - -// SQLExecuter is an interface that wraps the *sqlx.DB and *sqlx.Tx structs methods. -type SQLExecuter interface { - DriverName() string - ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) - GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error - sqlx.PreparerContext - sqlx.QueryerContext - Rebind(query string) string - SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error -} - -// make sure *sqlx.DB implements SQLExecuter: -var _ SQLExecuter = (*sqlx.DB)(nil) - -// make sure DBConnectionPool implements SQLExecuter: -var _ SQLExecuter = (DBConnectionPool)(nil) - -// make sure *sqlx.Tx implements SQLExecuter: -var _ SQLExecuter = (*sqlx.Tx)(nil) - -// make sure DBTransaction implements SQLExecuter: -var _ SQLExecuter = (DBTransaction)(nil) - -// DBTxRollback rolls back the transaction if there is an error. -func DBTxRollback(ctx context.Context, dbTx DBTransaction, err error, logMessage string) { - if err != nil { - log.Ctx(ctx).Errorf("%s: %s", logMessage, err.Error()) - errRollBack := dbTx.Rollback() - if errRollBack != nil { - log.Ctx(ctx).Errorf("error in database transaction rollback: %s", errRollBack.Error()) - } - } -} - -// OpenDBConnectionPool opens a new database connection pool. It returns an error if it can't connect to the database. -func OpenDBConnectionPool(dataSourceName string) (DBConnectionPool, error) { - sqlxDB, err := sqlx.Open("postgres", dataSourceName) - if err != nil { - return nil, fmt.Errorf("error creating app DB connection pool: %w", err) - } - sqlxDB.SetConnMaxIdleTime(MaxDBConnIdleTime) - sqlxDB.SetMaxOpenConns(MaxOpenDBConns) - - err = sqlxDB.Ping() - if err != nil { - return nil, fmt.Errorf("error pinging app DB connection pool: %w", err) - } - - return &DBConnectionPoolImplementation{DB: sqlxDB}, nil -} diff --git a/stellar-auth/internal/db/dbtest/dbtest.go b/stellar-auth/internal/db/dbtest/dbtest.go deleted file mode 100644 index 42d2232b6..000000000 --- a/stellar-auth/internal/db/dbtest/dbtest.go +++ /dev/null @@ -1,31 +0,0 @@ -package dbtest - -import ( - "net/http" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/go/support/db/dbtest" - "github.com/stellar/go/support/db/schema" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/migrations" -) - -func OpenWithoutMigrations(t *testing.T) *dbtest.DB { - db := dbtest.Postgres(t) - return db -} - -func Open(t *testing.T) *dbtest.DB { - db := OpenWithoutMigrations(t) - - conn := db.Open() - defer conn.Close() - - migrateDirection := schema.MigrateUp - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} - _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) - if err != nil { - t.Fatal(err) - } - return db -} diff --git a/stellar-auth/internal/db/dbtest/dbtest_test.go b/stellar-auth/internal/db/dbtest/dbtest_test.go deleted file mode 100644 index 6ade6b7fa..000000000 --- a/stellar-auth/internal/db/dbtest/dbtest_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package dbtest - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOpen(t *testing.T) { - db := Open(t) - defer db.Close() - - session := db.Open() - defer session.Close() - - count := 0 - err := session.Get(&count, `SELECT COUNT(*) FROM gorp_migrations`) - require.NoError(t, err) - assert.Greater(t, count, 0) -} diff --git a/stellar-auth/internal/db/migrate.go b/stellar-auth/internal/db/migrate.go deleted file mode 100644 index 97a267e3f..000000000 --- a/stellar-auth/internal/db/migrate.go +++ /dev/null @@ -1,27 +0,0 @@ -package db - -import ( - "fmt" - "net/http" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/migrations" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" -) - -const StellarAuthMigrationsTableName = "auth_migrations" - -func Migrate(dbURL string, dir migrate.MigrationDirection, count int) (int, error) { - dbConnectionPool, err := OpenDBConnectionPool(dbURL) - if err != nil { - return 0, fmt.Errorf("database URL '%s': %w", utils.TruncateString(dbURL, len(dbURL)/4), err) - } - defer dbConnectionPool.Close() - - ms := migrate.MigrationSet{ - TableName: StellarAuthMigrationsTableName, - } - - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} - return ms.ExecMax(dbConnectionPool.SqlDB(), dbConnectionPool.DriverName(), m, dir, count) -} diff --git a/stellar-auth/internal/db/migrate_test.go b/stellar-auth/internal/db/migrate_test.go deleted file mode 100644 index 3c4775985..000000000 --- a/stellar-auth/internal/db/migrate_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package db - -import ( - "context" - "fmt" - "io/fs" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/stellar-disbursement-platform-backend/internal/db/dbtest" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/migrations" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMigrate_upApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 1) - require.NoError(t, err) - assert.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarAuthMigrationsTableName)) - require.NoError(t, err) - wantIDs := []string{"2023-02-09.0.add-users-table.sql"} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_downApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 2) - require.NoError(t, err) - require.Equal(t, 2, n) - - n, err = Migrate(db.DSN, migrate.Down, 1) - require.NoError(t, err) - require.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarAuthMigrationsTableName)) - require.NoError(t, err) - wantIDs := []string{"2023-02-09.0.add-users-table.sql"} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_upAndDownAllTheWayTwice(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - // Get number of files in the migrations directory: - var count int - err = fs.WalkDir(migrations.FS, ".", func(path string, d fs.DirEntry, err error) error { - require.NoError(t, err) - if !d.IsDir() { - count++ - } - return nil - }) - require.NoError(t, err) - - n, err := Migrate(db.DSN, migrate.Up, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Down, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Up, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Down, count) - require.NoError(t, err) - require.Equal(t, count, n) -} diff --git a/stellar-auth/internal/db/migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql b/stellar-auth/internal/db/migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql deleted file mode 100644 index 4c3697690..000000000 --- a/stellar-auth/internal/db/migrations/2023-03-22.0.alter-users-table-add-is_active-column.sql +++ /dev/null @@ -1,7 +0,0 @@ --- +migrate Up - -ALTER TABLE public.auth_users ADD COLUMN is_active boolean DEFAULT true; - --- +migrate Down - -ALTER TABLE public.auth_users DROP COLUMN is_active; diff --git a/stellar-auth/pkg/auth/auth.go b/stellar-auth/pkg/auth/auth.go index 361e0a84a..aae5d2fe0 100644 --- a/stellar-auth/pkg/auth/auth.go +++ b/stellar-auth/pkg/auth/auth.go @@ -7,7 +7,7 @@ import ( "fmt" "time" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ErrInvalidToken = errors.New("invalid token") diff --git a/stellar-auth/pkg/auth/authenticator.go b/stellar-auth/pkg/auth/authenticator.go index 25ddce24b..7a6593024 100644 --- a/stellar-auth/pkg/auth/authenticator.go +++ b/stellar-auth/pkg/auth/authenticator.go @@ -11,7 +11,7 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" ) diff --git a/stellar-auth/pkg/auth/authenticator_test.go b/stellar-auth/pkg/auth/authenticator_test.go index 582a5aac2..49297d9be 100644 --- a/stellar-auth/pkg/auth/authenticator_test.go +++ b/stellar-auth/pkg/auth/authenticator_test.go @@ -7,8 +7,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/stellar-auth/pkg/auth/fixtures.go b/stellar-auth/pkg/auth/fixtures.go index 033e7a329..79f5020cc 100644 --- a/stellar-auth/pkg/auth/fixtures.go +++ b/stellar-auth/pkg/auth/fixtures.go @@ -9,7 +9,7 @@ import ( "time" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" "github.com/stretchr/testify/require" ) diff --git a/stellar-auth/pkg/auth/manager.go b/stellar-auth/pkg/auth/manager.go index ec0bf09a5..439c11454 100644 --- a/stellar-auth/pkg/auth/manager.go +++ b/stellar-auth/pkg/auth/manager.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" ) diff --git a/stellar-auth/pkg/auth/mfa_manager.go b/stellar-auth/pkg/auth/mfa_manager.go index 5593b10ef..a2d025c97 100644 --- a/stellar-auth/pkg/auth/mfa_manager.go +++ b/stellar-auth/pkg/auth/mfa_manager.go @@ -11,7 +11,7 @@ import ( "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) type MFAManager interface { diff --git a/stellar-auth/pkg/auth/mfa_manager_test.go b/stellar-auth/pkg/auth/mfa_manager_test.go index a41dfbf47..f3c2946d4 100644 --- a/stellar-auth/pkg/auth/mfa_manager_test.go +++ b/stellar-auth/pkg/auth/mfa_manager_test.go @@ -6,8 +6,8 @@ import ( "testing" "time" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/stellar-auth/pkg/auth/role_manager.go b/stellar-auth/pkg/auth/role_manager.go index 86f2cbfb3..6cf160c6b 100644 --- a/stellar-auth/pkg/auth/role_manager.go +++ b/stellar-auth/pkg/auth/role_manager.go @@ -7,7 +7,7 @@ import ( "fmt" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) const defaultOwnerRoleName = "owner" diff --git a/stellar-auth/pkg/auth/role_manager_test.go b/stellar-auth/pkg/auth/role_manager_test.go index 8dbbc9177..a57d49526 100644 --- a/stellar-auth/pkg/auth/role_manager_test.go +++ b/stellar-auth/pkg/auth/role_manager_test.go @@ -4,8 +4,8 @@ import ( "context" "testing" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/stellar-auth/pkg/cli/add_user.go b/stellar-auth/pkg/cli/add_user.go index 24716f56a..087b17098 100644 --- a/stellar-auth/pkg/cli/add_user.go +++ b/stellar-auth/pkg/cli/add_user.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/viper" "github.com/stellar/go/support/config" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/utils" ) diff --git a/stellar-auth/pkg/cli/add_user_test.go b/stellar-auth/pkg/cli/add_user_test.go index efa252762..fede3283d 100644 --- a/stellar-auth/pkg/cli/add_user_test.go +++ b/stellar-auth/pkg/cli/add_user_test.go @@ -7,8 +7,8 @@ import ( "github.com/lib/pq" "github.com/spf13/cobra" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/pkg/auth" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/stellar-auth/pkg/cli/migrate.go b/stellar-auth/pkg/cli/migrate.go index 280b836ed..d9f93757a 100644 --- a/stellar-auth/pkg/cli/migrate.go +++ b/stellar-auth/pkg/cli/migrate.go @@ -8,7 +8,8 @@ import ( "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" + migrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/auth-migrations" ) func MigrateCmd(databaseFlagName string) *cobra.Command { @@ -76,7 +77,7 @@ func MigrateCmd(databaseFlagName string) *cobra.Command { } func runMigration(databaseURL string, dir migrate.MigrationDirection, count int) error { - numMigrationsRun, err := db.Migrate(databaseURL, dir, count) + numMigrationsRun, err := db.Migrate(databaseURL, dir, count, migrations.FS, db.StellarAuthMigrationsTableName) if err != nil { return fmt.Errorf("running migrations: %w", err) } diff --git a/stellar-auth/pkg/cli/migrate_test.go b/stellar-auth/pkg/cli/migrate_test.go index 8bbe1f95c..db56f3901 100644 --- a/stellar-auth/pkg/cli/migrate_test.go +++ b/stellar-auth/pkg/cli/migrate_test.go @@ -12,8 +12,9 @@ import ( "github.com/spf13/viper" stellardbtest "github.com/stellar/go/support/db/dbtest" "github.com/stellar/go/support/log" - dbpkg "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-auth/internal/db/dbtest" + dbpkg "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" + migrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/auth-migrations" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -94,7 +95,7 @@ func Test_MigrateCmd(t *testing.T) { args: []string{"--log-level", "TRACE", "--database-url", "", "migrate", "down", "1"}, expect: "Successfully applied 1 migrations.", preRunFunc: func(t *testing.T, db *stellardbtest.DB) { - _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1) + _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1, migrations.FS, dbpkg.StellarAuthMigrationsTableName) require.NoError(t, err) conn := db.Open() @@ -114,7 +115,7 @@ func Test_MigrateCmd(t *testing.T) { envVars: map[string]string{"DATABASE_URL": ""}, expect: "Successfully applied 1 migrations.", preRunFunc: func(t *testing.T, db *stellardbtest.DB) { - _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1) + _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1, migrations.FS, dbpkg.StellarAuthMigrationsTableName) require.NoError(t, err) conn := db.Open() diff --git a/stellar-multitenant/internal/db/db.go b/stellar-multitenant/internal/db/db.go deleted file mode 100644 index c7cd77908..000000000 --- a/stellar-multitenant/internal/db/db.go +++ /dev/null @@ -1,152 +0,0 @@ -package db - -import ( - "context" - "database/sql" - "fmt" - "time" - - "github.com/jmoiron/sqlx" - _ "github.com/lib/pq" - "github.com/stellar/go/support/log" -) - -const ( - MaxDBConnIdleTime = 10 * time.Second - MaxOpenDBConns = 30 -) - -// DBConnectionPoolFromSqlDB returns a new DBConnectionPool wrapper for a PRE-EXISTING *sql.DB. The driverName of the -// original database is required for named query support. ATTENTION: this will not start a new connection pool, just -// create a wrap aroung the pre-existing connection pool. -func DBConnectionPoolFromSqlDB(sqlDB *sql.DB, driverName string) DBConnectionPool { - return &DBConnectionPoolImplementation{DB: sqlx.NewDb(sqlDB, driverName)} -} - -// DBConnectionPool is an interface that wraps the sqlx.DB structs methods and includes the RunInTransaction helper. -type DBConnectionPool interface { - SQLExecuter - BeginTxx(ctx context.Context, opts *sql.TxOptions) (DBTransaction, error) - Close() error - Ping() error - SqlDB() *sql.DB - SqlxDB() *sqlx.DB -} - -// DBConnectionPoolImplementation is a wrapper around sqlx.DB that implements DBConnectionPool. -type DBConnectionPoolImplementation struct { - *sqlx.DB -} - -func (db *DBConnectionPoolImplementation) BeginTxx(ctx context.Context, opts *sql.TxOptions) (DBTransaction, error) { - return db.DB.BeginTxx(ctx, opts) -} - -func (db *DBConnectionPoolImplementation) SqlDB() *sql.DB { - return db.DB.DB -} - -func (db *DBConnectionPoolImplementation) SqlxDB() *sqlx.DB { - return db.DB -} - -// RunInTransactionWithResult runs the given atomic function in an atomic database transaction and returns a result and -// an error. Boilerplate code for database transactions. -func RunInTransactionWithResult[T any](ctx context.Context, dbConnectionPool DBConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx DBTransaction) (T, error)) (result T, err error) { - dbTx, err := dbConnectionPool.BeginTxx(ctx, opts) - if err != nil { - return *new(T), fmt.Errorf("creating db transaction for RunInTransactionWithResult: %w", err) - } - - defer func() { - DBTxRollback(ctx, dbTx, err, "rolling back transaction due to error") - }() - - result, err = atomicFunction(dbTx) - if err != nil { - return *new(T), fmt.Errorf("running atomic function in RunInTransactionWithResult: %w", err) - } - - err = dbTx.Commit() - if err != nil { - return *new(T), fmt.Errorf("committing transaction in RunInTransactionWithResult: %w", err) - } - - return result, nil -} - -// RunInTransaction runs the given atomic function in an atomic database transaction and returns an error. Boilerplate -// code for database transactions. -func RunInTransaction(ctx context.Context, dbConnectionPool DBConnectionPool, opts *sql.TxOptions, atomicFunction func(dbTx DBTransaction) error) error { - // wrap the atomic function with a function that returns nil and an error so we can call RunInTransactionWithResult - wrappedFunction := func(dbTx DBTransaction) (interface{}, error) { - return nil, atomicFunction(dbTx) - } - - _, err := RunInTransactionWithResult(ctx, dbConnectionPool, opts, wrappedFunction) - return err -} - -// make sure *DBConnectionPoolImplementation implements DBConnectionPool: -var _ DBConnectionPool = (*DBConnectionPoolImplementation)(nil) - -// DBTransaction is an interface that wraps the sqlx.Tx structs methods. -type DBTransaction interface { - SQLExecuter - Rollback() error - Commit() error -} - -// make sure *sqlx.Tx implements DBTransaction: -var _ DBTransaction = (*sqlx.Tx)(nil) - -// SQLExecuter is an interface that wraps the *sqlx.DB and *sqlx.Tx structs methods. -type SQLExecuter interface { - DriverName() string - ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) - GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error - sqlx.PreparerContext - sqlx.QueryerContext - Rebind(query string) string - SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error -} - -// make sure *sqlx.DB implements SQLExecuter: -var _ SQLExecuter = (*sqlx.DB)(nil) - -// make sure DBConnectionPool implements SQLExecuter: -var _ SQLExecuter = (DBConnectionPool)(nil) - -// make sure *sqlx.Tx implements SQLExecuter: -var _ SQLExecuter = (*sqlx.Tx)(nil) - -// make sure DBTransaction implements SQLExecuter: -var _ SQLExecuter = (DBTransaction)(nil) - -// DBTxRollback rolls back the transaction if there is an error. -func DBTxRollback(ctx context.Context, dbTx DBTransaction, err error, logMessage string) { - if err != nil { - log.Ctx(ctx).Errorf("%s: %s", logMessage, err.Error()) - errRollBack := dbTx.Rollback() - if errRollBack != nil { - log.Ctx(ctx).Errorf("error in database transaction rollback: %s", errRollBack.Error()) - } - } -} - -// OpenDBConnectionPool opens a new database connection pool. It returns an error if it can't connect to the database. -func OpenDBConnectionPool(dataSourceName string) (DBConnectionPool, error) { - sqlxDB, err := sqlx.Open("postgres", dataSourceName) - if err != nil { - return nil, fmt.Errorf("error creating app DB connection pool: %w", err) - } - sqlxDB.SetConnMaxIdleTime(MaxDBConnIdleTime) - sqlxDB.SetMaxOpenConns(MaxOpenDBConns) - - err = sqlxDB.Ping() - if err != nil { - return nil, fmt.Errorf("error pinging app DB connection pool: %w", err) - } - - return &DBConnectionPoolImplementation{DB: sqlxDB}, nil -} diff --git a/stellar-multitenant/internal/db/db_test.go b/stellar-multitenant/internal/db/db_test.go deleted file mode 100644 index a67723e55..000000000 --- a/stellar-multitenant/internal/db/db_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package db - -import ( - "testing" - - "github.com/stellar/go/support/db/dbtest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOpen_OpenDBConnectionPool(t *testing.T) { - db := dbtest.Postgres(t) - defer db.Close() - - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - assert.Equal(t, "postgres", dbConnectionPool.DriverName()) - - err = dbConnectionPool.Ping() - require.NoError(t, err) -} diff --git a/stellar-multitenant/internal/db/dbtest/dbtest.go b/stellar-multitenant/internal/db/dbtest/dbtest.go deleted file mode 100644 index e5a9e3bd1..000000000 --- a/stellar-multitenant/internal/db/dbtest/dbtest.go +++ /dev/null @@ -1,31 +0,0 @@ -package dbtest - -import ( - "net/http" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/go/support/db/dbtest" - "github.com/stellar/go/support/db/schema" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/migrations" -) - -func OpenWithoutMigrations(t *testing.T) *dbtest.DB { - db := dbtest.Postgres(t) - return db -} - -func Open(t *testing.T) *dbtest.DB { - db := OpenWithoutMigrations(t) - - conn := db.Open() - defer conn.Close() - - migrateDirection := schema.MigrateUp - m := migrate.HttpFileSystemMigrationSource{FileSystem: http.FS(migrations.FS)} - _, err := schema.Migrate(conn.DB, m, migrateDirection, 0) - if err != nil { - t.Fatal(err) - } - return db -} diff --git a/stellar-multitenant/internal/db/dbtest/dbtest_test.go b/stellar-multitenant/internal/db/dbtest/dbtest_test.go deleted file mode 100644 index 6ade6b7fa..000000000 --- a/stellar-multitenant/internal/db/dbtest/dbtest_test.go +++ /dev/null @@ -1,21 +0,0 @@ -package dbtest - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestOpen(t *testing.T) { - db := Open(t) - defer db.Close() - - session := db.Open() - defer session.Close() - - count := 0 - err := session.Get(&count, `SELECT COUNT(*) FROM gorp_migrations`) - require.NoError(t, err) - assert.Greater(t, count, 0) -} diff --git a/stellar-multitenant/internal/db/migrate_test.go b/stellar-multitenant/internal/db/migrate_test.go deleted file mode 100644 index bf2a3c942..000000000 --- a/stellar-multitenant/internal/db/migrate_test.go +++ /dev/null @@ -1,93 +0,0 @@ -package db - -import ( - "context" - "fmt" - "io/fs" - "testing" - - migrate "github.com/rubenv/sql-migrate" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/dbtest" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/migrations" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -func TestMigrate_upApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 1) - require.NoError(t, err) - assert.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarMultitenantMigrationsTableName)) - require.NoError(t, err) - wantIDs := []string{"2023-10-16.0.add-tenants-table.sql"} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_downApplyOne(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - ctx := context.Background() - - n, err := Migrate(db.DSN, migrate.Up, 2) - require.NoError(t, err) - require.Equal(t, 1, n) - - n, err = Migrate(db.DSN, migrate.Down, 1) - require.NoError(t, err) - require.Equal(t, 1, n) - - ids := []string{} - err = dbConnectionPool.SelectContext(ctx, &ids, fmt.Sprintf("SELECT id FROM %s", StellarMultitenantMigrationsTableName)) - require.NoError(t, err) - wantIDs := []string{} - assert.Equal(t, wantIDs, ids) -} - -func TestMigrate_upAndDownAllTheWayTwice(t *testing.T) { - db := dbtest.OpenWithoutMigrations(t) - defer db.Close() - dbConnectionPool, err := OpenDBConnectionPool(db.DSN) - require.NoError(t, err) - defer dbConnectionPool.Close() - - // Get number of files in the migrations directory: - var count int - err = fs.WalkDir(migrations.FS, ".", func(path string, d fs.DirEntry, err error) error { - require.NoError(t, err) - if !d.IsDir() { - count++ - } - return nil - }) - require.NoError(t, err) - - n, err := Migrate(db.DSN, migrate.Up, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Down, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Up, count) - require.NoError(t, err) - require.Equal(t, count, n) - - n, err = Migrate(db.DSN, migrate.Down, count) - require.NoError(t, err) - require.Equal(t, count, n) -} diff --git a/stellar-multitenant/pkg/cli/add_tenants.go b/stellar-multitenant/pkg/cli/add_tenants.go index a8ce43a1b..8a16edd2c 100644 --- a/stellar-multitenant/pkg/cli/add_tenants.go +++ b/stellar-multitenant/pkg/cli/add_tenants.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/tenant" ) diff --git a/stellar-multitenant/pkg/cli/add_tenants_test.go b/stellar-multitenant/pkg/cli/add_tenants_test.go index a58ea04f5..7c6c5a923 100644 --- a/stellar-multitenant/pkg/cli/add_tenants_test.go +++ b/stellar-multitenant/pkg/cli/add_tenants_test.go @@ -9,8 +9,8 @@ import ( "github.com/spf13/cobra" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/tenant" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" diff --git a/stellar-multitenant/pkg/cli/config_tenant.go b/stellar-multitenant/pkg/cli/config_tenant.go index 8ff86d1d2..bf6a64918 100644 --- a/stellar-multitenant/pkg/cli/config_tenant.go +++ b/stellar-multitenant/pkg/cli/config_tenant.go @@ -8,7 +8,7 @@ import ( "github.com/spf13/cobra" "github.com/stellar/go/support/config" "github.com/stellar/go/support/log" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/cli/utils" "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/pkg/tenant" ) diff --git a/stellar-multitenant/pkg/cli/migrate.go b/stellar-multitenant/pkg/cli/migrate.go index 0e5c679cb..79ab4ea56 100644 --- a/stellar-multitenant/pkg/cli/migrate.go +++ b/stellar-multitenant/pkg/cli/migrate.go @@ -4,7 +4,8 @@ import ( "fmt" "strconv" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" + migrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/tenant-migrations" migrate "github.com/rubenv/sql-migrate" "github.com/spf13/cobra" @@ -77,7 +78,7 @@ func MigrateCmd(databaseFlagName string) *cobra.Command { } func runMigration(databaseURL string, dir migrate.MigrationDirection, count int) error { - numMigrationsRun, err := db.Migrate(databaseURL, dir, count) + numMigrationsRun, err := db.Migrate(databaseURL, dir, count, migrations.FS, db.StellarMultitenantMigrationsTableName) if err != nil { return fmt.Errorf("running migrations: %w", err) } diff --git a/stellar-multitenant/pkg/cli/migrate_test.go b/stellar-multitenant/pkg/cli/migrate_test.go index e2222da51..4db3d83a8 100644 --- a/stellar-multitenant/pkg/cli/migrate_test.go +++ b/stellar-multitenant/pkg/cli/migrate_test.go @@ -12,8 +12,9 @@ import ( "github.com/spf13/viper" stellardbtest "github.com/stellar/go/support/db/dbtest" "github.com/stellar/go/support/log" - dbpkg "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/dbtest" + dbpkg "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" + migrations "github.com/stellar/stellar-disbursement-platform-backend/db/migrations/tenant-migrations" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -94,7 +95,7 @@ func Test_MigrateCmd(t *testing.T) { args: []string{"--multitenant-db-url", "", "migrate", "down", "1"}, expect: "Successfully applied 1 migrations.", preRunFunc: func(t *testing.T, db *stellardbtest.DB) { - _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1) + _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1, migrations.FS, dbpkg.StellarMultitenantMigrationsTableName) require.NoError(t, err) conn := db.Open() @@ -114,7 +115,7 @@ func Test_MigrateCmd(t *testing.T) { envVars: map[string]string{"MULTITENANT_DB_URL": ""}, expect: "Successfully applied 1 migrations.", preRunFunc: func(t *testing.T, db *stellardbtest.DB) { - _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1) + _, err := dbpkg.Migrate(db.DSN, migrate.Up, 1, migrations.FS, dbpkg.StellarMultitenantMigrationsTableName) require.NoError(t, err) conn := db.Open() diff --git a/stellar-multitenant/pkg/tenant/manager.go b/stellar-multitenant/pkg/tenant/manager.go index 846532a4f..e75065958 100644 --- a/stellar-multitenant/pkg/tenant/manager.go +++ b/stellar-multitenant/pkg/tenant/manager.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/lib/pq" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" + "github.com/stellar/stellar-disbursement-platform-backend/db" ) var ( diff --git a/stellar-multitenant/pkg/tenant/manager_test.go b/stellar-multitenant/pkg/tenant/manager_test.go index b20104269..fa480f93c 100644 --- a/stellar-multitenant/pkg/tenant/manager_test.go +++ b/stellar-multitenant/pkg/tenant/manager_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/stellar/go/keypair" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db" - "github.com/stellar/stellar-disbursement-platform-backend/stellar-multitenant/internal/db/dbtest" + "github.com/stellar/stellar-disbursement-platform-backend/db" + "github.com/stellar/stellar-disbursement-platform-backend/db/dbtest" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" )