Skip to content

Commit bb968b0

Browse files
supersonicbytedaveverwer
authored andcommitted
Update Fork to containt fallback url
1 parent 3ae6ba7 commit bb968b0

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Sources/App/Commands/Ingest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func getFork(on database: Database, parent: Github.Metadata.Parent?) async -> Fo
223223
if let packageId = try? await Package.query(on: database)
224224
.filter(\.$url, .custom("ilike"), parentUrl)
225225
.first()?.id {
226-
return .parentId(packageId)
226+
return .parentId(id: packageId, fallbackURL: parentUrl)
227227
} else {
228228
return .parentURL(parentUrl)
229229
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Fluent
16+
import SQLKit
17+
18+
19+
struct UpdateRepositoryAddForkedFrom2: AsyncMigration {
20+
func prepare(on database: Database) async throws {
21+
guard let db = database as? SQLDatabase else {
22+
fatalError("Database must be an SQLDatabase ('as? SQLDatabase' must succeed)")
23+
}
24+
25+
try await db.raw(#"UPDATE "repositories" SET forked_from = NULL"#).run()
26+
}
27+
28+
func revert(on database: Database) async throws {
29+
// There's nothing we can do to restore the previous state
30+
}
31+
}

Sources/App/Models/Repository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,6 @@ enum S3Readme: Codable, Equatable {
273273
}
274274

275275
enum Fork: Codable, Equatable {
276-
case parentId(Package.Id)
276+
case parentId(id: Package.Id, fallbackURL: String)
277277
case parentURL(String)
278278
}

Sources/App/configure.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ public func configure(_ app: Application) async throws -> String {
337337
do { // Migration 079 - Add `forked_from` to `repositories`
338338
app.migrations.add(UpdateRepositoryAddForkedFrom())
339339
}
340+
do { // Migration 080 - Set`forkded_from` to NULL because of Fork model change in Repository
341+
app.migrations.add(UpdateRepositoryAddForkedFrom2())
342+
}
340343

341344
app.asyncCommands.use(Analyze.Command(), as: "analyze")
342345
app.asyncCommands.use(CreateRestfileCommand(), as: "create-restfile")

0 commit comments

Comments
 (0)