Skip to content

Commit 9e74e8c

Browse files
Merge branch 'alternation-engine' of https://github.com/drizzle-team/drizzle-orm into alternation-engine
2 parents 20e68ad + 3fa9194 commit 9e74e8c

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

drizzle-kit/src/cli/commands/push-postgres.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { ddlDiff } from '../../dialects/postgres/diff';
2121
import { fromDrizzleSchema, prepareFromSchemaFiles } from '../../dialects/postgres/drizzle';
2222
import type { JsonStatement } from '../../dialects/postgres/statements';
2323
import type { DB } from '../../utils';
24-
import { mockResolver } from '../../utils/mocks';
2524
import { prepareFilenames } from '../../utils/utils-node';
2625
import { resolver } from '../prompts';
2726
import { Select } from '../selector-ui';
@@ -37,18 +36,36 @@ export const handle = async (
3736
strict: boolean,
3837
credentials: PostgresCredentials,
3938
tablesFilter: string[],
40-
schemasFilter: string[],
39+
allowedSchemas: string[],
4140
entities: Entities,
4241
force: boolean,
4342
casing: CasingType | undefined,
4443
) => {
4544
const { preparePostgresDB } = await import('../connections');
46-
const { introspect: pgPushIntrospect } = await import('./pull-postgres');
45+
const { introspect } = await import('./pull-postgres');
4746

4847
const db = await preparePostgresDB(credentials);
4948
const filenames = prepareFilenames(schemaPath);
5049
const res = await prepareFromSchemaFiles(filenames);
5150

51+
console.log(allowedSchemas);
52+
if (allowedSchemas.length > 0) {
53+
const toCheck = res.schemas.map((it) => it.schemaName).filter((it) => it !== 'public');
54+
const missing = toCheck.filter((it) => !allowedSchemas.includes(it));
55+
if (missing.length > 0) {
56+
const missingArr = missing.map((it) => chalk.underline(it)).join(', ');
57+
const allowedArr = allowedSchemas.map((it) => chalk.underline(it)).join(', ');
58+
render(
59+
`[${chalk.red('x')}] ${missingArr} schemas missing in drizzle config file "schemaFilter": [${allowedArr}]`,
60+
);
61+
// TODO: write a guide and link here
62+
process.exit(1);
63+
}
64+
} else {
65+
allowedSchemas.push(...res.schemas.map((it) => it.schemaName));
66+
}
67+
console.log('.', allowedSchemas);
68+
5269
const { schema: schemaTo, errors, warnings } = fromDrizzleSchema(res, casing);
5370

5471
if (warnings.length > 0) {
@@ -61,11 +78,11 @@ export const handle = async (
6178
}
6279

6380
const progress = new ProgressView('Pulling schema from database...', 'Pulling schema from database...');
64-
const { schema: schemaFrom } = await pgPushIntrospect(db, tablesFilter, schemasFilter, entities, progress);
81+
const { schema: schemaFrom } = await introspect(db, tablesFilter, allowedSchemas, entities, progress);
6582

6683
const { ddl: ddl1, errors: errors1 } = interimToDDL(schemaFrom);
6784
const { ddl: ddl2, errors: errors2 } = interimToDDL(schemaTo);
68-
// todo: handle errors?
85+
// TODO: handle errors?
6986

7087
if (errors1.length > 0) {
7188
console.log(errors.map((it) => postgresSchemaError(it)).join('\n'));

drizzle-kit/src/dialects/postgres/drizzle.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,13 @@ export const fromDrizzleSchema = (
268268
};
269269

270270
res.schemas = schema.schemas
271+
.filter((it) => {
272+
return !it.isExisting && it.schemaName !== 'public';
273+
})
271274
.map<Schema>((it) => ({
272275
entityType: 'schemas',
273276
name: it.schemaName,
274-
}))
275-
.filter((it) => {
276-
if (schemaFilter) {
277-
return schemaFilter.includes(it.name) && it.name !== 'public';
278-
} else {
279-
return it.name !== 'public';
280-
}
281-
});
277+
}));
282278

283279
const tableConfigPairs = schema.tables.map((it) => {
284280
return { config: getTableConfig(it), table: it };

0 commit comments

Comments
 (0)