@smartive/graphql-magic 23.7.0 → 23.8.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -100,7 +100,12 @@ const createProductModels = (constraints: { kind: 'check'; name: string; express
100
100
  };
101
101
 
102
102
  const createGenerator = (rows: CheckRow[], models: Models) => {
103
- const raw = jest.fn().mockResolvedValue({ rows });
103
+ const raw = jest
104
+ .fn()
105
+ .mockResolvedValueOnce({ rows })
106
+ .mockResolvedValueOnce({ rows: [] })
107
+ .mockResolvedValueOnce({ rows: [] })
108
+ .mockResolvedValue({ rows: [] });
104
109
  const knexLike = Object.assign(
105
110
  jest.fn().mockReturnValue({
106
111
  where: jest.fn().mockReturnValue({
@@ -261,6 +266,47 @@ describe('MigrationGenerator check constraints', () => {
261
266
  });
262
267
  });
263
268
 
269
+ describe('MigrationGenerator exclude constraints', () => {
270
+ const excludeModels = new Models([
271
+ {
272
+ kind: 'entity',
273
+ name: 'PortfolioAllocation',
274
+ updatable: false,
275
+ fields: [
276
+ { name: 'portfolioId', type: 'UUID' },
277
+ { name: 'startDate', type: 'DateTime' },
278
+ { name: 'endDate', type: 'DateTime' },
279
+ { name: 'deleted', type: 'Boolean' },
280
+ ],
281
+ constraints: [
282
+ {
283
+ kind: 'exclude' as const,
284
+ name: 'no_overlap_per_portfolio',
285
+ using: 'gist' as const,
286
+ elements: [
287
+ { column: 'portfolioId', operator: '=' as const },
288
+ {
289
+ expression: 'tstzrange("startDate", COALESCE("endDate", \'infinity\'::timestamptz))',
290
+ operator: '&&' as const,
291
+ },
292
+ ],
293
+ where: '"deleted" = false',
294
+ deferrable: 'INITIALLY DEFERRED' as const,
295
+ },
296
+ ],
297
+ },
298
+ ]);
299
+
300
+ it('normalizes equivalent EXCLUDE defs (type alias, WHERE parens, identifier quoting)', () => {
301
+ const dbDef = `EXCLUDE USING gist ("portfolioId" WITH =, tstzrange("startDate", COALESCE("endDate", 'infinity'::timestamp with time zone)) WITH &&) WHERE ((deleted = false)) DEFERRABLE INITIALLY DEFERRED`;
302
+ const modelDef = `EXCLUDE USING gist ("portfolioId" WITH =, tstzrange("startDate", COALESCE("endDate", 'infinity'::timestamptz)) WITH &&) WHERE ("deleted" = false) DEFERRABLE INITIALLY DEFERRED`;
303
+ const gen = new MigrationGenerator({} as never, excludeModels);
304
+ const norm1 = (gen as any).normalizeExcludeDef(dbDef);
305
+ const norm2 = (gen as any).normalizeExcludeDef(modelDef);
306
+ expect(norm1).toBe(norm2);
307
+ });
308
+ });
309
+
264
310
  describe('MigrationGenerator canonicalizeCheckExpressionWithPostgres', () => {
265
311
  afterEach(() => {
266
312
  jest.restoreAllMocks();