feat: add new snapshot for version 6 with updated schema and relationships
All checks were successful
Build Docker Image / build (push) Successful in 1m23s

- Created a new snapshot file for version 6 of the database schema.
- Added tables for arc, character, characterHistory, characterOverride, characterScrapeValidation, config, devilFruit, userCharacterHistory, account, session, user, and verification with appropriate columns and constraints.
- Updated the journal to include new entries for version 6.
- Modified the userCharacterHistory table to enforce unique constraints on userId and characterHistoryId.
- Enhanced daily game logic to track user attempts and prevent duplicate entries for the same day.
This commit is contained in:
2026-03-03 19:31:10 +01:00
parent bfc6d76dfe
commit 085dae6765
8 changed files with 2428 additions and 15 deletions

View File

@@ -0,0 +1,15 @@
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_userCharacterHistory` (
`id` text PRIMARY KEY NOT NULL,
`userId` text,
`characterHistoryId` text,
`tryCount` integer NOT NULL,
`createdAt` integer NOT NULL,
FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`characterHistoryId`) REFERENCES `characterHistory`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
INSERT INTO `__new_userCharacterHistory`("id", "userId", "characterHistoryId", "tryCount", "createdAt") SELECT "id", "userId", "characterId", "tryCount", "createdAt" FROM `userCharacterHistory`;--> statement-breakpoint
DROP TABLE `userCharacterHistory`;--> statement-breakpoint
ALTER TABLE `__new_userCharacterHistory` RENAME TO `userCharacterHistory`;--> statement-breakpoint
PRAGMA foreign_keys=ON;

View File

@@ -0,0 +1 @@
CREATE UNIQUE INDEX `userCharacterHistory_userId_characterHistoryId_unique` ON `userCharacterHistory` (`userId`,`characterHistoryId`);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -36,6 +36,20 @@
"when": 1772480377099,
"tag": "0004_unique_lorna_dane",
"breakpoints": true
},
{
"idx": 5,
"version": "6",
"when": 1772562012631,
"tag": "0005_large_jane_foster",
"breakpoints": true
},
{
"idx": 6,
"version": "6",
"when": 1772562364830,
"tag": "0006_premium_mesmero",
"breakpoints": true
}
]
}

View File

@@ -1,4 +1,4 @@
import { integer, sqliteTable, text, real } from 'drizzle-orm/sqlite-core';
import { integer, sqliteTable, text, real, unique } from 'drizzle-orm/sqlite-core';
import { user } from './auth.schema';
// Define devil fruit types
@@ -116,7 +116,9 @@ export const userCharacterHistory = sqliteTable('userCharacterHistory', {
characterHistoryId: text('characterHistoryId').references(() => characterHistory.id),
tryCount: integer('tryCount').notNull(),
createdAt: integer('createdAt').notNull().$default(() => Date.now())
});
}, (table) => [
unique().on(table.userId, table.characterHistoryId)
]);
export * from './auth.schema';

View File

@@ -109,7 +109,8 @@
'Content-Type': 'application/json'
},
body: JSON.stringify({
characterId: dailyCharacter.id
characterId: dailyCharacter.id,
tryCount: selectedCharacters.length
})
}).catch(err => console.error('Failed to record win:', err));

View File

@@ -1,13 +1,13 @@
import { json } from '@sveltejs/kit';
import { db } from '$lib/server/db';
import { characterHistory } from '$lib/server/db/schema';
import { eq } from 'drizzle-orm';
import { characterHistory, userCharacterHistory } from '$lib/server/db/schema';
import { eq, and } from 'drizzle-orm';
import { sql } from 'drizzle-orm';
import { getDateKey } from '$lib/server/daily-character';
export async function POST({ request }) {
export async function POST({ request, locals }) {
try {
const { characterId } = await request.json();
const { characterId, tryCount } = await request.json();
if (!characterId) {
return json({ error: 'Missing characterId' }, { status: 400 });
@@ -15,14 +15,55 @@ export async function POST({ request }) {
const todayDate = getDateKey(new Date());
// Increment the won counter for today's entry
await db
.update(characterHistory)
.set({
won: sql`${characterHistory.won} + 1`,
updatedAt: Date.now()
})
.where(eq(characterHistory.date, todayDate));
// If user is logged in, check if they already played today
if (locals.user) {
// Get the characterHistoryId for today
const [todayHistoryEntry] = await db
.select({ id: characterHistory.id })
.from(characterHistory)
.where(eq(characterHistory.date, todayDate));
if (todayHistoryEntry) {
// Check if user already has a record for today
const [existingRecord] = await db
.select()
.from(userCharacterHistory)
.where(and(
eq(userCharacterHistory.userId, locals.user.id),
eq(userCharacterHistory.characterHistoryId, todayHistoryEntry.id)
));
// If user already played today, don't record again
if (existingRecord) {
return json({ success: false, message: 'Already played today' });
}
// Increment the won counter for today's entry
await db
.update(characterHistory)
.set({
won: sql`${characterHistory.won} + 1`,
updatedAt: Date.now()
})
.where(eq(characterHistory.date, todayDate));
// Insert into userCharacterHistory
await db.insert(userCharacterHistory).values({
userId: locals.user.id,
characterHistoryId: todayHistoryEntry.id,
tryCount: tryCount
});
}
} else {
// If user is not logged in, always increment counter
await db
.update(characterHistory)
.set({
won: sql`${characterHistory.won} + 1`,
updatedAt: Date.now()
})
.where(eq(characterHistory.date, todayDate));
}
return json({ success: true });
} catch (error) {