@tanglemedia/directus-collection-resource
Version:
Installs the Resource Collection to your Directus project.
55 lines (45 loc) • 1.54 kB
JavaScript
const COLLECTION_NAME = "tngl_resource";
export async function up(knex) {
// if table exists, do not proceed with migration
if (await knex.schema.hasTable(COLLECTION_NAME)) {
return;
}
// create table
await knex.schema.createTable(COLLECTION_NAME, (table) => {
table.increments("id").unsigned().notNullable();
// default fields
table.integer("sort").nullable();
table.string("status", 255).notNullable().defaultTo("draft");
// accountability fields
table.specificType("user_created", "char(36)").nullable();
table.specificType("user_updated", "char(36)").nullable();
table.timestamp("date_created").nullable();
table.timestamp("date_updated").nullable();
// seo fields
table.json("keywords").nullable();
table.text("description").nullable();
// custom fields
table.string("title", 255).notNullable();
table.string("slug", 255).notNullable().unique();
table.specificType("cover_thumbnail", "char(36)").nullable();
table.specificType("file", "char(36)").nullable();
table.primary(["id"]);
// relationships
table.foreign("user_created").references("id").inTable("directus_users");
table.foreign("user_updated").references("id").inTable("directus_users");
table
.foreign("cover_thumbnail")
.references("id")
.inTable("directus_files")
.onDelete("SET NULL");
table
.foreign("file")
.references("id")
.inTable("directus_files")
.onDelete("SET NULL");
});
}
export async function down(knex) {
// drop table
await knex.schema.dropTableIfExists(COLLECTION_NAME);
}