Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sql): alter string length, fix postgres stats #67

Merged
merged 3 commits into from
Dec 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mysql/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ function isDefUpdated(field: Field, column: ColumnInfo, def: string) {
case 'integer':
case 'unsigned':
case 'char':
case 'string':
return !!field.length && !!column.CHARACTER_MAXIMUM_LENGTH && column.CHARACTER_MAXIMUM_LENGTH !== field.length
case 'decimal':
return column.NUMERIC_PRECISION !== field.precision || column.NUMERIC_SCALE !== field.scale
case 'string':
case 'text':
case 'list':
case 'json':
Expand Down
12 changes: 7 additions & 5 deletions packages/postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ function isDefUpdated(field: Field & { autoInc?: boolean }, column: ColumnInfo,
case 'integer':
case 'unsigned':
case 'char':
case 'string':
return !!field.length && !!column.character_maximum_length && column.character_maximum_length !== field.length
case 'decimal':
return column.numeric_precision !== field.precision || column.numeric_scale !== field.scale
case 'string':
case 'text':
case 'list':
case 'json':
Expand Down Expand Up @@ -596,14 +596,16 @@ export class PostgresDriver extends Driver {
}

async stats(): Promise<Partial<Driver.Stats>> {
const tables = await this.query(`
const names = Object.keys(this.database.tables)
const tables = (await this.query<TableInfo[]>(`
SELECT *
FROM information_schema.tables
WHERE table_schema = 'public'`)
WHERE table_schema = 'public'`))
.map(t => t.table_name).filter(name => names.includes(name))
const tableStats = await this.query(
tables.map(({ table_name: name }) => {
tables.map(name => {
return `SELECT '${name}' AS name,
pg_total_relation_size('${name}') AS size,
pg_total_relation_size('${escapeId(name)}') AS size,
COUNT(*) AS count FROM ${escapeId(name)}`
}).join(' UNION '),
).then(s => s.map(t => [t.name, { size: +t.size, count: +t.count }]))
Expand Down