Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(backend): backend tenant graphql resolvers #3234

Merged
merged 10 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 191 additions & 2 deletions localenv/mock-account-servicing-entity/generated/graphql.ts

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions packages/backend/jest.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const setup = async (globalConfig): Promise<void> => {
POSTGRES_PORT
)}/testing`

process.env.TENANT_TEST_DATABASE_URL = `postgresql://postgres:password@localhost:${postgresContainer.getMappedPort(
POSTGRES_PORT
)}/tenant_testing`

global.__BACKEND_POSTGRES__ = postgresContainer
}

Expand All @@ -49,6 +53,18 @@ const setup = async (globalConfig): Promise<void> => {
}
})

const tenantDb = knex({
client: 'postgresql',
connection: process.env.TENANT_TEST_DATABASE_URL,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
})

// node pg defaults to returning bigint as string. This ensures it parses to bigint
db.client.driver.types.setTypeParser(
db.client.driver.types.builtins.INT8,
Expand All @@ -59,14 +75,29 @@ const setup = async (globalConfig): Promise<void> => {
directory: __dirname + '/migrations'
})

tenantDb.client.driver.types.setTypeParser(
tenantDb.client.driver.types.builtins.INT8,
'text',
BigInt
)
await tenantDb.migrate.latest({
directory: __dirname + '/migrations'
})

for (let i = 1; i <= workers; i++) {
const workerDatabaseName = `testing_${i}`
const tenantWorkerDatabaseName = `tenant_testing_${i}`

await db.raw(`DROP DATABASE IF EXISTS ${workerDatabaseName}`)
await tenantDb.raw(`DROP DATABASE IF EXISTS ${tenantWorkerDatabaseName}`)
await db.raw(`CREATE DATABASE ${workerDatabaseName} TEMPLATE testing`)
await tenantDb.raw(
`CREATE DATABASE ${tenantWorkerDatabaseName} TEMPLATE tenant_testing`
)
}

global.__BACKEND_KNEX__ = db
global.__BACKEND_TENANT_KNEX__ = tenantDb
}

const setupRedis = async () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/backend/jest.teardown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ module.exports = async () => {
{ directory: __dirname + '/migrations' },
true
)
await global.__BACKEND_TENANT_KNEX__.migrate.rollback(
{ directory: __dirname + '/migrations' },
true
)
await global.__BACKEND_KNEX__.destroy()
await global.__BACKEND_TENANT_KNEX__.destroy()
if (global.__BACKEND_POSTGRES__) {
await global.__BACKEND_POSTGRES__.stop()
}
Expand Down
16 changes: 16 additions & 0 deletions packages/backend/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ module.exports = {
}
},

tenant_testing: {
client: 'postgresql',
connection: {
database: 'tenant_testing',
user: 'postgres',
password: 'password'
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},

production: {
client: 'postgresql',
connection: process.env.DATABASE_URL,
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
DROP DATABASE IF EXISTS TESTING;
DROP DATABASE IF EXISTS TENANT_TESTING;
njlie marked this conversation as resolved.
Show resolved Hide resolved
CREATE DATABASE testing;
CREATE DATABASE tenant_testing;
CREATE DATABASE development;
EOSQL
Loading
Loading