From 35ab8da254006f9146083979285c5465fbc9321f Mon Sep 17 00:00:00 2001 From: Jaume Date: Mon, 2 Dec 2024 21:26:30 +0100 Subject: [PATCH] Adding some keys to the tables --- .../migrations/initial-migration.swift | 40 ++++++++++++++++++- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/swift-server/migrations/initial-migration.swift b/src/swift-server/migrations/initial-migration.swift index 70ecc08..111f38d 100644 --- a/src/swift-server/migrations/initial-migration.swift +++ b/src/swift-server/migrations/initial-migration.swift @@ -3,6 +3,7 @@ import FluentSQL struct InitialMigration: AsyncMigration { func prepare(on database: Database) async throws { + let sqlDb = database as? SQLDatabase try await database.schema("users") .id() .field("username", .string, .required) @@ -33,6 +34,7 @@ struct InitialMigration: AsyncMigration { .id() .field("user_id", .uuid, .required, .references("users", "id")) .field("group_id", .uuid, .required, .references("user_groups", "id")) + .unique(on: "user_id", "group_id") .create() try await database.schema("core_bank_transaction") @@ -46,6 +48,10 @@ struct InitialMigration: AsyncMigration { .field("kind", .string, .required) .field("description", .string) .create() + try await sqlDb?.create(index: "group_owner_idx") + .on("core_bank_transaction") + .column("group_owner_id") + .run() try await database.schema("core_label") .id() @@ -53,6 +59,7 @@ struct InitialMigration: AsyncMigration { .field("name", .string, .required) .create() + #warning("Add enum for the link_reason") try await database.schema("core_label_transaction") .id() .field("label_id", .uuid, .required, .references("core_label", "id")) @@ -64,6 +71,10 @@ struct InitialMigration: AsyncMigration { .field("link_reason", .string, .required) .unique(on: "label_id", "transaction_id") .create() + try await sqlDb?.create(index: "label_transaction_transaction_idx") + .on("core_label_transaction") + .column("transaction_id") + .run() try await database.schema("core_rule") .id() @@ -72,6 +83,10 @@ struct InitialMigration: AsyncMigration { .field("conditions_relation", .string, .required) .field("parent_id", .uuid, .references("core_rule", "id")) .create() + try await sqlDb?.create(index: "core_rule_group_owner_idx") + .on("core_rule") + .column("group_owner_id") + .run() try await database.schema("core_condition") .id() @@ -79,8 +94,11 @@ struct InitialMigration: AsyncMigration { .field("operation", .string, .required) .field("value_str", .string) .field("value_double", .double) - // .index("rule_id") .create() + try await sqlDb?.create(index: "core_condition_rule_idx") + .on("core_condition") + .column("rule_id") + .run() try await database.schema("core_rule_label_action") .id() @@ -89,6 +107,11 @@ struct InitialMigration: AsyncMigration { .unique(on: "rule_id", "label_id") .create() + try await sqlDb?.create(index: "core_rule_label_action_label_idx") + .on("core_rule_label_action") + .column("label_id") + .run() + try await database.schema("core_rule_label_pivot") .id() .field( @@ -110,6 +133,10 @@ struct InitialMigration: AsyncMigration { .field("label_filter", .uuid, .references("core_label", "id")) .field("date_range", .string, .required) .create() + try await sqlDb?.create(index: "graph_graph_group_owner_idx") + .on("graph_graph") + .column("group_owner_id") + .run() try await database.schema("graph_group") .field( @@ -129,7 +156,6 @@ struct InitialMigration: AsyncMigration { .field("group", .string, .required) .field("hide_others", .bool) .field("accumulate", .bool, .required) - .create() try await database.schema("graph_group_labels") @@ -164,6 +190,10 @@ struct InitialMigration: AsyncMigration { .field("stack", .string) .field("context", .string) .create() + try await sqlDb?.create(index: "import_fileimport_group_owner_idx") + .on("import_fileimport") + .column("group_owner_id") + .run() try await database.schema("import_fileimport_row") .id() @@ -180,6 +210,12 @@ struct InitialMigration: AsyncMigration { .field("message", .string) .field("transaction_id", .uuid) .create() + + try await sqlDb?.create(index: "import_fileimport_row_report_idx") + .on("import_fileimport_row") + .column("report_id") + .run() + } func revert(on database: Database) async throws {