after add new toy for sharing, the new toys still not exist in toys tabl

This commit is contained in:
Indigo Tang 2025-07-06 13:59:18 +00:00
parent 276db4fa31
commit c74edf7397
5 changed files with 71 additions and 69 deletions

View File

@ -6,7 +6,8 @@ import { createToy, updateToy, getToyById } from '@/data/operations';
import type { Toy } from '@/types'; import type { Toy } from '@/types';
// This type represents the data coming from the form. // This type represents the data coming from the form.
export type ToyFormData = Omit<Toy, 'id' | 'ownerId' | 'name' | 'description' | 'category' | 'images' | 'unavailableRanges' | 'pricePerDay' | 'location' | 'ownerName' | 'ownerAvatarUrl' | 'dataAiHint'> & { // Simplified for clarity and maintainability.
export type ToyFormData = {
name: string; name: string;
description: string; description: string;
category: string; category: string;

View File

@ -15,13 +15,11 @@ db.pragma('journal_mode = WAL');
db.pragma('foreign_keys = ON'); db.pragma('foreign_keys = ON');
function initDb() { function initDb() {
console.log("Resetting database and re-seeding data..."); // Check if the users table exists. If it does, we assume the DB is initialized.
const table = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'users'").get();
// Drop existing tables to ensure a clean slate on every run.
// This is useful for development to easily reset the data.
db.exec('DROP TABLE IF EXISTS toys');
db.exec('DROP TABLE IF EXISTS users');
if (!table) {
console.log("Database not found. Initializing and seeding...");
// Create Users Table // Create Users Table
db.exec(` db.exec(`
@ -90,6 +88,9 @@ function initDb() {
seedData(); seedData();
console.log("Database initialization and seeding complete."); console.log("Database initialization and seeding complete.");
} else {
console.log("Database already initialized.");
}
} }
// Initialize and export db // Initialize and export db

Binary file not shown.

Binary file not shown.

Binary file not shown.