mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
feat(server): save genres for artists and albums
This can later be used for reports
This commit is contained in:
parent
9b96d0fab4
commit
3c6f3289f1
12 changed files with 225 additions and 0 deletions
132
src/database/migrations/05-CreateGenreTables.ts
Normal file
132
src/database/migrations/05-CreateGenreTables.ts
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
import {
|
||||
MigrationInterface,
|
||||
QueryRunner,
|
||||
Table,
|
||||
TableIndex,
|
||||
TableForeignKey,
|
||||
} from "typeorm";
|
||||
import { TableColumnOptions } from "typeorm/schema-builder/options/TableColumnOptions";
|
||||
|
||||
const primaryUUIDColumn: TableColumnOptions = {
|
||||
name: "id",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
generationStrategy: "uuid",
|
||||
};
|
||||
|
||||
export class CreateGenreTables0000000000005 implements MigrationInterface {
|
||||
async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "genre",
|
||||
columns: [
|
||||
primaryUUIDColumn,
|
||||
{
|
||||
name: "name",
|
||||
type: "varchar",
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
new TableIndex({
|
||||
name: "IDX_GENRE_NAME",
|
||||
columnNames: ["name"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "artist_genres",
|
||||
columns: [
|
||||
{
|
||||
name: "artistId",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "genreId",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
new TableIndex({
|
||||
name: "IDX_ARTIST_GENRES_ARTIST_ID",
|
||||
columnNames: ["artistId"],
|
||||
}),
|
||||
new TableIndex({
|
||||
name: "IDX_ARTIST_GENRES_GENRE_ID",
|
||||
columnNames: ["genreId"],
|
||||
}),
|
||||
],
|
||||
foreignKeys: [
|
||||
new TableForeignKey({
|
||||
name: "FK_ARTIST_ID",
|
||||
columnNames: ["artistId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "artist",
|
||||
}),
|
||||
new TableForeignKey({
|
||||
name: "FK_GENRE_ID",
|
||||
columnNames: ["genreId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "genre",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: "artist_genres",
|
||||
columns: [
|
||||
{
|
||||
name: "artistId",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
},
|
||||
{
|
||||
name: "genreId",
|
||||
type: "uuid",
|
||||
isPrimary: true,
|
||||
},
|
||||
],
|
||||
indices: [
|
||||
new TableIndex({
|
||||
name: "IDX_ARTIST_GENRES_ARTIST_ID",
|
||||
columnNames: ["artistId"],
|
||||
}),
|
||||
new TableIndex({
|
||||
name: "IDX_ARTIST_GENRES_GENRE_ID",
|
||||
columnNames: ["genreId"],
|
||||
}),
|
||||
],
|
||||
foreignKeys: [
|
||||
new TableForeignKey({
|
||||
name: "FK_ARTIST_ID",
|
||||
columnNames: ["artistId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "artist",
|
||||
}),
|
||||
new TableForeignKey({
|
||||
name: "FK_GENRE_ID",
|
||||
columnNames: ["genreId"],
|
||||
referencedColumnNames: ["id"],
|
||||
referencedTableName: "genre",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable("album_genres");
|
||||
await queryRunner.dropTable("artist_genres");
|
||||
await queryRunner.dropTable("genre");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue