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.
 
 
 
 

145 lines
4.3 KiB

import * as Knex from "knex";
export async function up(knex: Knex): Promise<void> {
// tracks table.
await knex.schema.createTable(
'tracks',
(table: any) => {
table.increments('id');
table.string('name');
table.string('storeLinks')
table.integer('user').unsigned().notNullable().defaultTo(1);
table.integer('album').unsigned().defaultTo(null);
}
)
// Artists table.
await knex.schema.createTable(
'artists',
(table: any) => {
table.increments('id');
table.string('name');
table.string('storeLinks');
table.integer('user').unsigned().notNullable().defaultTo(1);
}
)
// Albums table.
await knex.schema.createTable(
'albums',
(table: any) => {
table.increments('id');
table.string('name');
table.string('storeLinks');
table.integer('user').unsigned().notNullable().defaultTo(1);
}
)
// Tags table.
await knex.schema.createTable(
'tags',
(table: any) => {
table.increments('id');
table.string('name');
table.integer('parentId');
table.integer('user').unsigned().notNullable().defaultTo(1);
}
)
// Users table.
await knex.schema.createTable(
'users',
(table: any) => {
table.increments('id');
table.string('email');
table.string('passwordHash')
}
)
// Integrations table.
await knex.schema.createTable(
'integrations',
(table: any) => {
table.increments('id');
table.integer('user').unsigned().notNullable().defaultTo(1);
table.string('name').notNullable(); // Uniquely identifies this integration configuration for the user.
table.string('type').notNullable(); // Enumerates different supported integration types (e.g. Spotify)
table.string('details'); // Stores anything that might be needed for the integration to work.
table.string('secretDetails'); // Stores anything that might be needed for the integration to work and which
// should never leave the server.
}
)
// tracks <-> Artists
await knex.schema.createTable(
'tracks_artists',
(table: any) => {
table.increments('id');
table.integer('trackId');
table.integer('artistId');
table.unique(['trackId', 'artistId'])
}
)
// tracks <-> Tags
await knex.schema.createTable(
'tracks_tags',
(table: any) => {
table.increments('id');
table.integer('trackId');
table.integer('tagId');
table.unique(['trackId', 'tagId'])
}
)
// Artists <-> Tags
await knex.schema.createTable(
'artists_tags',
(table: any) => {
table.increments('id');
table.integer('artistId');
table.integer('tagId');
table.unique(['artistId', 'tagId'])
}
)
// Albums <-> Tags
await knex.schema.createTable(
'albums_tags',
(table: any) => {
table.increments('id');
table.integer('tagId');
table.integer('albumId');
table.unique(['albumId', 'tagId'])
}
)
// Artists <-> Albums
await knex.schema.createTable(
'artists_albums',
(table: any) => {
table.increments('id');
table.integer('artistId');
table.integer('albumId');
table.unique(['artistId', 'albumId'])
}
)
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTable('tracks');
await knex.schema.dropTable('artists');
await knex.schema.dropTable('albums');
await knex.schema.dropTable('tags');
await knex.schema.dropTable('tracks_artists');
await knex.schema.dropTable('tracks_albums');
await knex.schema.dropTable('tracks_tags');
await knex.schema.dropTable('artists_tags');
await knex.schema.dropTable('albums_tags');
await knex.schema.dropTable('artists_albums');
await knex.schema.dropTable('users');
await knex.schema.dropTable('integrations');
}