diff --git a/packages/cli/src/databases/migrations/common/1729607673464-UpdateProcessedDataValueColumnToText.ts b/packages/cli/src/databases/migrations/common/1729607673464-UpdateProcessedDataValueColumnToText.ts new file mode 100644 index 0000000000..074b710fa1 --- /dev/null +++ b/packages/cli/src/databases/migrations/common/1729607673464-UpdateProcessedDataValueColumnToText.ts @@ -0,0 +1,34 @@ +import type { MigrationContext, ReversibleMigration } from '@/databases/types'; + +const processedDataTableName = 'processed_data'; +export class UpdateProcessedDataValueColumnToText1729607673464 implements ReversibleMigration { + async up({ schemaBuilder: { addNotNull }, isMysql, runQuery, tablePrefix }: MigrationContext) { + const prefixedTableName = `${tablePrefix}${processedDataTableName}`; + await runQuery(`ALTER TABLE ${prefixedTableName} ADD COLUMN value_temp TEXT;`); + await runQuery(`UPDATE ${prefixedTableName} SET value_temp = value;`); + await runQuery(`ALTER TABLE ${prefixedTableName} DROP COLUMN value;`); + + if (isMysql) { + await runQuery(`ALTER TABLE ${prefixedTableName} CHANGE value_temp value TEXT NOT NULL;`); + } else { + await runQuery(`ALTER TABLE ${prefixedTableName} RENAME COLUMN value_temp TO value`); + await addNotNull(processedDataTableName, 'value'); + } + } + + async down({ schemaBuilder: { addNotNull }, isMysql, runQuery, tablePrefix }: MigrationContext) { + const prefixedTableName = `${tablePrefix}${processedDataTableName}`; + await runQuery(`ALTER TABLE ${prefixedTableName} ADD COLUMN value_temp VARCHAR(255);`); + await runQuery(`UPDATE ${prefixedTableName} SET value_temp = value;`); + await runQuery(`ALTER TABLE ${prefixedTableName} DROP COLUMN value;`); + + if (isMysql) { + await runQuery( + `ALTER TABLE ${prefixedTableName} CHANGE value_temp value VARCHAR(255) NOT NULL;`, + ); + } else { + await runQuery(`ALTER TABLE ${prefixedTableName} RENAME COLUMN value_temp TO value`); + await addNotNull(processedDataTableName, 'value'); + } + } +} diff --git a/packages/cli/src/databases/migrations/mysqldb/index.ts b/packages/cli/src/databases/migrations/mysqldb/index.ts index d117a6c472..ff40fd9dc0 100644 --- a/packages/cli/src/databases/migrations/mysqldb/index.ts +++ b/packages/cli/src/databases/migrations/mysqldb/index.ts @@ -67,6 +67,7 @@ import { AddApiKeysTable1724951148974 } from '../common/1724951148974-AddApiKeys import { CreateProcessedDataTable1726606152711 } from '../common/1726606152711-CreateProcessedDataTable'; import { SeparateExecutionCreationFromStart1727427440136 } from '../common/1727427440136-SeparateExecutionCreationFromStart'; import { AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644 } from '../common/1728659839644-AddMissingPrimaryKeyOnAnnotationTagMapping'; +import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText'; export const mysqlMigrations: Migration[] = [ InitialMigration1588157391238, @@ -136,4 +137,5 @@ export const mysqlMigrations: Migration[] = [ SeparateExecutionCreationFromStart1727427440136, CreateProcessedDataTable1726606152711, AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644, + UpdateProcessedDataValueColumnToText1729607673464, ]; diff --git a/packages/cli/src/databases/migrations/postgresdb/index.ts b/packages/cli/src/databases/migrations/postgresdb/index.ts index b55ce32750..f3ac7e0474 100644 --- a/packages/cli/src/databases/migrations/postgresdb/index.ts +++ b/packages/cli/src/databases/migrations/postgresdb/index.ts @@ -67,6 +67,7 @@ import { AddApiKeysTable1724951148974 } from '../common/1724951148974-AddApiKeys import { CreateProcessedDataTable1726606152711 } from '../common/1726606152711-CreateProcessedDataTable'; import { SeparateExecutionCreationFromStart1727427440136 } from '../common/1727427440136-SeparateExecutionCreationFromStart'; import { AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644 } from '../common/1728659839644-AddMissingPrimaryKeyOnAnnotationTagMapping'; +import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText'; export const postgresMigrations: Migration[] = [ InitialMigration1587669153312, @@ -136,4 +137,5 @@ export const postgresMigrations: Migration[] = [ SeparateExecutionCreationFromStart1727427440136, CreateProcessedDataTable1726606152711, AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644, + UpdateProcessedDataValueColumnToText1729607673464, ]; diff --git a/packages/cli/src/databases/migrations/sqlite/index.ts b/packages/cli/src/databases/migrations/sqlite/index.ts index c2c75cbb84..e53b5f43bd 100644 --- a/packages/cli/src/databases/migrations/sqlite/index.ts +++ b/packages/cli/src/databases/migrations/sqlite/index.ts @@ -64,6 +64,7 @@ import { RefactorExecutionIndices1723796243146 } from '../common/1723796243146-R import { CreateAnnotationTables1724753530828 } from '../common/1724753530828-CreateExecutionAnnotationTables'; import { CreateProcessedDataTable1726606152711 } from '../common/1726606152711-CreateProcessedDataTable'; import { SeparateExecutionCreationFromStart1727427440136 } from '../common/1727427440136-SeparateExecutionCreationFromStart'; +import { UpdateProcessedDataValueColumnToText1729607673464 } from '../common/1729607673464-UpdateProcessedDataValueColumnToText'; const sqliteMigrations: Migration[] = [ InitialMigration1588102412422, @@ -130,6 +131,7 @@ const sqliteMigrations: Migration[] = [ SeparateExecutionCreationFromStart1727427440136, CreateProcessedDataTable1726606152711, AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644, + UpdateProcessedDataValueColumnToText1729607673464, ]; export { sqliteMigrations };