feat: add new snapshot for version 6 with updated schema and relationships
All checks were successful
Build Docker Image / build (push) Successful in 1m23s
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:
15
drizzle/0005_large_jane_foster.sql
Normal file
15
drizzle/0005_large_jane_foster.sql
Normal 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;
|
||||||
1
drizzle/0006_premium_mesmero.sql
Normal file
1
drizzle/0006_premium_mesmero.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CREATE UNIQUE INDEX `userCharacterHistory_userId_characterHistoryId_unique` ON `userCharacterHistory` (`userId`,`characterHistoryId`);
|
||||||
1166
drizzle/meta/0005_snapshot.json
Normal file
1166
drizzle/meta/0005_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1173
drizzle/meta/0006_snapshot.json
Normal file
1173
drizzle/meta/0006_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,20 @@
|
|||||||
"when": 1772480377099,
|
"when": 1772480377099,
|
||||||
"tag": "0004_unique_lorna_dane",
|
"tag": "0004_unique_lorna_dane",
|
||||||
"breakpoints": true
|
"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
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -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';
|
import { user } from './auth.schema';
|
||||||
|
|
||||||
// Define devil fruit types
|
// Define devil fruit types
|
||||||
@@ -116,7 +116,9 @@ export const userCharacterHistory = sqliteTable('userCharacterHistory', {
|
|||||||
characterHistoryId: text('characterHistoryId').references(() => characterHistory.id),
|
characterHistoryId: text('characterHistoryId').references(() => characterHistory.id),
|
||||||
tryCount: integer('tryCount').notNull(),
|
tryCount: integer('tryCount').notNull(),
|
||||||
createdAt: integer('createdAt').notNull().$default(() => Date.now())
|
createdAt: integer('createdAt').notNull().$default(() => Date.now())
|
||||||
});
|
}, (table) => [
|
||||||
|
unique().on(table.userId, table.characterHistoryId)
|
||||||
|
]);
|
||||||
|
|
||||||
|
|
||||||
export * from './auth.schema';
|
export * from './auth.schema';
|
||||||
|
|||||||
@@ -109,7 +109,8 @@
|
|||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
characterId: dailyCharacter.id
|
characterId: dailyCharacter.id,
|
||||||
|
tryCount: selectedCharacters.length
|
||||||
})
|
})
|
||||||
}).catch(err => console.error('Failed to record win:', err));
|
}).catch(err => console.error('Failed to record win:', err));
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
import { db } from '$lib/server/db';
|
import { db } from '$lib/server/db';
|
||||||
import { characterHistory } from '$lib/server/db/schema';
|
import { characterHistory, userCharacterHistory } from '$lib/server/db/schema';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq, and } from 'drizzle-orm';
|
||||||
import { sql } from 'drizzle-orm';
|
import { sql } from 'drizzle-orm';
|
||||||
import { getDateKey } from '$lib/server/daily-character';
|
import { getDateKey } from '$lib/server/daily-character';
|
||||||
|
|
||||||
export async function POST({ request }) {
|
export async function POST({ request, locals }) {
|
||||||
try {
|
try {
|
||||||
const { characterId } = await request.json();
|
const { characterId, tryCount } = await request.json();
|
||||||
|
|
||||||
if (!characterId) {
|
if (!characterId) {
|
||||||
return json({ error: 'Missing characterId' }, { status: 400 });
|
return json({ error: 'Missing characterId' }, { status: 400 });
|
||||||
@@ -15,6 +15,29 @@ export async function POST({ request }) {
|
|||||||
|
|
||||||
const todayDate = getDateKey(new Date());
|
const todayDate = getDateKey(new Date());
|
||||||
|
|
||||||
|
// 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
|
// Increment the won counter for today's entry
|
||||||
await db
|
await db
|
||||||
.update(characterHistory)
|
.update(characterHistory)
|
||||||
@@ -24,6 +47,24 @@ export async function POST({ request }) {
|
|||||||
})
|
})
|
||||||
.where(eq(characterHistory.date, todayDate));
|
.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 });
|
return json({ success: true });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error recording win:', error);
|
console.error('Error recording win:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user