From 7893f1af0ac6126570f70f596e3c404718adf85f Mon Sep 17 00:00:00 2001 From: Sophie <29753584+Druue@users.noreply.github.com> Date: Tue, 21 Mar 2023 10:40:23 +0100 Subject: [PATCH] Added code 27 :: partitioned found (#18386) Added tests for singular & multiple partitioned tables --- packages/migrate/src/__tests__/DbPull.test.ts | 650 +++++++++++------- .../partitioned-warning-27-1/schema.prisma | 8 + .../partitioned-warning-27-1/setup.sql | 15 + .../partitioned-warning-27-2/schema.prisma | 8 + .../partitioned-warning-27-2/setup.sql | 25 + packages/migrate/src/commands/DbPull.ts | 2 + packages/migrate/src/types.ts | 9 + 7 files changed, 473 insertions(+), 244 deletions(-) create mode 100644 packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/schema.prisma create mode 100644 packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/setup.sql create mode 100644 packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/schema.prisma create mode 100644 packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/setup.sql diff --git a/packages/migrate/src/__tests__/DbPull.test.ts b/packages/migrate/src/__tests__/DbPull.test.ts index 8f5c34c26afb..8c1d052085fc 100644 --- a/packages/migrate/src/__tests__/DbPull.test.ts +++ b/packages/migrate/src/__tests__/DbPull.test.ts @@ -190,20 +190,20 @@ describe('common/sqlite', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/reintrospection.prisma + - Introspecting based on datasource defined in prisma/reintrospection.prisma - ✔ Introspected 3 models and wrote them into prisma/reintrospection.prisma in XXXms - - *** WARNING *** + ✔ Introspected 3 models and wrote them into prisma/reintrospection.prisma in XXXms + + *** WARNING *** - These models were enriched with \`@@map\` information taken from the previous Prisma schema. - - Model "AwesomeNewPost" - - Model "AwesomeProfile" - - Model "AwesomeUser" + These models were enriched with \`@@map\` information taken from the previous Prisma schema. + - Model "AwesomeNewPost" + - Model "AwesomeProfile" + - Model "AwesomeUser" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.fs.read('prisma/reintrospection.prisma')).toMatchInlineSnapshot(` @@ -260,14 +260,14 @@ describe('common/sqlite', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These models were enriched with \`@@map\` information taken from the previous Prisma schema. - // - Model "AwesomeNewPost" - // - Model "AwesomeProfile" - // - Model "AwesomeUser" - // - `) + // *** WARNING *** + // + // These models were enriched with \`@@map\` information taken from the previous Prisma schema. + // - Model "AwesomeNewPost" + // - Model "AwesomeProfile" + // - Model "AwesomeUser" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) @@ -413,11 +413,11 @@ describe('common/sqlite', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/invalid.prisma + - Introspecting based on datasource defined in prisma/invalid.prisma - ✖ Introspecting based on datasource defined in prisma/invalid.prisma + ✖ Introspecting based on datasource defined in prisma/invalid.prisma - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -436,13 +436,13 @@ describe('common/sqlite', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/invalid.prisma + - Introspecting based on datasource defined in prisma/invalid.prisma - ✔ Introspected 3 models and wrote them into prisma/invalid.prisma in XXXms - - Run prisma generate to generate Prisma Client. + ✔ Introspected 3 models and wrote them into prisma/invalid.prisma in XXXms + + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.fs.read('prisma/invalid.prisma')).toMatchSnapshot() @@ -562,15 +562,15 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - Model "reservations", field: "dates", original data type: "daterange" - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - View "res", Field: "dates", Type: "daterange" - // - `) + // *** WARNING *** + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - Model "reservations", field: "dates", original data type: "daterange" + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - View "res", Field: "dates", Type: "daterange" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -620,16 +620,16 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - Model "reservations", field: "dates", original data type: "daterange" - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - View "res", Field: "dates", Type: "daterange" - // - View "dates", Field: "dates", Type: "daterange" - // - `) + // *** WARNING *** + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - Model "reservations", field: "dates", original data type: "daterange" + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - View "res", Field: "dates", Type: "daterange" + // - View "dates", Field: "dates", Type: "daterange" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -666,12 +666,12 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These fields were enriched with \`@map\` information taken from the previous Prisma schema. - // - View "A", Field: "id" - // - `) + // *** WARNING *** + // + // These fields were enriched with \`@map\` information taken from the previous Prisma schema. + // - View "A", Field: "id" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -712,13 +712,13 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These fields were enriched with \`@map\` information taken from the previous Prisma schema. - // - View "A", Field: "id" - // - View "B", Field: "id" - // - `) + // *** WARNING *** + // + // These fields were enriched with \`@map\` information taken from the previous Prisma schema. + // - View "A", Field: "id" + // - View "B", Field: "id" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -756,12 +756,12 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These views were enriched with \`@@map\` information taken from the previous Prisma schema. - // - View "Renamedif" - // - `) + // *** WARNING *** + // + // These views were enriched with \`@@map\` information taken from the previous Prisma schema. + // - View "Renamedif" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -808,12 +808,12 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "Schwuser" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "Schwuser" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -852,12 +852,12 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These views were enriched with custom compound id names taken from the previous Prisma schema. - // - View "B" - // - `) + // *** WARNING *** + // + // These views were enriched with custom compound id names taken from the previous Prisma schema. + // - View "B" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -898,15 +898,15 @@ describe('postgresql views re-introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "A" - // - // These fields were commented out because their names are currently not supported by Prisma. Please provide valid ones that match [a-zA-Z][a-zA-Z0-9_]* using the \`@map\` attribute. - // - View "A", Field: "1" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "A" + // + // These fields were commented out because their names are currently not supported by Prisma. Please provide valid ones that match [a-zA-Z][a-zA-Z0-9_]* using the \`@map\` attribute. + // - View "A", Field: "1" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -996,18 +996,18 @@ describe('postgresql views introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "res" - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - Model "reservations", field: "dates", original data type: "daterange" - // - // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. - // - View "res", Field: "dates", Type: "daterange" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "res" + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - Model "reservations", field: "dates", original data type: "daterange" + // + // These fields are not supported by the Prisma Client, because Prisma currently does not support their types. + // - View "res", Field: "dates", Type: "daterange" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1060,12 +1060,12 @@ describe('postgresql views introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "Schwuser" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "Schwuser" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1121,13 +1121,13 @@ describe('postgresql views introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "Schwuser" - // - View "Names" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "Schwuser" + // - View "Names" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1170,15 +1170,177 @@ describe('postgresql views introspection warnings', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers - // - View "A" - // - // These fields were commented out because their names are currently not supported by Prisma. Please provide valid ones that match [a-zA-Z][a-zA-Z0-9_]* using the \`@map\` attribute. - // - View "A", Field: "1" - // - `) + // *** WARNING *** + // + // The following views were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. Please refer to the documentation on defining unique identifiers in views: https://pris.ly/d/view-identifiers + // - View "A" + // + // These fields were commented out because their names are currently not supported by Prisma. Please provide valid ones that match [a-zA-Z][a-zA-Z0-9_]* using the \`@map\` attribute. + // - View "A", Field: "1" + // + `) + expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + }) + }) +}) + +describe('postgresql partitioned tables introspection', () => { + const connectionString = process.env.TEST_POSTGRES_URI_MIGRATE!.replace('tests-migrate', 'tests-migrate-db-pull') + + const computeSetupParams = (warningCode: number, variant?: number): SetupParams => { + const setupParams: SetupParams = { + connectionString, + // Note: dirname points to a location with a setup.sql file + // which will be executed to prepare the database with the correct tables, views etc. + dirname: path.join( + __dirname, + '..', + '__tests__', + 'fixtures', + 'introspection', + 'postgresql', + `partitioned-warning-${warningCode}${variant ? `-${variant}` : ''}`, + ), + } + return setupParams + } + + const setupPostgressForWarning = (warningCode: number, variant?: number) => { + const setupParams = computeSetupParams(warningCode, variant) + + beforeEach(async () => { + await setupPostgres(setupParams) + + // Back to original env vars + process.env = { ...originalEnv } + // Update env var because it's the one that is used in the schemas tested + process.env.TEST_POSTGRES_URI_MIGRATE = connectionString + }) + + afterEach(async () => { + // Back to original env vars + process.env = { ...originalEnv } + await tearDownPostgres(setupParams).catch((e) => { + console.error(e) + }) + }) + } + + describe('postgres partioned 27/1 - partitioned tables found', () => { + const warningCode = 27 + const variant = 1 + setupPostgressForWarning(warningCode, variant) + + test('basic introspection', async () => { + ctx.fixture(`introspection/postgresql/partitioned-warning-${warningCode}-${variant}`) + const introspect = new DbPull() + const result = introspect.parse(['--print']) + + await expect(result).resolves.toMatchInlineSnapshot(``) + + expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(` + generator client { + provider = "prisma-client-js" + } + + datasource db { + provider = "postgres" + url = env("TEST_POSTGRES_URI_MIGRATE") + } + + /// This table is a partition table and requires additional setup for migrations. Visit https://pris.ly/d/partition-tables for more info. + /// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client. + model measurement { + city_id Int + logdate DateTime @db.Date + peaktemp Int? + unitsales Int? + + @@ignore + } + + + // introspectionSchemaVersion: NonPrisma, + `) + expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` + + // *** WARNING *** + // + // The following models were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. + // - "measurement" + // + // These tables are partition tables, which are not yet fully supported. + // - Model "measurement" + // + `) + expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + }) + }) + + describe('postgres partioned 27/2 - multiple partitioned tables found', () => { + const warningCode = 27 + const variant = 2 + setupPostgressForWarning(warningCode, variant) + + test('basic introspection', async () => { + ctx.fixture(`introspection/postgresql/partitioned-warning-${warningCode}-${variant}`) + const introspect = new DbPull() + const result = introspect.parse(['--print']) + + await expect(result).resolves.toMatchInlineSnapshot(``) + + expect(ctx.mocked['console.log'].mock.calls.join('\n')).toMatchInlineSnapshot(` + generator client { + provider = "prisma-client-js" + } + + datasource db { + provider = "postgres" + url = env("TEST_POSTGRES_URI_MIGRATE") + } + + /// This table is a partition table and requires additional setup for migrations. Visit https://pris.ly/d/partition-tables for more info. + /// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client. + model definitely_not_measurement { + city_id Int + logdate DateTime @db.Date + peaktemp Int? + unitsales Int? + + @@ignore + } + + /// This table is a partition table and requires additional setup for migrations. Visit https://pris.ly/d/partition-tables for more info. + /// The underlying table does not contain a valid unique identifier and can therefore currently not be handled by the Prisma Client. + model measurement { + city_id Int + logdate DateTime @db.Date + peaktemp Int? + unitsales Int? + + @@ignore + } + + + // introspectionSchemaVersion: NonPrisma, + `) + expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) + expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` + + // *** WARNING *** + // + // The following models were ignored as they do not have a valid unique identifier or id. This is currently not supported by the Prisma Client. + // - "definitely_not_measurement" + // - "measurement" + // + // These tables are partition tables, which are not yet fully supported. + // - Model "definitely_not_measurement" + // - Model "measurement" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1282,11 +1444,11 @@ describe('postgresql', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/using-dotenv.prisma + - Introspecting based on datasource defined in prisma/using-dotenv.prisma - ✖ Introspecting based on datasource defined in prisma/using-dotenv.prisma + ✖ Introspecting based on datasource defined in prisma/using-dotenv.prisma - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1327,13 +1489,13 @@ describe('postgresql', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in with-directUrl-env.prisma + - Introspecting based on datasource defined in with-directUrl-env.prisma - ✔ Introspected 2 models and wrote them into with-directUrl-env.prisma in XXXms - - Run prisma generate to generate Prisma Client. + ✔ Introspected 2 models and wrote them into with-directUrl-env.prisma in XXXms + + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) }) @@ -1422,15 +1584,15 @@ describe('postgresql-multi-schema', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These models and enums were renamed due to their names being duplicates in the Prisma Schema Language. - // - Enum "base_status" - // - Enum "transactional_status" - // - Model "base_some_table" - // - Model "transactional_some_table" - // - `) + // *** WARNING *** + // + // These models and enums were renamed due to their names being duplicates in the Prisma Schema Language. + // - Enum "base_status" + // - Enum "transactional_status" + // - Model "base_some_table" + // - Model "transactional_some_table" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -1548,15 +1710,15 @@ describe('postgresql-multi-schema', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These models and enums were renamed due to their names being duplicates in the Prisma Schema Language. - // - Enum "base_status" - // - Enum "transactional_status" - // - Model "base_some_table" - // - Model "transactional_some_table" - // - `) + // *** WARNING *** + // + // These models and enums were renamed due to their names being duplicates in the Prisma Schema Language. + // - Enum "base_status" + // - Enum "transactional_status" + // - Model "base_some_table" + // - Model "transactional_some_table" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2011,20 +2173,20 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/no-model.prisma + - Introspecting based on datasource defined in prisma/no-model.prisma - ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/no-model.prisma in XXXms - - *** WARNING *** - - The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - - Model "users", field: "numberOrString1", chosen data type: "Json" - - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/no-model.prisma in XXXms + + *** WARNING *** + + The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + - Model "users", field: "numberOrString1", chosen data type: "Json" + - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2042,20 +2204,20 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/schema.prisma + - Introspecting based on datasource defined in prisma/schema.prisma - ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms - - *** WARNING *** - - The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - - Model "users", field: "numberOrString1", chosen data type: "Json" - - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms + + *** WARNING *** + + The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + - Model "users", field: "numberOrString1", chosen data type: "Json" + - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2105,14 +2267,14 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - // - Model "users", field: "numberOrString1", chosen data type: "Json" - // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - // - `) + // *** WARNING *** + // + // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + // - Model "users", field: "numberOrString1", chosen data type: "Json" + // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2148,12 +2310,12 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - // - Model "users", field: "numberOrString1", chosen data type: "Json" - // - `) + // *** WARNING *** + // + // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + // - Model "users", field: "numberOrString1", chosen data type: "Json" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2197,13 +2359,13 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - // - Model "users", field: "numberOrString1", chosen data type: "Json" - // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - // - `) + // *** WARNING *** + // + // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + // - Model "users", field: "numberOrString1", chosen data type: "Json" + // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2222,20 +2384,20 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/schema.prisma + - Introspecting based on datasource defined in prisma/schema.prisma - ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms - - *** WARNING *** - - The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - - Model "users", field: "numberOrString1", chosen data type: "Json" - - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms + + *** WARNING *** + + The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + - Model "users", field: "numberOrString1", chosen data type: "Json" + - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2285,14 +2447,14 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - // - Model "users", field: "numberOrString1", chosen data type: "Json" - // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - // - `) + // *** WARNING *** + // + // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + // - Model "users", field: "numberOrString1", chosen data type: "Json" + // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2305,14 +2467,14 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - // - Model "users", field: "numberOrString1", chosen data type: "Json" - // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - // - `) + // *** WARNING *** + // + // The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + // - Model "users", field: "numberOrString1", chosen data type: "Json" + // - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + // - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2332,20 +2494,20 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting + - Introspecting - ✔ Introspected 1 model and 2 embedded documents and wrote them into schema.prisma in XXXms - - *** WARNING *** - - The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - - Model "users", field: "numberOrString1", chosen data type: "Json" - - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + ✔ Introspected 1 model and 2 embedded documents and wrote them into schema.prisma in XXXms + + *** WARNING *** + + The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + - Model "users", field: "numberOrString1", chosen data type: "Json" + - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2363,20 +2525,20 @@ describeIf(!process.env.TEST_SKIP_MONGODB)('MongoDB', () => { expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(` - - Introspecting based on datasource defined in prisma/schema.prisma + - Introspecting based on datasource defined in prisma/schema.prisma - ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms - - *** WARNING *** - - The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. - - Model "users", field: "numberOrString1", chosen data type: "Json" - - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" - - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" + ✔ Introspected 1 model and 2 embedded documents and wrote them into prisma/schema.prisma in XXXms + + *** WARNING *** + + The following fields had data stored in multiple types. Either use Json or normalize data to the wanted type. + - Model "users", field: "numberOrString1", chosen data type: "Json" + - Type "UsersHobbies", field: "numberOrString2", chosen data type: "Json" + - Type "UsersHobbiesObjects", field: "numberOrString3", chosen data type: "Json" - Run prisma generate to generate Prisma Client. + Run prisma generate to generate Prisma Client. - `) + `) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) @@ -2501,13 +2663,13 @@ describeIf(!process.env.TEST_SKIP_MSSQL)('sqlserver-multi-schema', () => { expect(ctx.mocked['console.info'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['console.error'].mock.calls.join('\n')).toMatchInlineSnapshot(` - // *** WARNING *** - // - // These models were renamed due to their names being duplicates in the Prisma Schema Language. - // - Model "base_some_table" - // - Model "transactional_some_table" - // - `) + // *** WARNING *** + // + // These models were renamed due to their names being duplicates in the Prisma Schema Language. + // - Model "base_some_table" + // - Model "transactional_some_table" + // + `) expect(ctx.mocked['process.stdout.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) expect(ctx.mocked['process.stderr.write'].mock.calls.join('\n')).toMatchInlineSnapshot(``) }) diff --git a/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/schema.prisma b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/schema.prisma new file mode 100644 index 000000000000..7639f0bbed3d --- /dev/null +++ b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/schema.prisma @@ -0,0 +1,8 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgres" + url = env("TEST_POSTGRES_URI_MIGRATE") +} diff --git a/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/setup.sql b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/setup.sql new file mode 100644 index 000000000000..e0df8e8519fc --- /dev/null +++ b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-1/setup.sql @@ -0,0 +1,15 @@ +CREATE TABLE measurement ( + city_id int not null, + logdate date not null, + peaktemp int, + unitsales int +) PARTITION BY RANGE (logdate); + +CREATE TABLE measurement_y2019m01 PARTITION OF measurement + FOR VALUES FROM ('2019-01-01') TO ('2019-02-01'); + +CREATE TABLE measurement_y2019m02 PARTITION OF measurement + FOR VALUES FROM ('2019-02-01') TO ('2019-03-01'); + +CREATE TABLE measurement_y2019m03 PARTITION OF measurement + FOR VALUES FROM ('2019-03-01') TO ('2019-04-01'); \ No newline at end of file diff --git a/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/schema.prisma b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/schema.prisma new file mode 100644 index 000000000000..7639f0bbed3d --- /dev/null +++ b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/schema.prisma @@ -0,0 +1,8 @@ +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgres" + url = env("TEST_POSTGRES_URI_MIGRATE") +} diff --git a/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/setup.sql b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/setup.sql new file mode 100644 index 000000000000..f450c9faecfa --- /dev/null +++ b/packages/migrate/src/__tests__/fixtures/introspection/postgresql/partitioned-warning-27-2/setup.sql @@ -0,0 +1,25 @@ +CREATE TABLE measurement ( + city_id int not null, + logdate date not null, + peaktemp int, + unitsales int +) PARTITION BY RANGE (logdate); + +CREATE TABLE measurement_y2019m01 PARTITION OF measurement + FOR VALUES FROM ('2019-01-01') TO ('2019-02-01'); + +CREATE TABLE measurement_y2019m02 PARTITION OF measurement + FOR VALUES FROM ('2019-02-01') TO ('2019-03-01'); + +CREATE TABLE measurement_y2019m03 PARTITION OF measurement + FOR VALUES FROM ('2019-03-01') TO ('2019-04-01'); + +CREATE TABLE definitely_not_measurement ( + city_id int not null, + logdate date not null, + peaktemp int, + unitsales int +) PARTITION BY RANGE (logdate); + +CREATE TABLE definitely_not_measurement_y2019m01 PARTITION OF definitely_not_measurement + FOR VALUES FROM ('2019-01-01') TO ('2019-02-01'); \ No newline at end of file diff --git a/packages/migrate/src/commands/DbPull.ts b/packages/migrate/src/commands/DbPull.ts index c211c200bb6c..c8e123a8e7fc 100644 --- a/packages/migrate/src/commands/DbPull.ts +++ b/packages/migrate/src/commands/DbPull.ts @@ -480,6 +480,8 @@ ${`Run ${chalk.green(getCommandWithExecutor('prisma generate'))} to generate Pri message += warning.affected.map((it) => `- View "${it.view}", Field: "${it.field}"`).join('\n') } else if ([23, 24, 25].includes(warning.code)) { message += warning.affected.map((it) => `- View "${it.view}"`).join('\n') + } else if (warning.code === 27) { + message += warning.affected.map((it) => `- Model "${it.model}"`).join('\n') } else if (warning.code === 101) { message += warning.affected .map((it) => { diff --git a/packages/migrate/src/types.ts b/packages/migrate/src/types.ts index ec1718c049e9..7b142476e128 100644 --- a/packages/migrate/src/types.ts +++ b/packages/migrate/src/types.ts @@ -188,6 +188,8 @@ export namespace EngineArgs { | IntrospectionWarningsViewsWithoutIdentifier | IntrospectionWarningsEnrichedWithCustomPrimaryKeyNamesInViews | IntrospectionWarningsFieldsWithEmptyNamesInViews + // Partioned Tables + | IntrospectionWarningsPartionedTablesFound // MongoDB below | IntrospectionWarningsMongoMultipleTypes | IntrospectionWarningsMongoFieldsPointingToAnEmptyType @@ -321,6 +323,7 @@ export namespace EngineArgs { affected: AffectedTopLevel[] } + // Views interface IntrospectionWarningsUnsupportedTypesInViews extends IntrospectionWarning { code: 21 affected: AffectedViewAndFieldAndType[] @@ -351,6 +354,12 @@ export namespace EngineArgs { affected: AffectedViewAndField[] } + // Partioned Tables + interface IntrospectionWarningsPartionedTablesFound extends IntrospectionWarning { + code: 27 + affected: AffectedModel[] + } + // MongoDB starts at 101 see // https://github.com/prisma/prisma-engines/blob/main/introspection-engine/connectors/mongodb-introspection-connector/src/warnings.rs#L39-L43 interface IntrospectionWarningsMongoMultipleTypes extends IntrospectionWarning {