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 (refactor):
please remove this and the related parts and add it to a [new migration](https://github.com/louislam/uptime-kuma/tree/003ffc2cc2a3b572c197658b08b34a6618f804fa/db/knex_migrations), and only there (the `.sql` files are a crutch which we did not have the time/energy to clean up yet)

I think this file will only be run for new users, but not existing users.

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);