@@ -31,8 +31,8 @@ export async function getConnectionForTenant(
3131 type : 'postgres' ,
3232 host : process . env . POSTGRES_HOST ,
3333 port : Number ( process . env . POSTGRES_PORT ) ,
34- username : process . env . POSTGRES_USER ,
35- password : process . env . POSTGRES_PASSWORD ,
34+ username : process . env . POSTGRES_TENANT_USER ,
35+ password : process . env . POSTGRES_TENANT_PASSWORD ,
3636 database : process . env . POSTGRES_DB ,
3737 entities : [
3838 __dirname + '/../**/*.entity.ts' ,
@@ -68,3 +68,30 @@ const switchToTenant = async (
6868 ) ;
6969 }
7070} ;
71+
72+ export async function getConnectionAsOwner ( ) : Promise < DataSource > {
73+ if ( ! getConnectionManager ( ) . has ( 'Owner' ) )
74+ return await new DataSource ( {
75+ name : 'Owner' ,
76+ type : 'postgres' ,
77+ host : process . env . POSTGRES_HOST ,
78+ port : Number ( process . env . POSTGRES_PORT ) ,
79+ username : process . env . POSTGRES_ADMIN_USER ,
80+ password : process . env . POSTGRES_ADMIN_PASSWORD ,
81+ database : process . env . POSTGRES_DB ,
82+ entities : [ __dirname + '/../**/*.entity.js' ] ,
83+ synchronize : false ,
84+ logging : [ 'error' ] ,
85+ namingStrategy : new SnakeNamingStrategy ( ) ,
86+ migrationsTableName : 'migrations' ,
87+ migrations : [ __dirname + '/../migrations/*.js' ] ,
88+ ...( process . env . POSTGRES_ADMIN_MAX_CONNECTION_LIMIT
89+ ? { extra : { max : process . env . POSTGRES_ADMIN_MAX_CONNECTION_LIMIT } }
90+ : { } ) ,
91+ } ) . initialize ( ) ;
92+ const con = getConnectionManager ( ) . get ( 'Owner' ) ;
93+ const existingConnection = await Promise . resolve (
94+ con . isConnected ? con : con . connect ( ) ,
95+ ) ;
96+ return existingConnection ;
97+ }
0 commit comments