import { BaseSchema } from '@adonisjs/lucid/schema' export default class extends BaseSchema { protected tableName = 'custom_fields' async up() { this.schema.createTable(this.tableName, (table) => { table.increments('id').notNullable() table .integer('tenant_id') .unsigned() .notNullable() .references('id') .inTable('tenants') .onDelete('CASCADE') table.string('entity_type').notNullable() table.string('name').notNullable() table.string('key').notNullable() table.string('field_type').notNullable() table.boolean('required').notNullable().defaultTo(false) table.jsonb('options').nullable() table.string('status').notNullable().defaultTo('active') table.timestamp('created_at').notNullable().defaultTo(this.now()) table.timestamp('updated_at').notNullable().defaultTo(this.now()) table.unique(['tenant_id', 'entity_type', 'key']) table.index(['tenant_id', 'entity_type']) }) } async down() { this.schema.dropTable(this.tableName) } }