import * as Knex from "knex"; import { sha512 } from "js-sha512"; export async function up(knex: Knex): Promise { // Users table. await knex.schema.createTable( 'users', (table: any) => { table.increments('id'); table.string('email'); table.string('passwordHash') } ) // Add user column to other object tables. await knex.schema.alterTable( 'songs', (table: any) => { table.integer('user').unsigned().notNullable().defaultTo(1); } ) await knex.schema.alterTable( 'albums', (table: any) => { table.integer('user').unsigned().notNullable().defaultTo(1); } ) await knex.schema.alterTable( 'tags', (table: any) => { table.integer('user').unsigned().notNullable().defaultTo(1); } ) await knex.schema.alterTable( 'artists', (table: any) => { table.integer('user').unsigned().notNullable().defaultTo(1); } ) } export async function down(knex: Knex): Promise { await knex.schema.dropTable('users'); // Remove the user column await knex.schema.alterTable( 'songs', (table: any) => { table.dropColumn('user'); } ) await knex.schema.alterTable( 'albums', (table: any) => { table.dropColumn('user'); } ) await knex.schema.alterTable( 'tags', (table: any) => { table.dropColumn('user'); } ) await knex.schema.alterTable( 'artists', (table: any) => { table.dropColumn('user'); } ) }