From a2dc9e2d0894b65906b669b7c5f76bdb94c1c013 Mon Sep 17 00:00:00 2001 From: Petr Pavlik Date: Mon, 11 Mar 2024 22:05:49 +0100 Subject: [PATCH] update dependencies and refactor field key (#12) --- Package.resolved | 62 ++++++++++++------- .../App/Migrations/CreateOrganization.swift | 10 +-- Sources/App/Migrations/CreateProfile.swift | 18 +++--- .../CreateProfileOrganizationRole.swift | 12 ++-- Sources/App/Models/FIeldKeys.swift | 22 +++++++ Sources/App/Models/Organization.swift | 8 +-- Sources/App/Models/Profile.swift | 14 ++--- .../App/Models/ProfileOrganizationRole.swift | 8 +-- 8 files changed, 97 insertions(+), 57 deletions(-) create mode 100644 Sources/App/Models/FIeldKeys.swift diff --git a/Package.resolved b/Package.resolved index e155202..64a4ab5 100644 --- a/Package.resolved +++ b/Package.resolved @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlCatchException.git", "state" : { - "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", - "version" : "2.1.2" + "revision" : "3ef6999c73b6938cc0da422f2c912d0158abb0a0", + "version" : "2.2.0" } }, { @@ -41,8 +41,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", "state" : { - "revision" : "dc9af4781f2afdd1e68e90f80b8603be73ea7abc", - "version" : "2.2.0" + "revision" : "2ef56b2caf25f55fa7eef8784c30d5a767550f54", + "version" : "2.2.1" } }, { @@ -59,8 +59,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/fluent-kit.git", "state" : { - "revision" : "6cef8533c9ab87865de58fa3c6e6317e3e09857a", - "version" : "1.45.1" + "revision" : "bb47433520116b3cf7f3567137c81106b398b77e", + "version" : "1.47.1" } }, { @@ -86,8 +86,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/jwt-kit.git", "state" : { - "revision" : "cd0fe3af36764e876182137c3132a6d8459e1867", - "version" : "4.13.1" + "revision" : "e05513b5aec24f88012b6e3034115b6bc915356a", + "version" : "4.13.2" } }, { @@ -113,8 +113,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/Quick/Nimble.git", "state" : { - "revision" : "c1f3dd66222d5e7a1a20afc237f7e7bc432c564f", - "version" : "13.2.0" + "revision" : "efe11bbca024b57115260709b5c05e01131470d0", + "version" : "13.2.1" } }, { @@ -122,8 +122,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/postgres-kit.git", "state" : { - "revision" : "80ab7737dac4fccd4a8ad38743828dcb71ba7ac8", - "version" : "2.12.2" + "revision" : "475bf6f04ee1840917a70c32b48e4a724df4ccaf", + "version" : "2.12.3" } }, { @@ -131,8 +131,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/postgres-nio.git", "state" : { - "revision" : "fa3137d39bca84843739db1c5a3db2d7f4ae65e6", - "version" : "1.20.0" + "revision" : "6f0fc054babeed13850f9014e03ced7a1d714868", + "version" : "1.21.0" } }, { @@ -171,6 +171,15 @@ "version" : "1.2.0" } }, + { + "identity" : "swift-async-algorithms", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-async-algorithms.git", + "state" : { + "revision" : "da4e36f86544cdf733a40d59b3a2267e3a7bbf36", + "version" : "1.0.0" + } + }, { "identity" : "swift-atomics", "kind" : "remoteSourceControl", @@ -185,8 +194,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-collections.git", "state" : { - "revision" : "d029d9d39c87bed85b1c50adee7c41795261a192", - "version" : "1.0.6" + "revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb", + "version" : "1.1.0" } }, { @@ -230,8 +239,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio.git", "state" : { - "revision" : "635b2589494c97e48c62514bc8b37ced762e0a62", - "version" : "2.63.0" + "revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982", + "version" : "2.64.0" } }, { @@ -239,8 +248,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-nio-extras.git", "state" : { - "revision" : "363da63c1966405764f380c627409b2f9d9e710b", - "version" : "1.21.0" + "revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63", + "version" : "1.22.0" } }, { @@ -288,6 +297,15 @@ "revision" : "2bc05a18f20fcf124520f078b57a58e6c6f077c5" } }, + { + "identity" : "swift-service-lifecycle", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swift-server/swift-service-lifecycle.git", + "state" : { + "revision" : "d7fe0e731499a8dcce53bf4cbbc812c8e565d3a7", + "version" : "2.4.1" + } + }, { "identity" : "swift-system", "kind" : "remoteSourceControl", @@ -311,8 +329,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/vapor/vapor.git", "state" : { - "revision" : "4942d74e8493fc918ed6144c835c8a0e6affd4f4", - "version" : "4.92.1" + "revision" : "3a7da193a2937472b252b8db210897e7abf37b47", + "version" : "4.92.4" } }, { diff --git a/Sources/App/Migrations/CreateOrganization.swift b/Sources/App/Migrations/CreateOrganization.swift index 767802f..ea29d97 100644 --- a/Sources/App/Migrations/CreateOrganization.swift +++ b/Sources/App/Migrations/CreateOrganization.swift @@ -4,11 +4,11 @@ struct CreateOrganization: AsyncMigration { func prepare(on database: Database) async throws { try await database.schema(Organization.schema) .id() - .field("name", .string, .required) - .field("api_key", .string) - .field("created_at", .datetime) - .field("updated_at", .datetime) - .unique(on: "api_key") + .field(.name, .string, .required) + .field(.apiKey, .string) + .field(.createdAt, .datetime) + .field(.updatedAt, .datetime) + .unique(on: .apiKey) .create() } diff --git a/Sources/App/Migrations/CreateProfile.swift b/Sources/App/Migrations/CreateProfile.swift index b9a14df..8932112 100644 --- a/Sources/App/Migrations/CreateProfile.swift +++ b/Sources/App/Migrations/CreateProfile.swift @@ -4,15 +4,15 @@ struct CreateProfile: AsyncMigration { func prepare(on database: Database) async throws { try await database.schema(Profile.schema) .id() - .field("firebase_user_id", .string, .required) - .field("email", .string, .required) - .field("name", .string) - .field("avatar_url", .string) - .field("subscribed_to_newsletter_at", .date) - .field("created_at", .datetime) - .field("updated_at", .datetime) - .unique(on: "firebase_user_id") - .unique(on: "email") + .field(.firebaseUserId, .string, .required) + .field(.email, .string, .required) + .field(.name, .string) + .field(.avatarUrl, .string) + .field(.subscribedToNewsletterAt, .date) + .field(.createdAt, .datetime) + .field(.updatedAt, .datetime) + .unique(on: .firebaseUserId) + .unique(on: .email) .create() } diff --git a/Sources/App/Migrations/CreateProfileOrganizationRole.swift b/Sources/App/Migrations/CreateProfileOrganizationRole.swift index 764fd15..3ceafd8 100644 --- a/Sources/App/Migrations/CreateProfileOrganizationRole.swift +++ b/Sources/App/Migrations/CreateProfileOrganizationRole.swift @@ -11,12 +11,12 @@ struct CreateProfileOrganizationRole: AsyncMigration { try await database.schema(ProfileOrganizationRole.schema) .id() - .field("role", organizationRoles, .required) - .field("profile_id", .uuid, .references(Profile.schema, "id", onDelete: .cascade)) - .field("organization_id", .uuid, .references(Organization.schema, "id", onDelete: .cascade)) - .field("created_at", .datetime) - .field("updated_at", .datetime) - .unique(on: "profile_id", "organization_id") + .field(.role, organizationRoles, .required) + .field(.profileId, .uuid, .references(Profile.schema, "id", onDelete: .cascade)) + .field(.organizationId, .uuid, .references(Organization.schema, "id", onDelete: .cascade)) + .field(.createdAt, .datetime) + .field(.updatedAt, .datetime) + .unique(on: .profileId, .organizationId) .create() } diff --git a/Sources/App/Models/FIeldKeys.swift b/Sources/App/Models/FIeldKeys.swift new file mode 100644 index 0000000..b392b5e --- /dev/null +++ b/Sources/App/Models/FIeldKeys.swift @@ -0,0 +1,22 @@ +// +// File.swift +// +// +// Created by Petr Pavlik on 11.03.2024. +// + +import Fluent + +extension FieldKey { + static let name: FieldKey = "name" + static let createdAt: FieldKey = "created_at" + static let updatedAt: FieldKey = "updated_at" + static let apiKey: FieldKey = "api_key" + static let email: FieldKey = "email" + static let avatarUrl: FieldKey = "avatar_url" + static let firebaseUserId: FieldKey = "firebase_user_id" + static let subscribedToNewsletterAt: FieldKey = "subscribed_to_newsletter_at" + static let role: FieldKey = "role" + static let profileId: FieldKey = "profile_id" + static let organizationId: FieldKey = "organization_id" +} diff --git a/Sources/App/Models/Organization.swift b/Sources/App/Models/Organization.swift index 49af7e1..0bf4284 100644 --- a/Sources/App/Models/Organization.swift +++ b/Sources/App/Models/Organization.swift @@ -7,16 +7,16 @@ final class Organization: Model, Content { @ID(key: .id) var id: UUID? - @Field(key: "name") + @Field(key: .name) var name: String - @Timestamp(key: "created_at", on: .create) + @Timestamp(key: .createdAt, on: .create) var createdAt: Date? - @Timestamp(key: "updated_at", on: .update) + @Timestamp(key: .updatedAt, on: .update) var updatedAt: Date? - @OptionalField(key: "api_key") + @OptionalField(key: .apiKey) var apiKey: String? @Siblings(through: ProfileOrganizationRole.self, from: \.$organization, to: \.$profile) diff --git a/Sources/App/Models/Profile.swift b/Sources/App/Models/Profile.swift index 86b899c..51c52d5 100644 --- a/Sources/App/Models/Profile.swift +++ b/Sources/App/Models/Profile.swift @@ -7,25 +7,25 @@ final class Profile: Model, Content { @ID(key: .id) var id: UUID? - @Field(key: "firebase_user_id") + @Field(key: .firebaseUserId) var firebaseUserId: String - @Field(key: "email") + @Field(key: .email) var email: String - @OptionalField(key: "subscribed_to_newsletter_at") + @OptionalField(key: .subscribedToNewsletterAt) var subscribedToNewsletterAt: Date? - @OptionalField(key: "name") + @OptionalField(key: .name) var name: String? - @OptionalField(key: "avatar_url") + @OptionalField(key: .avatarUrl) var avatarUrl: String? - @Timestamp(key: "created_at", on: .create) + @Timestamp(key: .createdAt, on: .create) var createdAt: Date? - @Timestamp(key: "updated_at", on: .update) + @Timestamp(key: .updatedAt, on: .update) var updatedAt: Date? @Siblings(through: ProfileOrganizationRole.self, from: \.$profile, to: \.$organization) diff --git a/Sources/App/Models/ProfileOrganizationRole.swift b/Sources/App/Models/ProfileOrganizationRole.swift index eee5617..db7dcb4 100644 --- a/Sources/App/Models/ProfileOrganizationRole.swift +++ b/Sources/App/Models/ProfileOrganizationRole.swift @@ -20,19 +20,19 @@ final class ProfileOrganizationRole: Model { @ID(key: .id) var id: UUID? - @Parent(key: "profile_id") + @Parent(key: .profileId) var profile: Profile - @Parent(key: "organization_id") + @Parent(key: .organizationId) var organization: Organization @Enum(key: "role") var role: Role - @Timestamp(key: "created_at", on: .create) + @Timestamp(key: .createdAt, on: .create) var createdAt: Date? - @Timestamp(key: "updated_at", on: .update) + @Timestamp(key: .updatedAt, on: .update) var updatedAt: Date? init() { }