Repository: louislam/uptime-kuma
File: db/knex_init_db.js (JavaScript)

Code before:

        table.index("active");
        table.index([ "strategy", "active" ], "manual_active");
        table.index("user_id", "maintenance_user_id");
    });

    // status_page
    await knex.schema.createTable("status_page", (table) => {
        table.increments("id");
        table.string("slug", 255).notNullable().unique().collate("utf8_general_ci");
        table.string("title", 255).notNullable();
        table.text("description");
        table.string("icon", 255).notNullable();
        table.string("theme", 30).notNullable();
        table.boolean("published").notNullable().defaultTo(true);
        table.boolean("search_engine_index").notNullable().defaultTo(true);
        table.boolean("show_tags").notNullable().defaultTo(false);
        table.string("password");
        table.datetime("created_date").notNullable().defaultTo(knex.fn.now());
        table.datetime("modified_date").notNullable().defaultTo(knex.fn.now());
        table.text("footer_text");
        table.text("custom_css");
        table.boolean("show_powered_by").notNullable().defaultTo(true);
        table.string("google_analytics_tag_id");
        table.string("umami_analytics_domain_url");
        table.string("umami_analytics_website_id");
    });

    // maintenance_status_page
    await knex.schema.createTable("maintenance_status_page", (table) => {
        table.increments("id");

        table.integer("status_page_id").unsigned().notNullable()
            .references("id").inTable("status_page")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");

        table.integer("maintenance_id").unsigned().notNullable()
            .references("id").inTable("maintenance")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");
    });

    // maintenance_timeslot
    await knex.schema.createTable("maintenance_timeslot", (table) => {
        table.increments("id");
        table.integer("maintenance_id").unsigned().notNullable()
            .references("id").inTable("maintenance")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");
        table.datetime("start_date").notNullable();

Review comment (suggestion):
Regarding DB-Design as discussed below:
I think we should name this `analytics_domain_url` and `analytics_id` (rename from `google_analytics_tag_id`) instead.

Code after:

        table.index("active");
        table.index([ "strategy", "active" ], "manual_active");
        table.index("user_id", "maintenance_user_id");
    });

    // status_page
    await knex.schema.createTable("status_page", (table) => {
        table.increments("id");
        table.string("slug", 255).notNullable().unique().collate("utf8_general_ci");
        table.string("title", 255).notNullable();
        table.text("description");
        table.string("icon", 255).notNullable();
        table.string("theme", 30).notNullable();
        table.boolean("published").notNullable().defaultTo(true);
        table.boolean("search_engine_index").notNullable().defaultTo(true);
        table.boolean("show_tags").notNullable().defaultTo(false);
        table.string("password");
        table.datetime("created_date").notNullable().defaultTo(knex.fn.now());
        table.datetime("modified_date").notNullable().defaultTo(knex.fn.now());
        table.text("footer_text");
        table.text("custom_css");
        table.boolean("show_powered_by").notNullable().defaultTo(true);
        table.string("google_analytics_tag_id");
    });

    // maintenance_status_page
    await knex.schema.createTable("maintenance_status_page", (table) => {
        table.increments("id");

        table.integer("status_page_id").unsigned().notNullable()
            .references("id").inTable("status_page")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");

        table.integer("maintenance_id").unsigned().notNullable()
            .references("id").inTable("maintenance")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");
    });

    // maintenance_timeslot
    await knex.schema.createTable("maintenance_timeslot", (table) => {
        table.increments("id");
        table.integer("maintenance_id").unsigned().notNullable()
            .references("id").inTable("maintenance")
            .onDelete("CASCADE")
            .onUpdate("CASCADE");
        table.datetime("start_date").notNullable();
        table.datetime("end_date");
        table.boolean("generated_next").defaultTo(false);