exports.up = function(knex) { return knex.schema .createTable('users', function(table) { table.increments('user_id').primary() table.string('user_name', 32).notNullable() table.string('user_email', 90).notNullable() }) .createTable('profiles', function(table) { table.increments('profile_id').primary() table.integer('user_id').notNullable() }) .createTable('response_keys', function(table) { table.increments('response_key_id').primary() table.string('response_key_name').notNullable() table.string('response_key_description') }) .createTable('responses', function(table) { table.increments('response_id').primary() table.integer('profile_id').notNullable() table.integer('response_key_id').notNullable() table.string('val').notNullable() }) .createTable('groupings', function(table) { table.increments('grouping_id').primary() table.string('grouping_name', 128).notNullable() table.string('grouping_type', 128).notNullable() // Don't over normalize }) .createTable('memberships', function(table) { table.increments('membership_id').primary() table.integer('user_id').notNullable() // From table.integer('grouping_id').notNullable() // To table.string('membership_type', 128).notNullable() // Don't over normalize table.boolean('can_edit').notNullable() }) .createTable('messages', function(table) { table.increments('message_id').primary() table.integer('user_id').notNullable() table.integer('grouping_id').notNullable() table.string('message', 255).notNullable() }) } exports.down = function(knex) { return knex.schema .dropTable('users') .dropTable('profiles') .dropTable('response_keys') .dropTable('responses') .dropTable('groupings') .dropTable('memberships') .dropTable('chats') .dropTable('messages') }