From cc3861ecef1efc928ebe10d84b7f739d27f8dc49 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Fri, 13 Dec 2024 08:16:05 +0200 Subject: [PATCH] ignore postgis tables, prettier ignore file --- .prettierignore | 1 + .../src/utilities/createSchemaGenerator.ts | 3 + test/database/generated-database-schema.ts | 127 ++++++++---------- 3 files changed, 57 insertions(+), 74 deletions(-) diff --git a/.prettierignore b/.prettierignore index 1b3dc0c8ee4..d4c8a540a65 100644 --- a/.prettierignore +++ b/.prettierignore @@ -14,3 +14,4 @@ packages/payload/*.js packages/payload/*.d.ts payload-types.ts tsconfig.tsbuildinfo +test/database/generated-database-schema.ts diff --git a/packages/drizzle/src/utilities/createSchemaGenerator.ts b/packages/drizzle/src/utilities/createSchemaGenerator.ts index 919f19f5f06..7204ced895a 100644 --- a/packages/drizzle/src/utilities/createSchemaGenerator.ts +++ b/packages/drizzle/src/utilities/createSchemaGenerator.ts @@ -112,10 +112,13 @@ export const createSchemaGenerator = ({ ) { const tempDir = path.resolve(os.tmpdir(), uuid()) + const hasPostgis = Boolean((this as any).extensions?.postgis) + const drizzleArgs = { dialect, out: tempDir, schemaFilter, + tablesFilter: hasPostgis ? '!spatial_ref_sys' : undefined, url, } diff --git a/test/database/generated-database-schema.ts b/test/database/generated-database-schema.ts index e1edd9eb6e2..5e9ce3c7c57 100644 --- a/test/database/generated-database-schema.ts +++ b/test/database/generated-database-schema.ts @@ -7,17 +7,16 @@ */ import { pgTable, - check, - integer, - varchar, index, serial, + varchar, boolean, timestamp, geometry, jsonb, foreignKey, unique, + integer, text, uniqueIndex, numeric, @@ -51,25 +50,6 @@ export const enumDefaultValuesSelect = pgEnum('enum_default_values_select', [ export const radioEnum = pgEnum('radioEnum', ['a', 'b', 'c']) export const selectEnum = pgEnum('selectEnum', ['a', 'b', 'c']) -export const spatialRefSys = pgTable( - 'spatial_ref_sys', - { - srid: integer().primaryKey().notNull(), - authName: varchar('auth_name', { length: 256 }), - authSrid: integer('auth_srid'), - srtext: varchar({ length: 2048 }), - proj4Text: varchar({ length: 2048 }), - }, - (table) => { - return { - spatialRefSysSridCheck: check( - 'spatial_ref_sys_srid_check', - sql`(srid > 0) AND (srid <= 998999)`, - ), - } - }, -) - export const posts = pgTable( 'posts', { @@ -549,40 +529,6 @@ export const pgMigrationsV = pgTable( }, ) -export const pgMigrationsVBlocksMyBlockLocales = pgTable( - '_pg_migrations_v_blocks_my_block_locales', - { - relation6Id: integer('relation6_id'), - id: serial().primaryKey().notNull(), - locale: locales('_locale').notNull(), - parentId: integer('_parent_id').notNull(), - }, - (table) => { - return { - pgMigrationsVBlocksMyBlockRelation6Idx: index( - '_pg_migrations_v_blocks_my_block_relation6_idx', - ).using( - 'btree', - table.relation6Id.asc().nullsLast().op('int4_ops'), - table.locale.asc().nullsLast().op('int4_ops'), - ), - pgMigrationsVBlocksMyBlockLocalesRelation6IdRelation: foreignKey({ - columns: [table.relation6Id], - foreignColumns: [relationB.id], - name: '_pg_migrations_v_blocks_my_block_locales_relation6_id_relation_', - }).onDelete('set null'), - pgMigrationsVBlocksMyBlockLocalesParentIdFk: foreignKey({ - columns: [table.parentId], - foreignColumns: [pgMigrationsVBlocksMyBlock.id], - name: '_pg_migrations_v_blocks_my_block_locales_parent_id_fk', - }).onDelete('cascade'), - pgMigrationsVBlocksMyBlockLocalesLocaleParentIdUniqu: unique( - '_pg_migrations_v_blocks_my_block_locales_locale_parent_id_uniqu', - ).on(table.locale, table.parentId), - } - }, -) - export const pgMigrationsVLocales = pgTable( '_pg_migrations_v_locales', { @@ -1839,6 +1785,40 @@ export const pgMigrationsVVersionMyArrayMySubArray = pgTable( }, ) +export const pgMigrationsVBlocksMyBlockLocales = pgTable( + '_pg_migrations_v_blocks_my_block_locales', + { + relation6Id: integer('relation6_id'), + id: serial().primaryKey().notNull(), + locale: locales('_locale').notNull(), + parentId: integer('_parent_id').notNull(), + }, + (table) => { + return { + pgMigrationsVBlocksMyBlockRelation6Idx: index( + '_pg_migrations_v_blocks_my_block_relation6_idx', + ).using( + 'btree', + table.relation6Id.asc().nullsLast().op('int4_ops'), + table.locale.asc().nullsLast().op('int4_ops'), + ), + pgMigrationsVBlocksMyBlockLocalesRelation6IdRelation: foreignKey({ + columns: [table.relation6Id], + foreignColumns: [relationB.id], + name: '_pg_migrations_v_blocks_my_block_locales_relation6_id_relation_', + }).onDelete('set null'), + pgMigrationsVBlocksMyBlockLocalesParentIdFk: foreignKey({ + columns: [table.parentId], + foreignColumns: [pgMigrationsVBlocksMyBlock.id], + name: '_pg_migrations_v_blocks_my_block_locales_parent_id_fk', + }).onDelete('cascade'), + pgMigrationsVBlocksMyBlockLocalesLocaleParentIdUniqu: unique( + '_pg_migrations_v_blocks_my_block_locales_locale_parent_id_uniqu', + ).on(table.locale, table.parentId), + } + }, +) + export const customIdsV = pgTable( '_custom_ids_v', { @@ -1975,13 +1955,13 @@ export const relationBRelations = relations(relationB, ({ one, many }) => ({ pgMigrationsMyArrays: many(pgMigrationsMyArray), pgMigrationsVVersionMyArrayMySubArrayLocales: many(pgMigrationsVVersionMyArrayMySubArrayLocales), pgMigrationsVVersionMyArrays: many(pgMigrationsVVersionMyArray), - pgMigrationsVBlocksMyBlockLocales: many(pgMigrationsVBlocksMyBlockLocales), pgMigrationsVLocales: many(pgMigrationsVLocales), payloadLockedDocumentsRels: many(payloadLockedDocumentsRels), relationA: one(relationA, { fields: [relationB.relationshipId], references: [relationA.id], }), + pgMigrationsVBlocksMyBlockLocales: many(pgMigrationsVBlocksMyBlockLocales), })) export const pgMigrationsMyArrayMySubArrayRelations = relations( @@ -2141,20 +2121,6 @@ export const pgMigrationsVVersionMyArrayRelations = relations( }), ) -export const pgMigrationsVBlocksMyBlockLocalesRelations = relations( - pgMigrationsVBlocksMyBlockLocales, - ({ one }) => ({ - relationB: one(relationB, { - fields: [pgMigrationsVBlocksMyBlockLocales.relation6Id], - references: [relationB.id], - }), - pgMigrationsVBlocksMyBlock: one(pgMigrationsVBlocksMyBlock, { - fields: [pgMigrationsVBlocksMyBlockLocales.parentId], - references: [pgMigrationsVBlocksMyBlock.id], - }), - }), -) - export const pgMigrationsVLocalesRelations = relations(pgMigrationsVLocales, ({ one }) => ({ relationB: one(relationB, { fields: [pgMigrationsVLocales.versionMyGroupRelation4Id], @@ -2461,6 +2427,20 @@ export const defaultValuesArrayRelations = relations(defaultValuesArray, ({ one }), })) +export const pgMigrationsVBlocksMyBlockLocalesRelations = relations( + pgMigrationsVBlocksMyBlockLocales, + ({ one }) => ({ + relationB: one(relationB, { + fields: [pgMigrationsVBlocksMyBlockLocales.relation6Id], + references: [relationB.id], + }), + pgMigrationsVBlocksMyBlock: one(pgMigrationsVBlocksMyBlock, { + fields: [pgMigrationsVBlocksMyBlockLocales.parentId], + references: [pgMigrationsVBlocksMyBlock.id], + }), + }), +) + export const customIdsVRelations = relations(customIdsV, ({ one }) => ({ customId: one(customIds, { fields: [customIdsV.parentId], @@ -2494,7 +2474,6 @@ export type DatabaseSchema = { enumDefaultValuesSelect: typeof enumDefaultValuesSelect radioEnum: typeof radioEnum selectEnum: typeof selectEnum - spatialRefSys: typeof spatialRefSys posts: typeof posts defaultValues: typeof defaultValues relationA: typeof relationA @@ -2508,7 +2487,6 @@ export type DatabaseSchema = { pgMigrationsVBlocksMyBlock: typeof pgMigrationsVBlocksMyBlock pgMigrationsVVersionMyArray: typeof pgMigrationsVVersionMyArray pgMigrationsV: typeof pgMigrationsV - pgMigrationsVBlocksMyBlockLocales: typeof pgMigrationsVBlocksMyBlockLocales pgMigrationsVLocales: typeof pgMigrationsVLocales customsCustomSelect: typeof customsCustomSelect customBlocks: typeof customBlocks @@ -2545,6 +2523,7 @@ export type DatabaseSchema = { relationB: typeof relationB pgMigrationsMyArrayMySubArray: typeof pgMigrationsMyArrayMySubArray pgMigrationsVVersionMyArrayMySubArray: typeof pgMigrationsVVersionMyArrayMySubArray + pgMigrationsVBlocksMyBlockLocales: typeof pgMigrationsVBlocksMyBlockLocales customIdsV: typeof customIdsV payloadPreferencesRels: typeof payloadPreferencesRels pgMigrationsMyArrayMySubArrayLocalesRelations: typeof pgMigrationsMyArrayMySubArrayLocalesRelations @@ -2561,7 +2540,6 @@ export type DatabaseSchema = { pgMigrationsVBlocksMyBlockRelations: typeof pgMigrationsVBlocksMyBlockRelations pgMigrationsVRelations: typeof pgMigrationsVRelations pgMigrationsVVersionMyArrayRelations: typeof pgMigrationsVVersionMyArrayRelations - pgMigrationsVBlocksMyBlockLocalesRelations: typeof pgMigrationsVBlocksMyBlockLocalesRelations pgMigrationsVLocalesRelations: typeof pgMigrationsVLocalesRelations customsCustomSelectRelations: typeof customsCustomSelectRelations customsRelations: typeof customsRelations @@ -2593,6 +2571,7 @@ export type DatabaseSchema = { fakeCustomIdsRelations: typeof fakeCustomIdsRelations usersRelations: typeof usersRelations defaultValuesArrayRelations: typeof defaultValuesArrayRelations + pgMigrationsVBlocksMyBlockLocalesRelations: typeof pgMigrationsVBlocksMyBlockLocalesRelations customIdsVRelations: typeof customIdsVRelations payloadPreferencesRelsRelations: typeof payloadPreferencesRelsRelations payloadPreferencesRelations: typeof payloadPreferencesRelations