const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;

pub fn up(repo: anytype) !void {
    try repo.createTable(
        "tags",
        &.{
            t.primaryKey("id", .{}),
            t.column("name", .string, .{}),
            t.timestamps(.{}),
        },
        .{},
    );

    try repo.createTable(
        "blog_tags",
        &.{
            t.primaryKey("id", .{}),
            t.column("blog_id", .integer, .{ .reference = .{ "blogs", "id" } }),
            t.column("tag_id", .integer, .{ .reference = .{ "tags", "id" } }),
            t.timestamps(.{}),
        },
        .{},
    );
}

pub fn down(repo: anytype) !void {
    try repo.dropTable("tags", .{});
    try repo.dropTable("blog_tags", .{});
}
