First unchecked draft for tags

This commit is contained in:
araemer 2026-02-21 08:28:15 +01:00
parent f936e84168
commit 70b132dc6f
51 changed files with 494 additions and 69 deletions

View file

@ -0,0 +1,46 @@
import {MigrationInterface, QueryRunner, Table} from "typeorm";
/**
* Creates the `tag` table.
*/
export class CreateTagTable1771658108802 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "tag",
columns: [
{
name: "id",
type: "uuid",
isPrimary: true,
generationStrategy: "uuid",
default: "uuid_generate_v4()",
},
{
name: "description",
type: "varchar",
length: "100",
isUnique: true,
isNullable: false,
},
{
name: "create_date",
type: "timestamp",
default: "now()",
},
{
name: "update_date",
type: "timestamp",
default: "now()",
},
],
}),
true // ifNotExists
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable("tag", true);
}
}

View file

@ -0,0 +1,66 @@
import {MigrationInterface, QueryRunner, Table, TableForeignKey} from "typeorm";
/**
* Creates the `recipe_tag` many-to-many join table.
*
* Both foreign keys are defined with ON DELETE CASCADE so that:
* - deleting a Recipe automatically removes its rows from this table, and
* - deleting a Tag automatically removes its rows from this table.
* In both cases the other side of the relation is left untouched.
*/
export class CreateRecipeTagTable1771658131258 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: "recipe_tag",
columns: [
{
name: "recipe_id",
type: "uuid",
isPrimary: true,
},
{
name: "tag_id",
type: "uuid",
isPrimary: true,
},
],
}),
true // ifNotExists
);
// FK: recipe_tag.recipe_id → recipe.id (cascade on recipe delete)
await queryRunner.createForeignKey(
"recipe_tag",
new TableForeignKey({
name: "FK_recipe_tag_recipe",
columnNames: ["recipe_id"],
referencedTableName: "recipe",
referencedColumnNames: ["id"],
onDelete: "CASCADE",
onUpdate: "CASCADE",
})
);
// FK: recipe_tag.tag_id → tag.id (cascade on tag delete)
await queryRunner.createForeignKey(
"recipe_tag",
new TableForeignKey({
name: "FK_recipe_tag_tag",
columnNames: ["tag_id"],
referencedTableName: "tag",
referencedColumnNames: ["id"],
onDelete: "CASCADE",
onUpdate: "CASCADE",
})
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropForeignKey("recipe_tag", "FK_recipe_tag_tag");
await queryRunner.dropForeignKey("recipe_tag", "FK_recipe_tag_recipe");
await queryRunner.dropTable("recipe_tag", true);
}
}