Skip to content

Commit b79639f

Browse files
authored
Drop postgres (#2912)
1 parent aed8664 commit b79639f

30 files changed

+20
-5059
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
"nestjs-console": "^9.0.0",
8686
"p-retry": "^5.1.2",
8787
"pako": "^2.1.0",
88-
"pg": "^8.11.3",
8988
"pkg-up": "^4.0.0",
9089
"plur": "^5.1.0",
9190
"prismjs-terminal": "^1.2.2",
@@ -118,7 +117,6 @@
118117
"@types/luxon": "^3.3.1",
119118
"@types/node": "^18.17.7",
120119
"@types/pako": "^2.0.0",
121-
"@types/pg": "^8.10.2",
122120
"@types/prismjs": "^1.26.0",
123121
"@types/react": "^18.2.20",
124122
"@types/stack-trace": "^0.0.30",

src/core/config/config.service.ts

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import LRUCache from 'lru-cache';
99
import { Duration, DurationLike } from 'luxon';
1010
import { nanoid } from 'nanoid';
1111
import { Config as Neo4JDriverConfig } from 'neo4j-driver';
12-
import { PoolConfig } from 'pg';
1312
import { keys as keysOf } from 'ts-transformer-keys';
1413
import { Class, Merge, ReadonlyDeep } from 'type-fest';
1514
import { csv, ID, ServerException } from '../../common';
@@ -177,30 +176,8 @@ export const makeConfig = (env: EnvironmentService) =>
177176
};
178177
})();
179178

180-
postgres = (() => {
181-
// Put the PG* env vars in the global env, so the library can use them.
182-
// There's dozens of them, so we'll just pass them through implicitly.
183-
for (const [key, value] of env) {
184-
if (key.startsWith('PG')) {
185-
process.env[key] = value;
186-
}
187-
}
188-
/* eslint-disable @typescript-eslint/naming-convention */
189-
const config: PoolConfig = {
190-
application_name: env.string('PGAPPNAME').optional('cord_api'),
191-
connectionString:
192-
env.string('PGURI').optional() ??
193-
env
194-
.string('PGURL')
195-
.optional('postgres://postgres:postgres@localhost/cord'),
196-
};
197-
/* eslint-enable @typescript-eslint/naming-convention */
198-
return config;
199-
})();
200-
201-
// Control which database is prioritized, while we migrate to postgres
202-
database = env.string('DATABASE').optional('neo4j');
203-
usePostgres = this.database.toLowerCase() === 'postgres';
179+
// Control which database is prioritized, while we migrate.
180+
databaseEngine = env.string('DATABASE').optional('neo4j').toLowerCase();
204181

205182
dbIndexesCreate = env.boolean('DB_CREATE_INDEXES').optional(true);
206183
dbAutoMigrate = env

src/core/core.module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { EventsModule } from './events';
1414
import { ExceptionFilter } from './exception/exception.filter';
1515
import { ExceptionNormalizer } from './exception/exception.normalizer';
1616
import { GraphqlModule } from './graphql';
17-
import { PostgresModule } from './postgres/postgres.module';
1817
import { ResourceModule } from './resources/resource.module';
1918
import { ScalarProviders } from './scalars.resolver';
2019
import { TimeoutInterceptor } from './timeout.interceptor';
@@ -34,7 +33,6 @@ import { WaitResolver } from './wait.resolver';
3433
GraphqlModule,
3534
EventsModule,
3635
TracingModule,
37-
PostgresModule,
3836
ResourceModule,
3937
],
4038
providers: [
@@ -59,7 +57,6 @@ import { WaitResolver } from './wait.resolver';
5957
EventsModule,
6058
ResourceModule,
6159
TracingModule,
62-
PostgresModule,
6360
],
6461
})
6562
export class CoreModule {}

src/core/database/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './indexer';
88
export * from './migration';
99
export * from './db-type';
1010
export * from './rollback-manager';
11+
export * from './split-db.provider';
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Provider, Type } from '@nestjs/common';
2+
import { ModuleRef } from '@nestjs/core';
3+
import type { PublicOf } from '~/common';
4+
import { ConfigService } from '../config/config.service';
5+
6+
export const splitDb = <T>(
7+
neo4jRepository: Type<T>,
8+
edgeDbRepository: Type<PublicOf<T>>,
9+
): Provider => ({
10+
provide: neo4jRepository,
11+
inject: [ModuleRef, ConfigService],
12+
useFactory: async (moduleRef: ModuleRef, config: ConfigService) => {
13+
const cls =
14+
config.databaseEngine === 'edgedb' ? edgeDbRepository : neo4jRepository;
15+
return await moduleRef.create<T>(cls);
16+
},
17+
});

src/core/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export * from './core.module';
55
export * from './cache';
66
export * from './graphql';
77
export * from './database';
8-
export * from './postgres';
98
export * from './events';
109
export * from './resources';
1110
export * from './data-loader';

src/core/postgres/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/core/postgres/pg.service.ts

Lines changed: 0 additions & 123 deletions
This file was deleted.

src/core/postgres/postgres.module.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

src/core/postgres/split-db.provider.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)