Skip to content

Commit

Permalink
Adding some keys to the tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Dracks committed Dec 2, 2024
1 parent 021672d commit 35ab8da
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/swift-server/migrations/initial-migration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -46,13 +48,18 @@ 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()
.field("group_owner_id", .uuid, .required, .references("user_groups", "id"))
.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"))
Expand All @@ -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()
Expand All @@ -72,15 +83,22 @@ 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()
.field("rule_id", .uuid, .required, .references("core_rule", "id"))
.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()
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit 35ab8da

Please sign in to comment.