Skip to content

Commit

Permalink
feat(sql): alter string length, fix postgres stats (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hieuzest authored Dec 17, 2023
1 parent b1c21d8 commit 94c401e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
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

0 comments on commit 94c401e

Please sign in to comment.