Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Migrate to Prisma for the Internal launcher database #31

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ rustflags = [
]

[alias]
prisma = "run -p prisma-cli --bin prisma --"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repl-result-out*
.direnv

# Prisma
crates/prisma/src/prisma.rs
crates/prisma/src/prisma
dev.db
dev.db-journal

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ opt-level = 3
opt-level = 3
incremental = false


# sets the default for dependencies, except workspace members.
[profile.dev-debug.package."*"]
inherits = "dev"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/src-tauri/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string>OneLauncher</string>
<key>CFBundleURLSchemes</key>
<array>
<string>onelauncher</string>
<string>OneLauncher</string>
</array>
</dict>
</array>
Expand Down
7 changes: 6 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ default = []
tauri = [
"dep:tauri",
"dep:tauri-specta",
"dep:specta"
"dep:specta",
]
cli = [ "dep:indicatif" ]

[dependencies]
onelauncher_prisma = { path = "../prisma" }

# GUI-only deps
tauri = { workspace = true, optional = true }
tauri-specta = { workspace = true, optional = true }
specta = { workspace = true, optional = true }
# rspc = { workspace = true }
# rspc-tauri2 = { workspace = true, optional = true }

# CLI-only deps
indicatif = { workspace = true, optional = true }
Expand All @@ -49,6 +53,7 @@ serde = { workspace = true }
serde_json = { workspace = true }
serde_ini = { workspace = true }
flate2 = { workspace = true }
dashmap = { workspace = true }
paste = { workspace = true }
futures = { workspace = true }
tar = { workspace = true }
Expand Down
115 changes: 115 additions & 0 deletions crates/core/prisma/migrations/20240725024623_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
-- CreateTable
CREATE TABLE "settings" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0,
"theme" TEXT NOT NULL DEFAULT 'dark',
"hide_close_prompt" BOOLEAN NOT NULL DEFAULT true,
"disable_animations" BOOLEAN NOT NULL DEFAULT false,
"disable_analytics" BOOLEAN NOT NULL DEFAULT false,
"debug_mode" BOOLEAN NOT NULL DEFAULT false,
"hide_on_launch" BOOLEAN NOT NULL DEFAULT false,
"force_fullscreen" BOOLEAN NOT NULL DEFAULT false,
"disable_discord" BOOLEAN NOT NULL DEFAULT false,
"custom_java_args" TEXT NOT NULL,
"custom_env_args" TEXT NOT NULL,
"max_async_io_operations" INTEGER NOT NULL DEFAULT 10,
"max_async_fetches" INTEGER NOT NULL DEFAULT 10,
"resolution_x" INTEGER NOT NULL DEFAULT 854,
"resolution_y" INTEGER NOT NULL DEFAULT 480,
"memory_max" INTEGER NOT NULL DEFAULT 2048,
"memory_min" INTEGER NOT NULL DEFAULT 1024,
"hook_pre" TEXT,
"hook_wrapper" TEXT,
"hook_post" TEXT
);

-- CreateTable
CREATE TABLE "java_version" (
"major_version" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"full_version" TEXT NOT NULL,
"architecture" TEXT NOT NULL,
"path" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "minecraft_user" (
"uuid" TEXT NOT NULL PRIMARY KEY,
"active" BOOLEAN NOT NULL DEFAULT false,
"username" TEXT NOT NULL,
"access_token" TEXT NOT NULL,
"refresh_token" TEXT NOT NULL,
"expires" INTEGER NOT NULL
);

-- CreateTable
CREATE TABLE "minecraft_device_token" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT DEFAULT 0,
"uuid" TEXT NOT NULL,
"private_key" TEXT NOT NULL,
"x" TEXT NOT NULL,
"y" TEXT NOT NULL,
"issue_instant" INTEGER NOT NULL,
"not_after" INTEGER NOT NULL,
"token" TEXT NOT NULL,
"display_claims" TEXT NOT NULL
);

