5import { runMigrations } from "../db/migrations.ts";
6
7// Step 1: Initialize the database
8console.log("Initializing database...");
9const migrationResult = await runMigrations();
10if (!migrationResult.success) {
11 console.error("Database migration failed:", migrationResult.error);
12 Deno.exit(1);
13}
14console.log("Database initialized successfully");
15
16// Step 2: Create test data
1/**
2 * Initialize the database and create a test app
3 * Run this script to set up the initial database for local testing
4 */
5
6import { initializeDatabase } from "../db/init.ts";
7import { createApp } from "../db/queries.ts";
8import { generateApiKey } from "../utils/apiKey.ts";
9
10async function main() {
11 console.log("Initializing database...");
12 const initResult = await initializeDatabase();
13
14 if (!initResult.success) {
15 console.error("Failed to initialize database:", initResult.error);
16 return;
17 }
18
19 console.log("Database initialized successfully");
20
21 // Create a test app
25
26 try {
27 // Get all apps from the database
28 const apps = await getAllApps();
29
44 }
45
46 // Delete the app from the database
47 const deleted = await deleteApp(appId);
48
39 const apiKey = generateApiKey();
40
41 // Create the app in the database
42 const app = await createApp({
43 name: validation.data.name!,
50
51 /**
52 * Create the feedback in the database with the following fields:
53 *
54 * Basic fields:
1/**
2 * Database migrations for productpanel
3 * Handles schema updates and migrations
4 */
63
64/**
65 * Check if a table exists in the database
66 */
67async function checkTableExists(tableName: string): Promise<boolean> {
1/**
2 * Database initialization for productpanel
3 * Creates required tables if they don't exist
4 */
8
9/**
10 * Initialize the database by creating required tables
11 * Only needs to be run once when the app starts
12 */
13export async function initializeDatabase() {
14 try {
15 // Create apps table
23 return { success: true };
24 } catch (error) {
25 console.error("Error initializing database:", error);
26 return {
27 success: false,
32
33/**
34 * Reset database (for development use only)
35 * Drops existing tables and recreates them
36 */
37export async function resetDatabase() {
38 try {
39 // Drop tables if they exist (reverse order due to foreign key)
42
43 // Recreate tables
44 return await initializeDatabase();
45 } catch (error) {
46 console.error("Error resetting database:", error);
47 return {
48 success: false,
1/**
2 * Database schema for productpanel
3 * Contains table definitions for apps and feedback
4 */
27
28/**
29 * Validate an API key against the database
30 * @param apiKey The API key to validate
31 * @returns The app object if valid, null if invalid
36 }
37
38 // Check if the API key exists in the database
39 const app = await getAppByApiKey(apiKey);
40 return app;