diff --git a/api/src/database/migrations/20201105B-change-webhook-url-type.ts b/api/src/database/migrations/20201105B-change-webhook-url-type.ts index cc274907ae..d1ad118cc5 100644 --- a/api/src/database/migrations/20201105B-change-webhook-url-type.ts +++ b/api/src/database/migrations/20201105B-change-webhook-url-type.ts @@ -1,12 +1,31 @@ import { Knex } from 'knex'; +import env from '../../env'; + +async function oracleAlterUrl(knex: Knex, type: string): Promise { + await knex.raw('ALTER TABLE "directus_webhooks" ADD "url__temp" ?', [knex.raw(type)]); + await knex.raw('UPDATE "directus_webhooks" SET "url__temp"="url"'); + await knex.raw('ALTER TABLE "directus_webhooks" DROP COLUMN "url"'); + await knex.raw('ALTER TABLE "directus_webhooks" RENAME COLUMN "url__temp" TO "url"'); + await knex.raw('ALTER TABLE "directus_webhooks" MODIFY "url" NOT NULL'); +} export async function up(knex: Knex): Promise { + if (env.DB_CLIENT === 'oracledb') { + await oracleAlterUrl(knex, 'CLOB'); + return; + } + await knex.schema.alterTable('directus_webhooks', (table) => { table.text('url').alter(); }); } export async function down(knex: Knex): Promise { + if (env.DB_CLIENT === 'oracledb') { + await oracleAlterUrl(knex, 'VARCHAR2(255)'); + return; + } + await knex.schema.alterTable('directus_webhooks', (table) => { table.string('url').alter(); }); diff --git a/api/src/database/migrations/20210312A-webhooks-collections-text.ts b/api/src/database/migrations/20210312A-webhooks-collections-text.ts index 43b31ab628..09cd50b5c1 100644 --- a/api/src/database/migrations/20210312A-webhooks-collections-text.ts +++ b/api/src/database/migrations/20210312A-webhooks-collections-text.ts @@ -1,12 +1,31 @@ import { Knex } from 'knex'; +import env from '../../env'; + +async function oracleAlterCollections(knex: Knex, type: string): Promise { + await knex.raw('ALTER TABLE "directus_webhooks" ADD "collections__temp" ?', [knex.raw(type)]); + await knex.raw('UPDATE "directus_webhooks" SET "collections__temp"="collections"'); + await knex.raw('ALTER TABLE "directus_webhooks" DROP COLUMN "collections"'); + await knex.raw('ALTER TABLE "directus_webhooks" RENAME COLUMN "collections__temp" TO "collections"'); + await knex.raw('ALTER TABLE "directus_webhooks" MODIFY "collections" NOT NULL'); +} export async function up(knex: Knex): Promise { + if (env.DB_CLIENT === 'oracledb') { + await oracleAlterCollections(knex, 'CLOB'); + return; + } + await knex.schema.alterTable('directus_webhooks', (table) => { table.text('collections').alter(); }); } export async function down(knex: Knex): Promise { + if (env.DB_CLIENT === 'oracledb') { + await oracleAlterCollections(knex, 'VARCHAR2(255)'); + return; + } + await knex.schema.alterTable('directus_webhooks', (table) => { table.string('collections').alter(); });