Skip to content

Commit

Permalink
update dependencies and refactor field key (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrpavlik committed Mar 11, 2024
1 parent d0acfd1 commit a2dc9e2
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 57 deletions.
62 changes: 40 additions & 22 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"state" : {
"revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00",
"version" : "2.1.2"
"revision" : "3ef6999c73b6938cc0da422f2c912d0158abb0a0",
"version" : "2.2.0"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "dc9af4781f2afdd1e68e90f80b8603be73ea7abc",
"version" : "2.2.0"
"revision" : "2ef56b2caf25f55fa7eef8784c30d5a767550f54",
"version" : "2.2.1"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -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"
}
},
{
Expand All @@ -113,26 +113,26 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "c1f3dd66222d5e7a1a20afc237f7e7bc432c564f",
"version" : "13.2.0"
"revision" : "efe11bbca024b57115260709b5c05e01131470d0",
"version" : "13.2.1"
}
},
{
"identity" : "postgres-kit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/postgres-kit.git",
"state" : {
"revision" : "80ab7737dac4fccd4a8ad38743828dcb71ba7ac8",
"version" : "2.12.2"
"revision" : "475bf6f04ee1840917a70c32b48e4a724df4ccaf",
"version" : "2.12.3"
}
},
{
"identity" : "postgres-nio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/vapor/postgres-nio.git",
"state" : {
"revision" : "fa3137d39bca84843739db1c5a3db2d7f4ae65e6",
"version" : "1.20.0"
"revision" : "6f0fc054babeed13850f9014e03ced7a1d714868",
"version" : "1.21.0"
}
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
},
{
Expand Down Expand Up @@ -230,17 +239,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio.git",
"state" : {
"revision" : "635b2589494c97e48c62514bc8b37ced762e0a62",
"version" : "2.63.0"
"revision" : "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version" : "2.64.0"
}
},
{
"identity" : "swift-nio-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-nio-extras.git",
"state" : {
"revision" : "363da63c1966405764f380c627409b2f9d9e710b",
"version" : "1.21.0"
"revision" : "a3b640d7dc567225db7c94386a6e71aded1bfa63",
"version" : "1.22.0"
}
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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"
}
},
{
Expand Down
10 changes: 5 additions & 5 deletions Sources/App/Migrations/CreateOrganization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
18 changes: 9 additions & 9 deletions Sources/App/Migrations/CreateProfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/App/Migrations/CreateProfileOrganizationRole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
22 changes: 22 additions & 0 deletions Sources/App/Models/FIeldKeys.swift
Original file line number Diff line number Diff line change
@@ -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"
}
8 changes: 4 additions & 4 deletions Sources/App/Models/Organization.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions Sources/App/Models/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Sources/App/Models/ProfileOrganizationRole.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
Expand Down

0 comments on commit a2dc9e2

Please sign in to comment.