-
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
10 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
44 changes: 44 additions & 0 deletions
44
packages/cli/src/databases/migrations/postgresdb/1694091729095-MigrateToTimestampTz.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,44 @@ | ||
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 MigrateToTimestampTz1694091729095 implements IrreversibleMigration { | ||
async up({ queryRunner, tablePrefix }: MigrationContext) { | ||
const changeColumnType = async (tableName: string, columnName: string, setDefault: boolean) => { | ||
const alterColumnQuery = `ALTER TABLE "${tablePrefix}${tableName}" ALTER COLUMN "${columnName}"`; | ||
await queryRunner.query(`${alterColumnQuery} TYPE TIMESTAMP(3) WITH TIME ZONE`); | ||
if (setDefault) | ||
await queryRunner.query(`${alterColumnQuery} SET DEFAULT CURRENT_TIMESTAMP(3)`); | ||
}; | ||
|
||
for (const tableName of tablesWithDefaultTimestamps) { | ||
for (const columnName of defaultTimestampColumns) { | ||
await changeColumnType(tableName, columnName, true); | ||
} | ||
} | ||
|
||
for (const [tableName, columnNames] of Object.entries(additionalColumns)) { | ||
for (const columnName of columnNames) { | ||
await changeColumnType(tableName, columnName, false); | ||
} | ||
} | ||
} | ||
} |
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