From b8c313993363657847f4226d9100c2f54da87b1b Mon Sep 17 00:00:00 2001 From: Mert E Date: Thu, 11 Jul 2024 15:06:34 +0300 Subject: [PATCH] fix: missing pk for user junction table (#8973) --- .../src/meta/migrations/XcMigrationSourcev2.ts | 4 ++++ .../src/meta/migrations/v2/nc_055_junction_pk.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 packages/nocodb/src/meta/migrations/v2/nc_055_junction_pk.ts diff --git a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts index 8606cda5c0..101ce71591 100644 --- a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts +++ b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts @@ -41,6 +41,7 @@ import * as nc_051_source_readonly_columns from '~/meta/migrations/v2/nc_051_sou import * as nc_052_field_aggregation from '~/meta/migrations/v2/nc_052_field_aggregation'; import * as nc_053_jobs from '~/meta/migrations/v2/nc_053_jobs'; import * as nc_054_id_length from '~/meta/migrations/v2/nc_054_id_length'; +import * as nc_055_junction_pk from '~/meta/migrations/v2/nc_055_junction_pk'; // Create a custom migration source class export default class XcMigrationSourcev2 { @@ -93,6 +94,7 @@ export default class XcMigrationSourcev2 { 'nc_052_field_aggregation', 'nc_053_jobs', 'nc_054_id_length', + 'nc_055_junction_pk', ]); } @@ -188,6 +190,8 @@ export default class XcMigrationSourcev2 { return nc_053_jobs; case 'nc_054_id_length': return nc_054_id_length; + case 'nc_055_junction_pk': + return nc_055_junction_pk; } } } diff --git a/packages/nocodb/src/meta/migrations/v2/nc_055_junction_pk.ts b/packages/nocodb/src/meta/migrations/v2/nc_055_junction_pk.ts new file mode 100644 index 0000000000..edb870b442 --- /dev/null +++ b/packages/nocodb/src/meta/migrations/v2/nc_055_junction_pk.ts @@ -0,0 +1,16 @@ +import type { Knex } from 'knex'; +import { MetaTable } from '~/utils/globals'; + +const up = async (knex: Knex) => { + await knex.schema.alterTable(MetaTable.PROJECT_USERS, (table) => { + table.primary(['base_id', 'fk_user_id']); + }); +}; + +const down = async (knex: Knex) => { + await knex.schema.alterTable(MetaTable.PROJECT_USERS, (table) => { + table.dropPrimary(); + }); +}; + +export { up, down };