1// best tutorial knex migration
2https://www.youtube.com/watch?v=ipAH7lMfq7k
3https://www.youtube.com/watch?v=U7GjS3FuSkA
1 table.increments('id')
2 table.string('account_name')
3 table.integer('age')
4 table.float('age')
5 table.decimal('balance', 8, 2)
6 table.boolean('is_admin')
7 table.date('birthday')
8 table.time('created_at')
9 table.timestamp('created_at').defaultTo(knex.fn.now())
10 table.json('profile')
11 table.jsonb('profile')
12 table.uuid('id').primary()
13
1exports.up = (knex) => {
2 knex.schema.createTable('bookings', (table) => {
3 table.increment('booking_id').primary()
4 table.foreign('user_id').references('user_id').inTable('users').notNullable().onDelete('CASCADE').index()
5 table.foreign('room_id').references('room_id').inTable('rooms').notNullable().onDelete('CASCADE').index()
6 table.integer('total_person').notNullable().defaultTo(0)
7 table.datetime('booking_time').notNullable().defaultTo(knex.fn.now())
8 table.string('noted').notNullable()
9 table.datetime('check_in_time').defaultTo(knex.fn.now())
10 table.datetime('check_out_time').defaultTo(knex.fn.now())
11 table.timestamp('created_at').defaultTo(knex.fn.now())
12 table.timestamp('update_at').defaultTo(knex.fn.now())
13 table.timestamp('delete_at').defaultTo(knex.fn.now())
14 })
15}
16
17exports.down = (knex) => knex.schema.dropTable('bookings')