-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: client and server-only mods (#71)
* feat: local registry database migrations * chore: store raw API responses in local registry * feat: update ficsit-resolver * feat: client and server-only mods * fix: remove mods that no longer support the current target
- Loading branch information
1 parent
bf6d6b0
commit 3640e5e
Showing
11 changed files
with
392 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package localregistry | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
) | ||
|
||
var migrations = []func(*sql.Tx) error{ | ||
initialSetup, | ||
addRequiredOnRemote, | ||
} | ||
|
||
func applyMigrations(db *sql.DB) error { | ||
// user_version will store the 1-indexed migration that was last applied | ||
var nextMigration int | ||
err := db.QueryRow("PRAGMA user_version;").Scan(&nextMigration) | ||
if err != nil { | ||
return fmt.Errorf("failed to get user_version: %w", err) | ||
} | ||
|
||
for i := nextMigration; i < len(migrations); i++ { | ||
err := applyMigration(db, i) | ||
if err != nil { | ||
return fmt.Errorf("failed to apply migration %d: %w", i, err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func applyMigration(db *sql.DB, migrationIndex int) error { | ||
tx, err := db.Begin() | ||
if err != nil { | ||
return fmt.Errorf("failed to start transaction: %w", err) | ||
} | ||
// Will noop if the transaction was committed | ||
defer tx.Rollback() //nolint:errcheck | ||
|
||
err = migrations[migrationIndex](tx) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = tx.Exec(fmt.Sprintf("PRAGMA user_version = %d;", migrationIndex+1)) | ||
if err != nil { | ||
return fmt.Errorf("failed to set user_version: %w", err) | ||
} | ||
|
||
err = tx.Commit() | ||
if err != nil { | ||
return fmt.Errorf("failed to commit transaction: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func initialSetup(tx *sql.Tx) error { | ||
// Create the initial user | ||
_, err := tx.Exec(` | ||
CREATE TABLE IF NOT EXISTS "versions" ( | ||
"id" TEXT NOT NULL PRIMARY KEY, | ||
"mod_reference" TEXT NOT NULL, | ||
"version" TEXT NOT NULL, | ||
"game_version" TEXT NOT NULL | ||
); | ||
CREATE INDEX IF NOT EXISTS "mod_reference" ON "versions" ("mod_reference"); | ||
CREATE UNIQUE INDEX IF NOT EXISTS "mod_version" ON "versions" ("mod_reference", "version"); | ||
CREATE TABLE IF NOT EXISTS "dependencies" ( | ||
"version_id" TEXT NOT NULL, | ||
"dependency" TEXT NOT NULL, | ||
"condition" TEXT NOT NULL, | ||
"optional" INT NOT NULL, | ||
FOREIGN KEY ("version_id") REFERENCES "versions" ("id") ON DELETE CASCADE, | ||
PRIMARY KEY ("version_id", "dependency") | ||
); | ||
CREATE TABLE IF NOT EXISTS "targets" ( | ||
"version_id" TEXT NOT NULL, | ||
"target_name" TEXT NOT NULL, | ||
"link" TEXT NOT NULL, | ||
"hash" TEXT NOT NULL, | ||
"size" INT NOT NULL, | ||
FOREIGN KEY ("version_id") REFERENCES "versions" ("id") ON DELETE CASCADE, | ||
PRIMARY KEY ("version_id", "target_name") | ||
); | ||
`) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to create initial tables: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func addRequiredOnRemote(tx *sql.Tx) error { | ||
_, err := tx.Exec(` | ||
ALTER TABLE "versions" ADD COLUMN "required_on_remote" INT NOT NULL DEFAULT 1; | ||
`) | ||
|
||
if err != nil { | ||
return fmt.Errorf("failed to add required_on_remote column: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package provider | ||
|
||
import ( | ||
resolver "github.com/satisfactorymodding/ficsit-resolver" | ||
"github.com/spf13/viper" | ||
|
||
"github.com/satisfactorymodding/ficsit-cli/ficsit" | ||
) | ||
|
||
func convertFicsitVersionsToResolver(versions []ficsit.ModVersion) []resolver.ModVersion { | ||
modVersions := make([]resolver.ModVersion, len(versions)) | ||
for i, modVersion := range versions { | ||
dependencies := make([]resolver.Dependency, len(modVersion.Dependencies)) | ||
for j, dependency := range modVersion.Dependencies { | ||
dependencies[j] = resolver.Dependency{ | ||
ModID: dependency.ModID, | ||
Condition: dependency.Condition, | ||
Optional: dependency.Optional, | ||
} | ||
} | ||
|
||
targets := make([]resolver.Target, len(modVersion.Targets)) | ||
for j, target := range modVersion.Targets { | ||
targets[j] = resolver.Target{ | ||
TargetName: resolver.TargetName(target.TargetName), | ||
Link: viper.GetString("api-base") + target.Link, | ||
Hash: target.Hash, | ||
Size: target.Size, | ||
} | ||
} | ||
|
||
modVersions[i] = resolver.ModVersion{ | ||
Version: modVersion.Version, | ||
GameVersion: modVersion.GameVersion, | ||
Dependencies: dependencies, | ||
Targets: targets, | ||
RequiredOnRemote: modVersion.RequiredOnRemote, | ||
} | ||
} | ||
return modVersions | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.