import { Knex } from "knex"; export const TABLES = { USERS: "users", POSTS: "posts" } export async function up(knex: Knex): Promise { if ( !(await knex.schema.hasTable(TABLES.USERS)) ) { await knex.schema.createTable(TABLES.USERS, (table) => { table.increments(); table.string("username").notNullable(); table.string("email").notNullable(); table.string("password").notNullable(); table.timestamps(false, true); }); } if ( !(await knex.schema.hasTable(TABLES.POSTS)) ) { await knex.schema.createTable(TABLES.POSTS, (table) => { table.increments(); table.integer("user_id"); table.foreign('user_id').references(`${TABLES.USERS}.id`); table.string("content"); table.timestamps(false, true); }); } } export async function down(knex: Knex): Promise { await knex.schema.dropTableIfExists(TABLES.POSTS); await knex.schema.dropTableIfExists(TABLES.USERS); }