-- CreateTable
CREATE TABLE "cache" (
"id" TEXT NOT NULL PRIMARY KEY,
"data_type" TEXT NOT NULL,
"alias" TEXT,
"data" TEXT,
"expires" DATETIME NOT NULL,
"created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- CreateTable
CREATE TABLE "cluster" (
"path" TEXT NOT NULL PRIMARY KEY,
"stage" TEXT NOT NULL,
"name" TEXT NOT NULL,
"icon_path" TEXT,
"mc_version" TEXT NOT NULL,
"loader" TEXT NOT NULL DEFAULT 'vanilla',
"loader_version" TEXT DEFAULT 'stable',
"groups" TEXT NOT NULL,
"created_at" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"modified_at" DATETIME NOT NULL,
"played_at" DATETIME,
"overall_played" INTEGER NOT NULL DEFAULT 0,
"recently_played" INTEGER NOT NULL DEFAULT 0,
"override_java_path" TEXT,
"override_custom_java_args" TEXT NOT NULL,
"override_custom_env_args" TEXT NOT NULL,
"override_memory_max" INTEGER,
"override_memory_min" INTEGER,
"override_force_fullscreen" INTEGER,
"override_resolution_x" INTEGER,
"override_resolution_y" INTEGER,
"override_hook_pre" TEXT,
"override_hook_wrapper" TEXT,
"override_hook_post" TEXT
);

-- CreateTable
CREATE TABLE "process" (
"pid" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"start_time" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"name" TEXT NOT NULL,
"executable" TEXT NOT NULL,
"cluster_path" TEXT NOT NULL,
"post_exit" TEXT,
CONSTRAINT "process_cluster_path_fkey" FOREIGN KEY ("cluster_path") REFERENCES "cluster" ("path") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateIndex
CREATE UNIQUE INDEX "minecraft_user_active_key" ON "minecraft_user"("active");

-- CreateIndex
CREATE UNIQUE INDEX "cache_data_type_alias_key" ON "cache"("data_type", "alias");

-- CreateIndex
CREATE INDEX "process_cluster_path_idx" ON "process"("cluster_path");

-- CreateIndex
CREATE UNIQUE INDEX "process_pid_key" ON "process"("pid");
3 changes: 3 additions & 0 deletions crates/core/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "sqlite"
139 changes: 139 additions & 0 deletions crates/core/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
datasource db {
provider = "sqlite"
url = "file:dev.db"
}

generator client {
provider = "cargo prisma"
output = "../../prisma/src/prisma"
module_path = "prisma"
client_format = "folder"
}

model Settings {
id Int @id @default(0)
theme String @default("dark")
hide_close_prompt Boolean @default(true)
disable_animations Boolean @default(false)
disable_analytics Boolean @default(false)
debug_mode Boolean @default(false)
hide_on_launch Boolean @default(false)
force_fullscreen Boolean @default(false)
disable_discord Boolean @default(false)

custom_java_args String
custom_env_args String

max_async_io_operations Int @default(10)
max_async_fetches Int @default(10)

resolution_x Int @default(854)
resolution_y Int @default(480)

memory_max Int @default(2048)
memory_min Int @default(1024)

hook_pre String?
hook_wrapper String?
hook_post String?

@@map("settings")
}

model JavaVersion {
major_version Int @id
full_version String
architecture String
path String

@@map("java_version")
}

model MinecraftUser {
uuid String @id
active Boolean @default(false)
username String
access_token String
refresh_token String
expires Int

@@unique([active])
@@map("minecraft_user")
}

model MinecraftDeviceToken {
id Int @id @default(0)
uuid String
private_key String
x String
y String
issue_instant Int
not_after Int
token String
display_claims String

@@map("minecraft_device_token")
}

model Cache {
id String @id
data_type String
alias String?
data String?
expires DateTime
created DateTime @default(now())

@@unique([data_type, alias])
@@map("cache")
}

model Cluster {
path String @id
stage String
name String
icon_path String?

mc_version String
loader String @default("vanilla")
loader_version String? @default("stable")

groups String

created_at DateTime @default(now())
modified_at DateTime
played_at DateTime?

overall_played Int @default(0)
recently_played Int @default(0)

override_java_path String?
override_custom_java_args String
override_custom_env_args String
override_memory_max Int?
override_memory_min Int?
override_force_fullscreen Int?
override_resolution_x Int?
override_resolution_y Int?
override_hook_pre String?
override_hook_wrapper String?
override_hook_post String?

processes Process[]

@@map("cluster")
}

model Process {
pid Int @id
start_time DateTime @default(now())
name String
executable String
cluster_path String
post_exit String?

cluster Cluster @relation(fields: [cluster_path], references: [path])

@@unique([pid])
@@index([cluster_path])
@@map("process")
}
13 changes: 13 additions & 0 deletions crates/prisma-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "prisma-cli"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }

[dependencies]
prisma-client-rust-cli = { workspace = true }
3 changes: 3 additions & 0 deletions crates/prisma-cli/src/bin/prisma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
prisma_client_rust_cli::run();
}
16 changes: 16 additions & 0 deletions crates/prisma/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "onelauncher_prisma"
version = { workspace = true }
license = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
documentation = { workspace = true }
readme = { workspace = true }
homepage = { workspace = true }
authors = { workspace = true }

[dependencies]
prisma-client-rust = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
uuid = { workspace = true }
3 changes: 3 additions & 0 deletions crates/prisma/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#![recursion_limit = "256"]
#[allow(warnings, unused)]
pub mod prisma;
6 changes: 3 additions & 3 deletions crates/testing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ async fn launch_and_authenticate() -> onelauncher::Result<()> {
}
}

let name = "examplecluster".to_string();
let game = "1.20.4".to_string();
let loader = Loader::Vanilla;
let name = "Example".to_string();
let game = "1.21".to_string();
let loader = Loader::Fabric;
let loader_version = "stable".to_string();

let cluster = create_cluster(
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@
"format": "pnpm lint:fix && cargo +nightly fmt",
"lint": "pnpm eslint . --cache",
"lint:fix": "pnpm lint --fix",
"format": "pnpm lint:fix && pnpm core:prisma format",
"prep": "pnpm gen:prisma",
"release:node": "pnpm bumpp -r",
"core": "cd crates/core && cargo"
"core": "cd crates/core && cargo",
"gen:prisma": "pnpm core prisma generate",
"gen:migrations": "pnpm core prisma migrate dev",
"gen:code": "pnpm core test gen"
},
"devDependencies": {
"@flowr/eslint-config": "^3.10.0",
Expand Down