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(typeorm): allow overriding tables schema #661

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 4 additions & 1 deletion apps/api/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# in case you want to define the bandada tables in a specific schema
# default is unspecified is public schema
DB_SCHEMA=
DB_TYPE=sqlite
DB_URL=data/bandada.db
API_URL=http://localhost:3000
Expand All @@ -23,7 +26,7 @@ TWITTER_REDIRECT_URI=
TWITTER_CLIENT_ID=
TWITTER_CLIENT_SECRET=

# The network name must be the same as the id that appears in the `blockchainCredentialSupportedNetworks` list
# The network name must be the same as the id that appears in the `blockchainCredentialSupportedNetworks` list
# exported from the `@bandada/utils` package but with capital letters. E.g. polygon_amoy would be POLYGON_AMOY.

SEPOLIA_RPC_URL=
Expand Down
21 changes: 12 additions & 9 deletions apps/api/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { CredentialsModule } from "./credentials/credentials.module"

type DB_TYPE = "mysql" | "sqlite" | "postgres"

const TYPEORM_OPTIONS = {
autoLoadEntities: true,
synchronize: process.env.NODE_ENV !== "production",
type: (process.env.DB_TYPE as DB_TYPE) || "postgres",
url: process.env.DB_URL,
...(process.env.DB_TYPE === "sqlite" && { database: process.env.DB_URL })
}
const schema = process.env.DB_SCHEMA?.trim() || ""
const typeOrmOptions =
schema === "" ? TYPEORM_OPTIONS : { ...TYPEORM_OPTIONS, schema }

@Module({
imports: [
AuthModule,
Expand All @@ -26,15 +37,7 @@ type DB_TYPE = "mysql" | "sqlite" | "postgres"
ttl: 60,
limit: 10
}),
TypeOrmModule.forRoot({
type: (process.env.DB_TYPE as DB_TYPE) || "postgres",
url: process.env.DB_URL,
...(process.env.DB_TYPE === "sqlite" && {
database: process.env.DB_URL
}),
autoLoadEntities: true,
synchronize: process.env.NODE_ENV !== "production"
})
TypeOrmModule.forRoot(typeOrmOptions)
]
})
export class AppModule {}