Skip to content

Commit 1cda98c

Browse files
committed
Fixed Pongo databases and collections identifiers to be unique urns
1 parent aaae02f commit 1cda98c

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/packages/dumbo/src/core/schema/dumboSchema/dumboSchema.unit.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import assert from 'node:assert';
22
import { describe, it } from 'node:test';
33
import { SQL } from '../../sql';
4+
import type { Equal, Expect } from '../../testing';
45
import type { TableRowType } from '../components';
56
import { dumboSchema } from './index';
6-
import type { Expect, Equal } from '../../testing';
77

88
const { database, schema, table, column, index } = dumboSchema;
99
const { Varchar } = SQL.column.type;
@@ -183,9 +183,9 @@ const multiSchemaDb = database('myapp', {
183183

184184
// Access using name-based maps
185185
const publicSchema = multiSchemaDb.schemas.public;
186-
const usersTable = publicSchema.tables.users;
186+
const _usersTable = publicSchema.tables.users;
187187

188-
type Users = TableRowType<typeof usersTable>;
188+
type Users = TableRowType<typeof _usersTable>;
189189

190190
type _IdColumnIsNonNullableString = Expect<Equal<Users['id'], string>>;
191191
type _EmailColumnIsNonNullableString = Expect<Equal<Users['email'], string>>;

src/packages/pongo/src/core/collection/pongoCollectionSchemaComponent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import {
66
} from '@event-driven-io/dumbo';
77
import type { PongoCollectionSchema, PongoCollectionSQLBuilder } from '..';
88

9+
export type PongoCollectionURNType = 'sc:pongo:collection';
10+
export type PongoCollectionURN = `${PongoCollectionURNType}:${string}`;
11+
912
export type PongoCollectionSchemaComponent =
10-
SchemaComponent<'pongo:schema-component:collection'> & {
13+
SchemaComponent<PongoCollectionURN> & {
1114
collectionName: string;
1215
definition: PongoCollectionSchema;
1316
sqlBuilder: PongoCollectionSQLBuilder;
@@ -31,7 +34,7 @@ export const PongoCollectionSchemaComponent = <
3134
}: PongoCollectionSchemaComponentOptions<DriverType>): PongoCollectionSchemaComponent =>
3235
({
3336
...schemaComponent(
34-
'pongo:schema-component:collection',
37+
`sc:pongo:collection:${definition.name}`,
3538
migrationsOrSchemaComponents,
3639
),
3740
sqlBuilder,

src/packages/pongo/src/core/database/pongoDatabaseSchemaComponent.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,17 @@ import {
1414
} from '../schema';
1515
import type { PongoDocument } from '../typing';
1616

17+
export type PongoDatabaseURNType = 'sc:dumbo:database';
18+
export type PongoDatabaseURN = `${PongoDatabaseURNType}:${string}`;
19+
1720
export type PongoDatabaseSchemaComponent<
1821
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1922
DriverType extends DatabaseDriverType = DatabaseDriverType,
2023
T extends Record<string, PongoCollectionSchema> = Record<
2124
string,
2225
PongoCollectionSchema
2326
>,
24-
> = SchemaComponent<'pongo:schema-component:database'> & {
27+
> = SchemaComponent<PongoDatabaseURN> & {
2528
definition: PongoDbSchema<T>;
2629
collections: ReadonlyArray<PongoCollectionSchemaComponent>;
2730

@@ -54,7 +57,7 @@ export const PongoDatabaseSchemaComponent = <
5457
Object.values(definition.collections).map(collectionFactory) ?? [];
5558

5659
return {
57-
...schemaComponent('pongo:schema-component:database', {
60+
...schemaComponent(`sc:dumbo:database:${definition.name}`, {
5861
components: collections,
5962
}),
6063
definition,

0 commit comments

Comments
 (0)