Skip to content

Commit

Permalink
Update CI
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelosalloum committed Jul 18, 2024
1 parent c45be7d commit 5edf26e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 12 deletions.
74 changes: 69 additions & 5 deletions .github/workflows/singletenant-to-multitenant-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
go run main.go db admin migrate up
go run main.go db tss migrate up
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: |
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;
Expand All @@ -90,3 +145,12 @@ jobs:
DROP TABLE public.submitter_transactions CASCADE;
DROP TABLE public.channel_accounts CASCADE;
COMMIT;"
- name: Print server.log content
if: always()
run: |
if [ -f server.log ]; then
cat server.log
else
echo "server.log does not exist."
fi
4 changes: 2 additions & 2 deletions cmd/db/schema_migration_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"os"

"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/stellar/go/support/log"

Expand All @@ -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)
Expand Down

0 comments on commit 5edf26e

Please sign in to comment.