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.
 
 
 
 

119 lines
2.9 KiB

import * as Knex from "knex";
export async function up(knex: Knex): Promise<void> {
// Songs table.
await knex.schema.createTable(
'songs',
(table: any) => {
table.increments('id');
table.string('title');
table.json('storeLinks')
}
)
// Artists table.
await knex.schema.createTable(
'artists',
(table: any) => {
table.increments('id');
table.string('name');
table.json('storeLinks');
}
)
// Albums table.
await knex.schema.createTable(
'albums',
(table: any) => {
table.increments('id');
table.string('name');
table.json('storeLinks');
}
)
// Tags table.
await knex.schema.createTable(
'tags',
(table: any) => {
table.increments('id');
table.string('name');
table.integer('parentId');
}
)
// Songs <-> Artists
await knex.schema.createTable(
'songs_artists',
(table: any) => {
table.increments('id');
table.integer('songId');
table.integer('artistId');
}
)
// Songs <-> Albums
await knex.schema.createTable(
'songs_albums',
(table: any) => {
table.increments('id');
table.integer('songId');
table.integer('albumId');
}
)
// Songs <-> Tags
await knex.schema.createTable(
'songs_tags',
(table: any) => {
table.increments('id');
table.integer('songId');
table.integer('tagId');
}
)
// Artists <-> Tags
await knex.schema.createTable(
'artists_tags',
(table: any) => {
table.increments('id');
table.integer('artistId');
table.integer('tagId');
}
)
// Albums <-> Tags
await knex.schema.createTable(
'albums_tags',
(table: any) => {
table.increments('id');
table.integer('tagId');
table.integer('albumId');
}
)
// Artists <-> Albums
await knex.schema.createTable(
'artists_albums',
(table: any) => {
table.increments('id');
table.integer('artistId');
table.integer('albumId');
}
)
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.dropTable('songs');
await knex.schema.dropTable('artists');
await knex.schema.dropTable('albums');
await knex.schema.dropTable('tags');
await knex.schema.dropTable('songs_artists');
await knex.schema.dropTable('songs_albums');
await knex.schema.dropTable('songs_tags');
await knex.schema.dropTable('artists_tags');
await knex.schema.dropTable('albums_tags');
await knex.schema.dropTable('artists_albums');
}