Skip to content

Commit

Permalink
fix(core): Change dedupe value column type from varchar(255) to text (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ShireenMissi authored and r00gm committed Oct 24, 2024
1 parent 0ac1b18 commit 6b272b0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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');
}
}
}
4 changes: 4 additions & 0 deletions packages/cli/src/databases/migrations/mysqldb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { CreateAnnotationTables1724753530828 } from '../common/1724753530828-Cre
import { AddApiKeysTable1724951148974 } from '../common/1724951148974-AddApiKeysTable';
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,
Expand Down Expand Up @@ -134,4 +136,6 @@ export const mysqlMigrations: Migration[] = [
AddApiKeysTable1724951148974,
SeparateExecutionCreationFromStart1727427440136,
CreateProcessedDataTable1726606152711,
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
];
4 changes: 4 additions & 0 deletions packages/cli/src/databases/migrations/postgresdb/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { CreateAnnotationTables1724753530828 } from '../common/1724753530828-Cre
import { AddApiKeysTable1724951148974 } from '../common/1724951148974-AddApiKeysTable';
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,
Expand Down Expand Up @@ -134,4 +136,6 @@ export const postgresMigrations: Migration[] = [
AddApiKeysTable1724951148974,
SeparateExecutionCreationFromStart1727427440136,
CreateProcessedDataTable1726606152711,
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
];
3 changes: 3 additions & 0 deletions packages/cli/src/databases/migrations/sqlite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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,
Expand Down Expand Up @@ -128,6 +129,8 @@ const sqliteMigrations: Migration[] = [
AddApiKeysTable1724951148974,
SeparateExecutionCreationFromStart1727427440136,
CreateProcessedDataTable1726606152711,
AddMissingPrimaryKeyOnAnnotationTagMapping1728659839644,
UpdateProcessedDataValueColumnToText1729607673464,
];

export { sqliteMigrations };

0 comments on commit 6b272b0

Please sign in to comment.