knex migration
// best tutorial knex migration
https://www.youtube.com/watch?v=ipAH7lMfq7k
https://www.youtube.com/watch?v=U7GjS3FuSkA
knex migration
// best tutorial knex migration
https://www.youtube.com/watch?v=ipAH7lMfq7k
https://www.youtube.com/watch?v=U7GjS3FuSkA
knex datatypes
table.increments('id')
table.string('account_name')
table.integer('age')
table.float('age')
table.decimal('balance', 8, 2)
table.boolean('is_admin')
table.date('birthday')
table.time('created_at')
table.timestamp('created_at').defaultTo(knex.fn.now())
table.json('profile')
table.jsonb('profile')
table.uuid('id').primary()
knex js join schema
exports.up = (knex) => {
knex.schema.createTable('bookings', (table) => {
table.increment('booking_id').primary()
table.foreign('user_id').references('user_id').inTable('users').notNullable().onDelete('CASCADE').index()
table.foreign('room_id').references('room_id').inTable('rooms').notNullable().onDelete('CASCADE').index()
table.integer('total_person').notNullable().defaultTo(0)
table.datetime('booking_time').notNullable().defaultTo(knex.fn.now())
table.string('noted').notNullable()
table.datetime('check_in_time').defaultTo(knex.fn.now())
table.datetime('check_out_time').defaultTo(knex.fn.now())
table.timestamp('created_at').defaultTo(knex.fn.now())
table.timestamp('update_at').defaultTo(knex.fn.now())
table.timestamp('delete_at').defaultTo(knex.fn.now())
})
}
exports.down = (knex) => knex.schema.dropTable('bookings')
knexjs execute all migrations
$ knex migrate:make create_users_table
$ knex migrate:make create_tasks_table
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us