Skip to content

Commit

Permalink
Added code 27 :: partitioned found (#18386)
Browse files Browse the repository at this point in the history
Added tests for singular & multiple partitioned tables
  • Loading branch information
Druue committed Mar 21, 2023
1 parent 456bab4 commit 7893f1a
Show file tree
Hide file tree
Showing 7 changed files with 473 additions and 244 deletions.
650 changes: 406 additions & 244 deletions packages/migrate/src/__tests__/DbPull.test.ts

Large diffs are not rendered by default.

@@ -0,0 +1,8 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgres"
url = env("TEST_POSTGRES_URI_MIGRATE")
}
@@ -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');
@@ -0,0 +1,8 @@
generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgres"
url = env("TEST_POSTGRES_URI_MIGRATE")
}
@@ -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');
2 changes: 2 additions & 0 deletions packages/migrate/src/commands/DbPull.ts
Expand Up @@ -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) => {
Expand Down
9 changes: 9 additions & 0 deletions packages/migrate/src/types.ts
Expand Up @@ -188,6 +188,8 @@ export namespace EngineArgs {
| IntrospectionWarningsViewsWithoutIdentifier
| IntrospectionWarningsEnrichedWithCustomPrimaryKeyNamesInViews
| IntrospectionWarningsFieldsWithEmptyNamesInViews
// Partioned Tables
| IntrospectionWarningsPartionedTablesFound
// MongoDB below
| IntrospectionWarningsMongoMultipleTypes
| IntrospectionWarningsMongoFieldsPointingToAnEmptyType
Expand Down Expand Up @@ -321,6 +323,7 @@ export namespace EngineArgs {
affected: AffectedTopLevel[]
}

// Views
interface IntrospectionWarningsUnsupportedTypesInViews extends IntrospectionWarning {
code: 21
affected: AffectedViewAndFieldAndType[]
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7893f1a

Please sign in to comment.