UNPKG

@tanglemedia/directus-collection-flex-editor

Version:

Creates the flex table and some basic related nodes like image, resource, embed, and section

37 lines (29 loc) 1.05 kB
const COLLECTION_NAME = "tngl_flex_content"; export async function up(knex) { // if table exists, create non existing fields if (await knex.schema.hasTable(COLLECTION_NAME)) { // create non existing `id` field const idExists = await knex.schema.hasColumn(COLLECTION_NAME, "id"); if (!idExists) table.uuid("id").primary().notNullable(); // create non existing `content` field const contentExists = await knex.schema.hasColumn( COLLECTION_NAME, "content" ); if (!contentExists) table.json("content").nullable(); // create non existing `plain` field const plainExists = await knex.schema.hasColumn(COLLECTION_NAME, "plain"); if (!plainExists) table.text("plain").nullable(); return; } // if table does not exist, create table await knex.schema.createTable(COLLECTION_NAME, (table) => { table.uuid("id").primary().notNullable(); table.json("content").nullable(); table.text("plain").nullable(); }); } export async function down(knex) { // drop table await knex.schema.dropTableIfExists(COLLECTION_NAME); }