Change database a bit

This commit is contained in:
2025-12-20 21:29:57 -07:00
parent 3e682afb61
commit 3057d2ad80
4 changed files with 84 additions and 36 deletions

View File

@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Dec 20, 2025 at 10:45 PM
-- Generation Time: Dec 21, 2025 at 04:23 AM
-- Server version: 12.1.2-MariaDB
-- PHP Version: 8.5.1
@@ -24,16 +24,15 @@ SET time_zone = "+00:00";
-- --------------------------------------------------------
--
-- Table structure for table `launchergames`
-- Table structure for table `games`
--
CREATE TABLE `launchergames` (
CREATE TABLE `games` (
`id` int(11) NOT NULL,
`name` text NOT NULL,
`official` tinyint(1) NOT NULL DEFAULT 0,
`verified` tinyint(1) NOT NULL DEFAULT 0,
`developer` varchar(32) DEFAULT NULL,
`cutOff` int(11) DEFAULT NULL
`developer` varchar(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
-- --------------------------------------------------------
@@ -55,10 +54,10 @@ CREATE TABLE `launcherupdates` (
-- --------------------------------------------------------
--
-- Table structure for table `launcherversions`
-- Table structure for table `launcherversionmanifest`
--
CREATE TABLE `launcherversions` (
CREATE TABLE `launcherversionmanifest` (
`id` varchar(24) NOT NULL,
`versionName` text NOT NULL,
`releaseDate` bigint(20) NOT NULL,
@@ -74,6 +73,19 @@ CREATE TABLE `launcherversions` (
-- --------------------------------------------------------
--
-- Table structure for table `loaderupdates`
--
CREATE TABLE `loaderupdates` (
`id` varchar(24) NOT NULL,
`releaseDate` bigint(20) NOT NULL,
`hidden` tinyint(1) NOT NULL DEFAULT 1,
`place` int(11) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=COMPRESSED;
-- --------------------------------------------------------
--
-- Table structure for table `users`
--
@@ -93,9 +105,9 @@ CREATE TABLE `users` (
--
--
-- Indexes for table `launchergames`
-- Indexes for table `games`
--
ALTER TABLE `launchergames`
ALTER TABLE `games`
ADD PRIMARY KEY (`id`);
--
@@ -105,12 +117,18 @@ ALTER TABLE `launcherupdates`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `launcherversions`
-- Indexes for table `launcherversionmanifest`
--
ALTER TABLE `launcherversions`
ALTER TABLE `launcherversionmanifest`
ADD PRIMARY KEY (`id`),
ADD KEY `fk_game` (`game`);
--
-- Indexes for table `loaderupdates`
--
ALTER TABLE `loaderupdates`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `users`
--
@@ -122,9 +140,9 @@ ALTER TABLE `users`
--
--
-- AUTO_INCREMENT for table `launchergames`
-- AUTO_INCREMENT for table `games`
--
ALTER TABLE `launchergames`
ALTER TABLE `games`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
--
@@ -138,10 +156,10 @@ ALTER TABLE `users`
--
--
-- Constraints for table `launcherversions`
-- Constraints for table `launcherversionmanifest`
--
ALTER TABLE `launcherversions`
ADD CONSTRAINT `fk_category` FOREIGN KEY (`game`) REFERENCES `launchergames` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
ALTER TABLE `launcherversionmanifest`
ADD CONSTRAINT `fk_category` FOREIGN KEY (`game`) REFERENCES `games` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

View File

@@ -32,7 +32,14 @@ export const launcherUpdates = mysqlTable('launcherupdates', {
sha512sums: text('sha512sums').default('[]').notNull()
})
export const launcherGames = mysqlTable('launchergames', {
export const loaderUpdates = mysqlTable('loaderupdates', {
id: varchar('id', { length: 24 }).primaryKey().notNull(),
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
hidden: boolean('hidden').default(false).notNull(),
place: int('place').default(0).notNull()
})
export const games = mysqlTable('games', {
id: int('id').primaryKey().autoincrement().notNull(),
name: text('name').notNull(),
official: boolean('official').default(false).notNull(),
@@ -40,7 +47,7 @@ export const launcherGames = mysqlTable('launchergames', {
developer: varchar('developer', { length: 32 })
})
export const launcherVersions = mysqlTable('launcherversions', {
export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
id: varchar('id', { length: 24 }).primaryKey().notNull(),
versionName: text('versionName').notNull(),
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
@@ -50,7 +57,7 @@ export const launcherVersions = mysqlTable('launcherversions', {
hidden: boolean('hidden').default(false).notNull(),
game: int('game')
.default(0)
.references(() => launcherGames.id)
.references(() => games.id)
.notNull(),
place: int('place').default(0).notNull(),
sha512sums: text('sha512sums').default('[]').notNull(),

View File

@@ -1,3 +1,23 @@
import { loaderUpdates } from '../../../lib/tables'
import { desc, eq } from 'drizzle-orm'
import { getDatabaseConnection, jsonResponse } from '../../../lib/util'
export async function handler () {
return '1.0.2'
const dbResult = getDatabaseConnection(0)
if (!dbResult)
return jsonResponse({ error: 'Failed to connect to database' }, 500)
const { connection, db } = dbResult
const version = await db
.select({
id: loaderUpdates.id
})
.from(loaderUpdates)
.where(eq(loaderUpdates.hidden, false))
.orderBy(desc(loaderUpdates.place))
.limit(1)
connection.end()
return version[0].id
}

View File

@@ -1,4 +1,4 @@
import { launcherGames, launcherVersions } from '../../lib/tables'
import { games, launcherVersionManifest } from '../../lib/tables'
import { asc, desc, eq } from 'drizzle-orm'
import { getDatabaseConnection, jsonResponse } from '../../lib/util'
import { Context } from 'elysia'
@@ -72,20 +72,23 @@ export async function handler (context: Context) {
const versionsRaw = await db
.select({
id: launcherVersions.id,
versionName: launcherVersions.versionName,
releaseDate: launcherVersions.releaseDate,
game: launcherVersions.game,
downloadUrls: launcherVersions.downloadUrls,
platforms: launcherVersions.platforms,
executables: launcherVersions.executables,
sha512sums: launcherVersions.sha512sums,
sizes: launcherVersions.sizes,
place: launcherVersions.place
id: launcherVersionManifest.id,
versionName: launcherVersionManifest.versionName,
releaseDate: launcherVersionManifest.releaseDate,
game: launcherVersionManifest.game,
downloadUrls: launcherVersionManifest.downloadUrls,
platforms: launcherVersionManifest.platforms,
executables: launcherVersionManifest.executables,
sha512sums: launcherVersionManifest.sha512sums,
sizes: launcherVersionManifest.sizes,
place: launcherVersionManifest.place
})
.from(launcherVersions)
.where(eq(launcherVersions.hidden, false))
.orderBy(asc(launcherVersions.game), desc(launcherVersions.place))
.from(launcherVersionManifest)
.where(eq(launcherVersionManifest.hidden, false))
.orderBy(
asc(launcherVersionManifest.game),
desc(launcherVersionManifest.place)
)
.execute()
const versions = versionsRaw
@@ -125,9 +128,9 @@ export async function handler (context: Context) {
return false
})
const games = await db.select().from(launcherGames).execute()
const gameList = await db.select().from(games).execute()
connection.end()
return jsonResponse({ versions, games })
return jsonResponse({ versions, gameList })
}