web-service/apps/catalog/src/database/migrations/20230722090425_content.ts

44 lines
1.3 KiB
TypeScript

import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.createTable('content', (table) => {
table.increments('id').primary();
table.string('name', 255).notNullable().index();
table.text('description').notNullable();
table.uuid('user_id').nullable();
table.integer('parent_id').unsigned().nullable();
table.boolean('restricted').defaultTo(false);
table.boolean('onsale').defaultTo(false).index();
table.boolean('published').defaultTo(false);
table.boolean('comments_enabled').defaultTo(true);
table.boolean('open_source').defaultTo(false);
table.boolean('tradeable').defaultTo(false);
table.boolean('marketable').defaultTo(false);
table
.enum('privacy', ['public', 'friends', 'unlisted', 'private'])
.notNullable()
.defaultTo('public');
table.string('type').notNullable().index().defaultTo('content');
table.integer('stock').unsigned().nullable();
table.text('license').nullable();
table.uuid('created_by').nullable();
table.uuid('updated_by').nullable();
table.timestamps(true, true);
table.timestamp('deleted_at');
table.foreign('parent_id').references('content.id').onDelete('CASCADE');
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.dropTable('content');
}