-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Use consistent timezone-aware timestamps in postgres
- Loading branch information
Showing
3 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...cli/src/databases/migrations/postgresdb/1692207852593-MigrateToTimestampZ1692207852593.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import type { IrreversibleMigration, MigrationContext } from '@/databases/types'; | ||
|
||
const defaultTimestampColumns = ['createdAt', 'updatedAt']; | ||
const tablesWithDefaultTimestamps = [ | ||
'auth_identity', | ||
'credentials_entity', | ||
'event_destinations', | ||
'installed_packages', | ||
'role', | ||
'shared_credentials', | ||
'shared_workflow', | ||
'tag_entity', | ||
'user', | ||
'workflow_entity', | ||
]; | ||
|
||
const additionalColumns = { | ||
auth_provider_sync_history: ['endedAt', 'startedAt'], | ||
execution_entity: ['startedAt', 'stoppedAt', 'waitTill'], | ||
workflow_statistics: ['latestEvent'], | ||
}; | ||
|
||
export class MigrateToTimestampZ1692207852593 implements IrreversibleMigration { | ||
async up({ queryRunner, tablePrefix }: MigrationContext) { | ||
const changeColumnType = async (tableName: string, columnName: string) => | ||
queryRunner.query( | ||
`ALTER TABLE "${tablePrefix}${tableName}" ALTER COLUMN "${columnName}" TYPE TIMESTAMPTZ(3)`, | ||
); | ||
|
||
for (const tableName of tablesWithDefaultTimestamps) { | ||
for (const columnName of defaultTimestampColumns) { | ||
await changeColumnType(tableName, columnName); | ||
} | ||
} | ||
for (const [tableName, columnNames] of Object.entries(additionalColumns)) { | ||
for (const columnName of columnNames) { | ||
await changeColumnType(tableName, columnName); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters