Fix string to text migrations for Oracle (#5462)

* Disabled string to text migrations for Oracle

* Added oracle specific alter table migrations

* Added notNull parameter to Oracle alter function

* Wrapped notNull in if

* Removed public oracle column alter function
This commit is contained in:
Aiden Foxx
2021-05-14 18:30:17 +02:00
committed by GitHub
parent 7a4871dbdb
commit e8e295ef6a
2 changed files with 38 additions and 0 deletions

View File

@@ -1,12 +1,31 @@
import { Knex } from 'knex';
import env from '../../env';
async function oracleAlterUrl(knex: Knex, type: string): Promise<void> {
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<void> {
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<void> {
if (env.DB_CLIENT === 'oracledb') {
await oracleAlterUrl(knex, 'VARCHAR2(255)');
return;
}
await knex.schema.alterTable('directus_webhooks', (table) => {
table.string('url').alter();
});

View File

@@ -1,12 +1,31 @@
import { Knex } from 'knex';
import env from '../../env';
async function oracleAlterCollections(knex: Knex, type: string): Promise<void> {
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<void> {
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<void> {
if (env.DB_CLIENT === 'oracledb') {
await oracleAlterCollections(knex, 'VARCHAR2(255)');
return;
}
await knex.schema.alterTable('directus_webhooks', (table) => {
table.string('collections').alter();
});