exports.up = function (knex) { return knex.schema .createTable("conversations", (t) => { t.increments("Id"); t.integer("UsuarioId").unsigned().notNullable(); t.string("Title", 255).notNullable().defaultTo("Nova conversa"); t.timestamp("CreatedAt").notNullable().defaultTo(knex.fn.now()); t.timestamp("UpdatedAt").notNullable().defaultTo(knex.fn.now()); t.foreign("UsuarioId").references("usuarios.Id").onDelete("CASCADE"); t.index(["UsuarioId"]); t.index(["UpdatedAt"]); }) .createTable("messages", (t) => { t.increments("Id"); t.integer("ConversationId").unsigned().notNullable(); t.string("Role", 10).notNullable(); t.text("Content").notNullable(); t.json("Sources").nullable(); t.timestamp("SentAt").notNullable().defaultTo(knex.fn.now()); t.foreign("ConversationId").references("conversations.Id").onDelete("CASCADE"); t.index(["ConversationId"]); }); }; exports.down = function (knex) { return knex.schema.dropTable("messages").dropTable("conversations"); };