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/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost -- 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 -- Server version: 12.1.2-MariaDB
-- PHP Version: 8.5.1 -- 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, `id` int(11) NOT NULL,
`name` text NOT NULL, `name` text NOT NULL,
`official` tinyint(1) NOT NULL DEFAULT 0, `official` tinyint(1) NOT NULL DEFAULT 0,
`verified` tinyint(1) NOT NULL DEFAULT 0, `verified` tinyint(1) NOT NULL DEFAULT 0,
`developer` varchar(32) DEFAULT NULL, `developer` varchar(32) DEFAULT NULL
`cutOff` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; ) 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, `id` varchar(24) NOT NULL,
`versionName` text NOT NULL, `versionName` text NOT NULL,
`releaseDate` bigint(20) 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` -- 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`); ADD PRIMARY KEY (`id`);
-- --
@@ -105,12 +117,18 @@ ALTER TABLE `launcherupdates`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `launcherversions` -- Indexes for table `launcherversionmanifest`
-- --
ALTER TABLE `launcherversions` ALTER TABLE `launcherversionmanifest`
ADD PRIMARY KEY (`id`), ADD PRIMARY KEY (`id`),
ADD KEY `fk_game` (`game`); ADD KEY `fk_game` (`game`);
--
-- Indexes for table `loaderupdates`
--
ALTER TABLE `loaderupdates`
ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `users` -- 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; 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` ALTER TABLE `launcherversionmanifest`
ADD CONSTRAINT `fk_category` FOREIGN KEY (`game`) REFERENCES `launchergames` (`id`) ON DELETE CASCADE ON UPDATE CASCADE; ADD CONSTRAINT `fk_category` FOREIGN KEY (`game`) REFERENCES `games` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
COMMIT; COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!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() 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(), id: int('id').primaryKey().autoincrement().notNull(),
name: text('name').notNull(), name: text('name').notNull(),
official: boolean('official').default(false).notNull(), official: boolean('official').default(false).notNull(),
@@ -40,7 +47,7 @@ export const launcherGames = mysqlTable('launchergames', {
developer: varchar('developer', { length: 32 }) developer: varchar('developer', { length: 32 })
}) })
export const launcherVersions = mysqlTable('launcherversions', { export const launcherVersionManifest = mysqlTable('launcherversionmanifest', {
id: varchar('id', { length: 24 }).primaryKey().notNull(), id: varchar('id', { length: 24 }).primaryKey().notNull(),
versionName: text('versionName').notNull(), versionName: text('versionName').notNull(),
releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(), releaseDate: bigint('releaseDate', { mode: 'number' }).notNull(),
@@ -50,7 +57,7 @@ export const launcherVersions = mysqlTable('launcherversions', {
hidden: boolean('hidden').default(false).notNull(), hidden: boolean('hidden').default(false).notNull(),
game: int('game') game: int('game')
.default(0) .default(0)
.references(() => launcherGames.id) .references(() => games.id)
.notNull(), .notNull(),
place: int('place').default(0).notNull(), place: int('place').default(0).notNull(),
sha512sums: text('sha512sums').default('[]').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 () { 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 { asc, desc, eq } from 'drizzle-orm'
import { getDatabaseConnection, jsonResponse } from '../../lib/util' import { getDatabaseConnection, jsonResponse } from '../../lib/util'
import { Context } from 'elysia' import { Context } from 'elysia'
@@ -72,20 +72,23 @@ export async function handler (context: Context) {
const versionsRaw = await db const versionsRaw = await db
.select({ .select({
id: launcherVersions.id, id: launcherVersionManifest.id,
versionName: launcherVersions.versionName, versionName: launcherVersionManifest.versionName,
releaseDate: launcherVersions.releaseDate, releaseDate: launcherVersionManifest.releaseDate,
game: launcherVersions.game, game: launcherVersionManifest.game,
downloadUrls: launcherVersions.downloadUrls, downloadUrls: launcherVersionManifest.downloadUrls,
platforms: launcherVersions.platforms, platforms: launcherVersionManifest.platforms,
executables: launcherVersions.executables, executables: launcherVersionManifest.executables,
sha512sums: launcherVersions.sha512sums, sha512sums: launcherVersionManifest.sha512sums,
sizes: launcherVersions.sizes, sizes: launcherVersionManifest.sizes,
place: launcherVersions.place place: launcherVersionManifest.place
}) })
.from(launcherVersions) .from(launcherVersionManifest)
.where(eq(launcherVersions.hidden, false)) .where(eq(launcherVersionManifest.hidden, false))
.orderBy(asc(launcherVersions.game), desc(launcherVersions.place)) .orderBy(
asc(launcherVersionManifest.game),
desc(launcherVersionManifest.place)
)
.execute() .execute()
const versions = versionsRaw const versions = versionsRaw
@@ -125,9 +128,9 @@ export async function handler (context: Context) {
return false return false
}) })
const games = await db.select().from(launcherGames).execute() const gameList = await db.select().from(games).execute()
connection.end() connection.end()
return jsonResponse({ versions, games }) return jsonResponse({ versions, gameList })
} }