Lambda-School-Labs/Studium-BE

View on GitHub
db/migrations/20200527234641_create-decks-table.js

Summary

Maintainability
A
0 mins
Test Coverage

exports.up = function (knex) {
    knex.raw('CREATE EXTENSION IF NOT EXISTS "uuid-ossp"')
        .then(() => {
            return knex.schema.createTable('decks', tbl => {
                tbl.uuid('id').defaultTo(knex.raw('uuid_generate_v4()')).notNullable().primary(); // ID
                tbl.uuid('user_id') // USER ID FROM USERS TABLE 
                    .unsigned()
                    .notNullable()
                    .references('id')
                    .inTable('users')
                tbl.string('deck_name') // DECK NAME
                    .notNullable();
                tbl.string('category') // OPTIONAL CATEGORY 
                tbl.string('description') // OPTIONAL DESCRIPTION
                tbl.boolean('public') // PUBLIC OR NOT BOOLEAN 
                    .defaultTo(false)
                tbl.string('deck_img') // OPTIONAL DECK IMAGE 
                tbl.bigint('created_at') // CREATED AT TIMESTAMP 
                tbl.bigint('updated_at') // UPDATED AT TIMESTAMP 
            })
        })
};

exports.down = function (knex) {
    knex.raw('drop extension if exists "uuid-ossp"');
    return knex.schema.dropTableIfExists('decks');
};