pgSuggestions() — drizzle-orm Function Reference
Architecture documentation for the pgSuggestions() function in pgPushUtils.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 87f7b1b3_7d8d_e578_65e8_0a5068faa9da["pgSuggestions()"] 293050d4_dc5a_8857_bc4c_a61fb70eb6cf["pgPushUtils.ts"] 87f7b1b3_7d8d_e578_65e8_0a5068faa9da -->|defined in| 293050d4_dc5a_8857_bc4c_a61fb70eb6cf 52c3c13e_4679_a62f_6db0_92c8626d2645["pushSchema()"] 52c3c13e_4679_a62f_6db0_92c8626d2645 -->|calls| 87f7b1b3_7d8d_e578_65e8_0a5068faa9da f9b9f77e_3056_bcf4_5233_f690b56a8d53["pgPush()"] f9b9f77e_3056_bcf4_5233_f690b56a8d53 -->|calls| 87f7b1b3_7d8d_e578_65e8_0a5068faa9da 6c15155a_f692_1f6c_649c_e170101c51bc["concatSchemaAndTableName()"] 87f7b1b3_7d8d_e578_65e8_0a5068faa9da -->|calls| 6c15155a_f692_1f6c_649c_e170101c51bc 0addd835_a514_0456_9add_0ef6e8ab3a56["tableNameWithSchemaFrom()"] 87f7b1b3_7d8d_e578_65e8_0a5068faa9da -->|calls| 0addd835_a514_0456_9add_0ef6e8ab3a56 3777ab94_5115_f1de_1718_0bb9c292bf84["render()"] 87f7b1b3_7d8d_e578_65e8_0a5068faa9da -->|calls| 3777ab94_5115_f1de_1718_0bb9c292bf84 1773b8e8_0312_51ff_3ec6_a3b93ef193bf["fromJson()"] 87f7b1b3_7d8d_e578_65e8_0a5068faa9da -->|calls| 1773b8e8_0312_51ff_3ec6_a3b93ef193bf style 87f7b1b3_7d8d_e578_65e8_0a5068faa9da fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-kit/src/cli/commands/pgPushUtils.ts lines 59–269
export const pgSuggestions = async (db: DB, statements: JsonStatement[]) => {
let shouldAskForApprove = false;
const statementsToExecute: string[] = [];
const infoToPrint: string[] = [];
const tablesToRemove: string[] = [];
const columnsToRemove: string[] = [];
const schemasToRemove: string[] = [];
const tablesToTruncate: string[] = [];
const matViewsToRemove: string[] = [];
let renamedSchemas: Record<string, string> = {};
let renamedTables: Record<string, string> = {};
for (const statement of statements) {
if (statement.type === 'rename_schema') {
renamedSchemas[statement.to] = statement.from;
} else if (statement.type === 'rename_table') {
renamedTables[concatSchemaAndTableName(statement.toSchema, statement.tableNameTo)] = statement.tableNameFrom;
} else if (statement.type === 'drop_table') {
const res = await db.query(
`select count(*) as count from ${
tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)
}`,
);
const count = Number(res[0].count);
if (count > 0) {
infoToPrint.push(`· You're about to delete ${chalk.underline(statement.tableName)} table with ${count} items`);
// statementsToExecute.push(
// `truncate table ${tableNameWithSchemaFrom(statement)} cascade;`
// );
tablesToRemove.push(statement.tableName);
shouldAskForApprove = true;
}
} else if (statement.type === 'drop_view' && statement.materialized) {
const res = await db.query(`select count(*) as count from "${statement.schema ?? 'public'}"."${statement.name}"`);
const count = Number(res[0].count);
if (count > 0) {
infoToPrint.push(
`· You're about to delete "${chalk.underline(statement.name)}" materialized view with ${count} items`,
);
matViewsToRemove.push(statement.name);
shouldAskForApprove = true;
}
} else if (statement.type === 'alter_table_drop_column') {
const res = await db.query(
`select count(*) as count from ${
tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)
}`,
);
const count = Number(res[0].count);
if (count > 0) {
infoToPrint.push(
`· You're about to delete ${
chalk.underline(statement.columnName)
} column in ${statement.tableName} table with ${count} items`,
);
columnsToRemove.push(`${statement.tableName}_${statement.columnName}`);
shouldAskForApprove = true;
}
} else if (statement.type === 'drop_schema') {
const res = await db.query(
`select count(*) as count from information_schema.tables where table_schema = '${statement.name}';`,
);
const count = Number(res[0].count);
if (count > 0) {
infoToPrint.push(`· You're about to delete ${chalk.underline(statement.name)} schema with ${count} tables`);
schemasToRemove.push(statement.name);
shouldAskForApprove = true;
}
} else if (statement.type === 'alter_table_alter_column_set_type') {
const res = await db.query(
`select count(*) as count from ${
tableNameWithSchemaFrom(statement.schema, statement.tableName, renamedSchemas, renamedTables)
}`,
);
const count = Number(res[0].count);
if (count > 0) {
infoToPrint.push(
`· You're about to change ${chalk.underline(statement.columnName)} column type from ${
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does pgSuggestions() do?
pgSuggestions() is a function in the drizzle-orm codebase, defined in drizzle-kit/src/cli/commands/pgPushUtils.ts.
Where is pgSuggestions() defined?
pgSuggestions() is defined in drizzle-kit/src/cli/commands/pgPushUtils.ts at line 59.
What does pgSuggestions() call?
pgSuggestions() calls 4 function(s): concatSchemaAndTableName, fromJson, render, tableNameWithSchemaFrom.
What calls pgSuggestions()?
pgSuggestions() is called by 2 function(s): pgPush, pushSchema.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free