You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
1.7 KiB
73 lines
1.7 KiB
import * as Knex from "knex"; |
|
import { sha512 } from "js-sha512"; |
|
|
|
|
|
export async function up(knex: Knex): Promise<void> { |
|
// 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<void> { |
|
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'); |
|
} |
|
) |
|
} |
|
|
|
|