diff --git a/.github/workflows/singletenant-to-multitenant-migration.yml b/.github/workflows/singletenant-to-multitenant-migration.yml index 368d8392c..3a5ec8cc2 100644 --- a/.github/workflows/singletenant-to-multitenant-migration.yml +++ b/.github/workflows/singletenant-to-multitenant-migration.yml @@ -50,24 +50,79 @@ jobs: - name: Wait for PostgreSQL to be ready run: | + SECONDS=0 until pg_isready; do - echo "Waiting for postgres container..." + echo "Waiting for postgres container... $SECONDS seconds elapsed" sleep 2 + if [ $SECONDS -ge 8 ]; then + echo "Postgres container is not ready after 16 seconds." + exit 1 + fi done - name: Load Database Dump - run: psql -d $DATABASE_URL -f .github/resources/single_tenant_dump.sql + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + run: | + psql -d $DATABASE_URL -f .github/resources/single_tenant_dump.sql + psql -d $DATABASE_URL -c "SELECT current_database();" - name: Run Go migrations + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + run: | + psql -d $DATABASE_URL -c "SELECT current_database();" + go run main.go db admin migrate up --database-url=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + go run main.go db tss migrate up --database-url=postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + + - name: Start Go Server in Background + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable + ENABLE_SCHEDULER: "true" + EVENT_BROKER_TYPE: "NONE" + run: | + nohup go run main.go serve > server.log 2> server.log.err < /dev/null & + + - name: Wait for Go Server to be ready + run: | + SECONDS=0 + until curl -s http://localhost:8000/health; do + echo "Waiting for Go server... $SECONDS seconds elapsed" + sleep 2 + if [ $SECONDS -ge 8 ]; then + echo "Go server is not ready after 16 seconds." + exit 1 + fi + done + + - name: execute curl to create tenant run: | - go run main.go db admin migrate up - go run main.go db tss migrate up + adminAccount="SDP-admin" + adminApiKey="api_key_1234567890" + encodedCredentials=$(echo -n "$adminAccount:$adminApiKey" | base64) + AuthHeader="Authorization: Basic $encodedCredentials" + + curl -X POST http://localhost:8003/tenants -H "$AuthHeader" -d '{ + "name": "migrated-tenant", + "organization_name": "migrated-tenant", + "owner_email": "init_owner@$tenant.local", + "owner_first_name": "jane", + "owner_last_name": "doe", + "distribution_account_type": "DISTRIBUTION_ACCOUNT.STELLAR.DB_VAULT" + }' - name: Execute migration function + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable run: | - psql -d ${DATABASE_URL} -c "SELECT admin.migrate_tenant_data_from_v1_to_v2('migrated_tenant');" + psql -d $DATABASE_URL -c "SELECT current_database();" + psql -d $DATABASE_URL -c "SHOW search_path;" + psql -d $DATABASE_URL -c "SELECT schema_name FROM information_schema.schemata;" + psql -d $DATABASE_URL -c "SELECT admin.migrate_tenant_data_from_v1_to_v2('migrated-tenant');" - name: Execute cleanup queries + env: + DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable run: | psql -d ${DATABASE_URL} -c " BEGIN TRANSACTION; @@ -90,3 +145,20 @@ jobs: DROP TABLE public.submitter_transactions CASCADE; DROP TABLE public.channel_accounts CASCADE; COMMIT;" + + - name: Print server.log content + if: always() + run: | + pwd + ls -la + if [ -f server.log ]; then + cat server.log + else + echo "server.log does not exist." + fi + + if [ -f server.log.err ]; then + cat server.log.err + else + echo "server.log.err does not exist." + fi diff --git a/cmd/db/schema_migration_manager.go b/cmd/db/schema_migration_manager.go index 50b3ec988..ce91ee1ed 100644 --- a/cmd/db/schema_migration_manager.go +++ b/cmd/db/schema_migration_manager.go @@ -78,7 +78,7 @@ func (m *SchemaMigrationManager) deleteSchemaIfNeeded(ctx context.Context) error err := m.schemaDBConnectionPool.GetContext(ctx, &numberOfRemainingTablesInSchema, query) if err != nil { - return fmt.Errorf("counting number of tables remaining in the '%s' database schema: %w", m.SchemaName, err) + return fmt.Errorf("counting number of table(s) remaining in the '%s' database schema: %w", m.SchemaName, err) } if numberOfRemainingTablesInSchema == 0 { @@ -90,7 +90,7 @@ func (m *SchemaMigrationManager) deleteSchemaIfNeeded(ctx context.Context) error } log.Ctx(ctx).Infof("dropped the '%s' database schema ✅", m.SchemaName) } else { - log.Ctx(ctx).Debugf("the '%s' database schema was not dropped because there are %d tables remaining", m.SchemaName, numberOfRemainingTablesInSchema) + log.Ctx(ctx).Debugf("the '%s' database schema was not dropped because there are %d table(s) remaining", m.SchemaName, numberOfRemainingTablesInSchema) } return nil diff --git a/main.go b/main.go index 7a8c82748..689d3847a 100644 --- a/main.go +++ b/main.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - "github.com/joho/godotenv" "github.com/sirupsen/logrus" "github.com/stellar/go/support/log" @@ -20,10 +19,6 @@ const Version = "2.1.0-rc.1" var GitCommit string func main() { - if err := godotenv.Load(); err != nil { - log.Debug("No .env file found") - } - preConfigureLogger() rootCmd := cmd.SetupCLI(Version, GitCommit)