sitepaige-mcp-server 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/defaultapp/db-mysql.ts +7 -17
- package/defaultapp/db-postgres.ts +9 -12
- package/defaultapp/db-sqlite.ts +12 -11
- package/defaultapp/db.ts +5 -5
- package/defaultapp/migrate.ts +17 -13
- package/dist/defaultapp/db-mysql.ts +7 -17
- package/dist/defaultapp/db-postgres.ts +9 -12
- package/dist/defaultapp/db-sqlite.ts +12 -11
- package/dist/defaultapp/db.ts +5 -5
- package/dist/defaultapp/migrate.ts +17 -13
- package/dist/generators/db-template.txt +6 -4
- package/dist/generators/env-example-template.txt +2 -1
- package/package.json +1 -1
package/defaultapp/db-mysql.ts
CHANGED
|
@@ -5,7 +5,7 @@ WARNING: This file is automatically generated and should not be modified.
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import mysql from 'mysql2/promise';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Model, ModelField } from './db';
|
|
9
9
|
|
|
10
10
|
// Connection pool for better performance
|
|
11
11
|
let pool: mysql.Pool | null = null;
|
|
@@ -14,7 +14,7 @@ let pool: mysql.Pool | null = null;
|
|
|
14
14
|
* Initialize database connection
|
|
15
15
|
* @returns Database client (Pool)
|
|
16
16
|
*/
|
|
17
|
-
export async function db_init(
|
|
17
|
+
export async function db_init(): Promise<mysql.Pool> {
|
|
18
18
|
// Skip database initialization during build time
|
|
19
19
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
20
20
|
// Return a mock pool object that won't cause errors
|
|
@@ -29,11 +29,11 @@ export async function db_init(config: DatabaseConfig): Promise<mysql.Pool> {
|
|
|
29
29
|
try {
|
|
30
30
|
// Create connection configuration
|
|
31
31
|
const poolConfig: mysql.PoolOptions = {
|
|
32
|
-
host:
|
|
33
|
-
port:
|
|
34
|
-
user:
|
|
35
|
-
password:
|
|
36
|
-
database:
|
|
32
|
+
host: process.env.DB_HOST || 'localhost',
|
|
33
|
+
port: parseInt(process.env.DB_PORT || '3306'),
|
|
34
|
+
user: process.env.DB_USER || 'root',
|
|
35
|
+
password: process.env.DB_PASSWORD,
|
|
36
|
+
database: process.env.DB_NAME || 'app',
|
|
37
37
|
waitForConnections: true,
|
|
38
38
|
connectionLimit: 20,
|
|
39
39
|
queueLimit: 0,
|
|
@@ -41,16 +41,6 @@ export async function db_init(config: DatabaseConfig): Promise<mysql.Pool> {
|
|
|
41
41
|
keepAliveInitialDelay: 0
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
// Use connection string if provided
|
|
45
|
-
if (config.connectionString) {
|
|
46
|
-
const url = new URL(config.connectionString);
|
|
47
|
-
poolConfig.host = url.hostname;
|
|
48
|
-
poolConfig.port = parseInt(url.port || '3306');
|
|
49
|
-
poolConfig.user = url.username;
|
|
50
|
-
poolConfig.password = url.password;
|
|
51
|
-
poolConfig.database = url.pathname.substring(1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
44
|
// Create the pool
|
|
55
45
|
pool = mysql.createPool(poolConfig);
|
|
56
46
|
|
|
@@ -5,7 +5,7 @@ WARNING: This file is automatically generated and should not be modified.
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { Client, Pool } from 'pg';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Model, ModelField } from './db';
|
|
9
9
|
|
|
10
10
|
// Connection pool for better performance
|
|
11
11
|
let pool: Pool | null = null;
|
|
@@ -14,7 +14,7 @@ let pool: Pool | null = null;
|
|
|
14
14
|
* Initialize database connection
|
|
15
15
|
* @returns Database client (Pool)
|
|
16
16
|
*/
|
|
17
|
-
export async function db_init(
|
|
17
|
+
export async function db_init(): Promise<Pool> {
|
|
18
18
|
// Skip database initialization during build time
|
|
19
19
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
20
20
|
// Return a mock pool object that won't cause errors
|
|
@@ -30,19 +30,16 @@ export async function db_init(config: DatabaseConfig): Promise<Pool> {
|
|
|
30
30
|
// Create connection configuration
|
|
31
31
|
const poolConfig: any = {};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
poolConfig.password = config.password;
|
|
40
|
-
poolConfig.database = config.database;
|
|
41
|
-
}
|
|
33
|
+
// Read configuration from environment variables
|
|
34
|
+
poolConfig.host = process.env.DB_HOST || 'localhost';
|
|
35
|
+
poolConfig.port = parseInt(process.env.DB_PORT || '5432');
|
|
36
|
+
poolConfig.user = process.env.DB_USER || 'postgres';
|
|
37
|
+
poolConfig.password = process.env.DB_PASSWORD;
|
|
38
|
+
poolConfig.database = process.env.DB_NAME || 'app';
|
|
42
39
|
|
|
43
40
|
// SSL configuration for secure connections (e.g., AWS RDS)
|
|
44
41
|
// Always enable SSL for PostgreSQL connections
|
|
45
|
-
poolConfig.ssl =
|
|
42
|
+
poolConfig.ssl = {
|
|
46
43
|
rejectUnauthorized: false, // For self-signed certificates
|
|
47
44
|
require: true // Equivalent to sslmode=require
|
|
48
45
|
};
|
package/defaultapp/db-sqlite.ts
CHANGED
|
@@ -8,7 +8,7 @@ import Database from 'better-sqlite3';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import { promises as fsPromises } from 'fs';
|
|
11
|
-
import type {
|
|
11
|
+
import type { Model, ModelField } from './db';
|
|
12
12
|
|
|
13
13
|
// Map to store multiple database connections by path
|
|
14
14
|
const dbConnections: Map<string, Database.Database> = new Map();
|
|
@@ -16,23 +16,24 @@ const dbConnections: Map<string, Database.Database> = new Map();
|
|
|
16
16
|
/**
|
|
17
17
|
* Get the default database path
|
|
18
18
|
*/
|
|
19
|
-
function getDefaultDbPath(
|
|
20
|
-
// First check if DATABASE_URL is provided
|
|
21
|
-
|
|
19
|
+
function getDefaultDbPath(): string {
|
|
20
|
+
// First check if DATABASE_URL is provided
|
|
21
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
22
|
+
if (databaseUrl) {
|
|
22
23
|
// DATABASE_URL can be either a direct file path or a sqlite:// URL
|
|
23
|
-
if (
|
|
24
|
+
if (databaseUrl.startsWith('sqlite://')) {
|
|
24
25
|
// Remove the sqlite:// prefix and return the path
|
|
25
|
-
return
|
|
26
|
+
return databaseUrl.slice(9);
|
|
26
27
|
} else {
|
|
27
28
|
// Assume it's a direct file path
|
|
28
|
-
return
|
|
29
|
+
return databaseUrl;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
// Use EFS_MOUNT_PATH for production (in container with EFS)
|
|
33
34
|
// Use SQLITE_DIR for local development
|
|
34
|
-
const efsMountPath =
|
|
35
|
-
const sqliteDir =
|
|
35
|
+
const efsMountPath = process.env.EFS_MOUNT_PATH;
|
|
36
|
+
const sqliteDir = process.env.SQLITE_DIR || '.';
|
|
36
37
|
|
|
37
38
|
if (efsMountPath) {
|
|
38
39
|
// In production with EFS
|
|
@@ -50,7 +51,7 @@ function getDefaultDbPath(config: DatabaseConfig): string {
|
|
|
50
51
|
* If the file doesn't exist, it will be created automatically.
|
|
51
52
|
* @returns Database client
|
|
52
53
|
*/
|
|
53
|
-
export async function db_init(
|
|
54
|
+
export async function db_init(): Promise<Database.Database> {
|
|
54
55
|
// Skip database initialization during build time
|
|
55
56
|
// Check if we're in a build environment by detecting the absence of runtime variables
|
|
56
57
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
@@ -59,7 +60,7 @@ export async function db_init(config: DatabaseConfig): Promise<Database.Database
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// Always use the default path - no parameter needed
|
|
62
|
-
const actualPath = getDefaultDbPath(
|
|
63
|
+
const actualPath = getDefaultDbPath();
|
|
63
64
|
|
|
64
65
|
// Check if we already have a connection to this database
|
|
65
66
|
const existingConnection = dbConnections.get(actualPath);
|
package/defaultapp/db.ts
CHANGED
|
@@ -112,13 +112,13 @@ async function loadDatabaseImplementation(dbType: DatabaseType) {
|
|
|
112
112
|
* @returns Database client
|
|
113
113
|
*/
|
|
114
114
|
export async function db_init(): Promise<DatabaseClient> {
|
|
115
|
-
const
|
|
115
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
116
116
|
|
|
117
117
|
if (!dbImplementation) {
|
|
118
|
-
await loadDatabaseImplementation(
|
|
118
|
+
await loadDatabaseImplementation(dbType);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
return dbImplementation.db_init(
|
|
121
|
+
return dbImplementation.db_init();
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -142,8 +142,8 @@ export async function db_query(
|
|
|
142
142
|
* @returns SQL string for creating the table
|
|
143
143
|
*/
|
|
144
144
|
export function db_migrate(model: Model): string {
|
|
145
|
-
const
|
|
146
|
-
return dbImplementation.db_migrate(model,
|
|
145
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
146
|
+
return dbImplementation.db_migrate(model, dbType);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
package/defaultapp/migrate.ts
CHANGED
|
@@ -7,34 +7,38 @@ This script initializes the database and runs all migrations
|
|
|
7
7
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import { db_init, db_query
|
|
10
|
+
import { db_init, db_query } from './db';
|
|
11
11
|
|
|
12
12
|
async function runMigrations() {
|
|
13
13
|
console.log('🚀 Starting database migration...');
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
|
-
// Get database
|
|
17
|
-
const
|
|
16
|
+
// Get database type from environment
|
|
17
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase();
|
|
18
18
|
|
|
19
|
-
if (
|
|
20
|
-
console.log(`⚠️ Migration runner currently only supports SQLite. Detected: ${
|
|
19
|
+
if (dbType !== 'sqlite') {
|
|
20
|
+
console.log(`⚠️ Migration runner currently only supports SQLite. Detected: ${dbType}`);
|
|
21
21
|
console.log('Please run your database migrations manually.');
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Display database path for SQLite
|
|
26
26
|
let dbPath: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
28
|
+
const efsMountPath = process.env.EFS_MOUNT_PATH;
|
|
29
|
+
const sqliteDir = process.env.SQLITE_DIR || '.';
|
|
30
|
+
|
|
31
|
+
if (databaseUrl) {
|
|
32
|
+
dbPath = databaseUrl.startsWith('sqlite://')
|
|
33
|
+
? databaseUrl.slice(9)
|
|
34
|
+
: databaseUrl;
|
|
31
35
|
console.log(`📁 Database location: ${dbPath} (from DATABASE_URL)`);
|
|
32
|
-
} else if (
|
|
33
|
-
dbPath = path.join(
|
|
36
|
+
} else if (efsMountPath) {
|
|
37
|
+
dbPath = path.join(efsMountPath, 'data', 'app.db');
|
|
34
38
|
console.log(`📁 Database location: ${dbPath} (from EFS_MOUNT_PATH)`);
|
|
35
39
|
} else {
|
|
36
|
-
dbPath = path.join(
|
|
37
|
-
console.log(`📁 Database location: ${dbPath} (default: ${
|
|
40
|
+
dbPath = path.join(sqliteDir, 'app.db');
|
|
41
|
+
console.log(`📁 Database location: ${dbPath} (default: ${sqliteDir !== '.' ? 'SQLITE_DIR' : 'current directory'})`);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
// Initialize database connection
|
|
@@ -5,7 +5,7 @@ WARNING: This file is automatically generated and should not be modified.
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import mysql from 'mysql2/promise';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Model, ModelField } from './db';
|
|
9
9
|
|
|
10
10
|
// Connection pool for better performance
|
|
11
11
|
let pool: mysql.Pool | null = null;
|
|
@@ -14,7 +14,7 @@ let pool: mysql.Pool | null = null;
|
|
|
14
14
|
* Initialize database connection
|
|
15
15
|
* @returns Database client (Pool)
|
|
16
16
|
*/
|
|
17
|
-
export async function db_init(
|
|
17
|
+
export async function db_init(): Promise<mysql.Pool> {
|
|
18
18
|
// Skip database initialization during build time
|
|
19
19
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
20
20
|
// Return a mock pool object that won't cause errors
|
|
@@ -29,11 +29,11 @@ export async function db_init(config: DatabaseConfig): Promise<mysql.Pool> {
|
|
|
29
29
|
try {
|
|
30
30
|
// Create connection configuration
|
|
31
31
|
const poolConfig: mysql.PoolOptions = {
|
|
32
|
-
host:
|
|
33
|
-
port:
|
|
34
|
-
user:
|
|
35
|
-
password:
|
|
36
|
-
database:
|
|
32
|
+
host: process.env.DB_HOST || 'localhost',
|
|
33
|
+
port: parseInt(process.env.DB_PORT || '3306'),
|
|
34
|
+
user: process.env.DB_USER || 'root',
|
|
35
|
+
password: process.env.DB_PASSWORD,
|
|
36
|
+
database: process.env.DB_NAME || 'app',
|
|
37
37
|
waitForConnections: true,
|
|
38
38
|
connectionLimit: 20,
|
|
39
39
|
queueLimit: 0,
|
|
@@ -41,16 +41,6 @@ export async function db_init(config: DatabaseConfig): Promise<mysql.Pool> {
|
|
|
41
41
|
keepAliveInitialDelay: 0
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
// Use connection string if provided
|
|
45
|
-
if (config.connectionString) {
|
|
46
|
-
const url = new URL(config.connectionString);
|
|
47
|
-
poolConfig.host = url.hostname;
|
|
48
|
-
poolConfig.port = parseInt(url.port || '3306');
|
|
49
|
-
poolConfig.user = url.username;
|
|
50
|
-
poolConfig.password = url.password;
|
|
51
|
-
poolConfig.database = url.pathname.substring(1);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
44
|
// Create the pool
|
|
55
45
|
pool = mysql.createPool(poolConfig);
|
|
56
46
|
|
|
@@ -5,7 +5,7 @@ WARNING: This file is automatically generated and should not be modified.
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { Client, Pool } from 'pg';
|
|
8
|
-
import type {
|
|
8
|
+
import type { Model, ModelField } from './db';
|
|
9
9
|
|
|
10
10
|
// Connection pool for better performance
|
|
11
11
|
let pool: Pool | null = null;
|
|
@@ -14,7 +14,7 @@ let pool: Pool | null = null;
|
|
|
14
14
|
* Initialize database connection
|
|
15
15
|
* @returns Database client (Pool)
|
|
16
16
|
*/
|
|
17
|
-
export async function db_init(
|
|
17
|
+
export async function db_init(): Promise<Pool> {
|
|
18
18
|
// Skip database initialization during build time
|
|
19
19
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
20
20
|
// Return a mock pool object that won't cause errors
|
|
@@ -30,19 +30,16 @@ export async function db_init(config: DatabaseConfig): Promise<Pool> {
|
|
|
30
30
|
// Create connection configuration
|
|
31
31
|
const poolConfig: any = {};
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
poolConfig.password = config.password;
|
|
40
|
-
poolConfig.database = config.database;
|
|
41
|
-
}
|
|
33
|
+
// Read configuration from environment variables
|
|
34
|
+
poolConfig.host = process.env.DB_HOST || 'localhost';
|
|
35
|
+
poolConfig.port = parseInt(process.env.DB_PORT || '5432');
|
|
36
|
+
poolConfig.user = process.env.DB_USER || 'postgres';
|
|
37
|
+
poolConfig.password = process.env.DB_PASSWORD;
|
|
38
|
+
poolConfig.database = process.env.DB_NAME || 'app';
|
|
42
39
|
|
|
43
40
|
// SSL configuration for secure connections (e.g., AWS RDS)
|
|
44
41
|
// Always enable SSL for PostgreSQL connections
|
|
45
|
-
poolConfig.ssl =
|
|
42
|
+
poolConfig.ssl = {
|
|
46
43
|
rejectUnauthorized: false, // For self-signed certificates
|
|
47
44
|
require: true // Equivalent to sslmode=require
|
|
48
45
|
};
|
|
@@ -8,7 +8,7 @@ import Database from 'better-sqlite3';
|
|
|
8
8
|
import * as path from 'path';
|
|
9
9
|
import * as fs from 'fs';
|
|
10
10
|
import { promises as fsPromises } from 'fs';
|
|
11
|
-
import type {
|
|
11
|
+
import type { Model, ModelField } from './db';
|
|
12
12
|
|
|
13
13
|
// Map to store multiple database connections by path
|
|
14
14
|
const dbConnections: Map<string, Database.Database> = new Map();
|
|
@@ -16,23 +16,24 @@ const dbConnections: Map<string, Database.Database> = new Map();
|
|
|
16
16
|
/**
|
|
17
17
|
* Get the default database path
|
|
18
18
|
*/
|
|
19
|
-
function getDefaultDbPath(
|
|
20
|
-
// First check if DATABASE_URL is provided
|
|
21
|
-
|
|
19
|
+
function getDefaultDbPath(): string {
|
|
20
|
+
// First check if DATABASE_URL is provided
|
|
21
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
22
|
+
if (databaseUrl) {
|
|
22
23
|
// DATABASE_URL can be either a direct file path or a sqlite:// URL
|
|
23
|
-
if (
|
|
24
|
+
if (databaseUrl.startsWith('sqlite://')) {
|
|
24
25
|
// Remove the sqlite:// prefix and return the path
|
|
25
|
-
return
|
|
26
|
+
return databaseUrl.slice(9);
|
|
26
27
|
} else {
|
|
27
28
|
// Assume it's a direct file path
|
|
28
|
-
return
|
|
29
|
+
return databaseUrl;
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
// Use EFS_MOUNT_PATH for production (in container with EFS)
|
|
33
34
|
// Use SQLITE_DIR for local development
|
|
34
|
-
const efsMountPath =
|
|
35
|
-
const sqliteDir =
|
|
35
|
+
const efsMountPath = process.env.EFS_MOUNT_PATH;
|
|
36
|
+
const sqliteDir = process.env.SQLITE_DIR || '.';
|
|
36
37
|
|
|
37
38
|
if (efsMountPath) {
|
|
38
39
|
// In production with EFS
|
|
@@ -50,7 +51,7 @@ function getDefaultDbPath(config: DatabaseConfig): string {
|
|
|
50
51
|
* If the file doesn't exist, it will be created automatically.
|
|
51
52
|
* @returns Database client
|
|
52
53
|
*/
|
|
53
|
-
export async function db_init(
|
|
54
|
+
export async function db_init(): Promise<Database.Database> {
|
|
54
55
|
// Skip database initialization during build time
|
|
55
56
|
// Check if we're in a build environment by detecting the absence of runtime variables
|
|
56
57
|
if (typeof window === 'undefined' && !process.env.HOSTNAME && process.env.NODE_ENV === 'production') {
|
|
@@ -59,7 +60,7 @@ export async function db_init(config: DatabaseConfig): Promise<Database.Database
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
// Always use the default path - no parameter needed
|
|
62
|
-
const actualPath = getDefaultDbPath(
|
|
63
|
+
const actualPath = getDefaultDbPath();
|
|
63
64
|
|
|
64
65
|
// Check if we already have a connection to this database
|
|
65
66
|
const existingConnection = dbConnections.get(actualPath);
|
package/dist/defaultapp/db.ts
CHANGED
|
@@ -112,13 +112,13 @@ async function loadDatabaseImplementation(dbType: DatabaseType) {
|
|
|
112
112
|
* @returns Database client
|
|
113
113
|
*/
|
|
114
114
|
export async function db_init(): Promise<DatabaseClient> {
|
|
115
|
-
const
|
|
115
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
116
116
|
|
|
117
117
|
if (!dbImplementation) {
|
|
118
|
-
await loadDatabaseImplementation(
|
|
118
|
+
await loadDatabaseImplementation(dbType);
|
|
119
119
|
}
|
|
120
120
|
|
|
121
|
-
return dbImplementation.db_init(
|
|
121
|
+
return dbImplementation.db_init();
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
/**
|
|
@@ -142,8 +142,8 @@ export async function db_query(
|
|
|
142
142
|
* @returns SQL string for creating the table
|
|
143
143
|
*/
|
|
144
144
|
export function db_migrate(model: Model): string {
|
|
145
|
-
const
|
|
146
|
-
return dbImplementation.db_migrate(model,
|
|
145
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
146
|
+
return dbImplementation.db_migrate(model, dbType);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
@@ -7,34 +7,38 @@ This script initializes the database and runs all migrations
|
|
|
7
7
|
|
|
8
8
|
import fs from 'fs';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import { db_init, db_query
|
|
10
|
+
import { db_init, db_query } from './db';
|
|
11
11
|
|
|
12
12
|
async function runMigrations() {
|
|
13
13
|
console.log('🚀 Starting database migration...');
|
|
14
14
|
|
|
15
15
|
try {
|
|
16
|
-
// Get database
|
|
17
|
-
const
|
|
16
|
+
// Get database type from environment
|
|
17
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase();
|
|
18
18
|
|
|
19
|
-
if (
|
|
20
|
-
console.log(`⚠️ Migration runner currently only supports SQLite. Detected: ${
|
|
19
|
+
if (dbType !== 'sqlite') {
|
|
20
|
+
console.log(`⚠️ Migration runner currently only supports SQLite. Detected: ${dbType}`);
|
|
21
21
|
console.log('Please run your database migrations manually.');
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Display database path for SQLite
|
|
26
26
|
let dbPath: string;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const databaseUrl = process.env.DATABASE_URL;
|
|
28
|
+
const efsMountPath = process.env.EFS_MOUNT_PATH;
|
|
29
|
+
const sqliteDir = process.env.SQLITE_DIR || '.';
|
|
30
|
+
|
|
31
|
+
if (databaseUrl) {
|
|
32
|
+
dbPath = databaseUrl.startsWith('sqlite://')
|
|
33
|
+
? databaseUrl.slice(9)
|
|
34
|
+
: databaseUrl;
|
|
31
35
|
console.log(`📁 Database location: ${dbPath} (from DATABASE_URL)`);
|
|
32
|
-
} else if (
|
|
33
|
-
dbPath = path.join(
|
|
36
|
+
} else if (efsMountPath) {
|
|
37
|
+
dbPath = path.join(efsMountPath, 'data', 'app.db');
|
|
34
38
|
console.log(`📁 Database location: ${dbPath} (from EFS_MOUNT_PATH)`);
|
|
35
39
|
} else {
|
|
36
|
-
dbPath = path.join(
|
|
37
|
-
console.log(`📁 Database location: ${dbPath} (default: ${
|
|
40
|
+
dbPath = path.join(sqliteDir, 'app.db');
|
|
41
|
+
console.log(`📁 Database location: ${dbPath} (default: ${sqliteDir !== '.' ? 'SQLITE_DIR' : 'current directory'})`);
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
// Initialize database connection
|
|
@@ -98,8 +98,10 @@ import * as dbImplementation from './db-{{DATABASE_TYPE}}';
|
|
|
98
98
|
* @returns Database client
|
|
99
99
|
*/
|
|
100
100
|
export async function db_init(): Promise<DatabaseClient> {
|
|
101
|
-
const
|
|
102
|
-
|
|
101
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
102
|
+
|
|
103
|
+
// For the template, we use static import based on database type
|
|
104
|
+
return dbImplementation.db_init();
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
/**
|
|
@@ -123,8 +125,8 @@ export async function db_query(
|
|
|
123
125
|
* @returns SQL string for creating the table
|
|
124
126
|
*/
|
|
125
127
|
export function db_migrate(model: Model): string {
|
|
126
|
-
const
|
|
127
|
-
return dbImplementation.db_migrate(model,
|
|
128
|
+
const dbType = (process.env.DATABASE_TYPE || process.env.DB_TYPE || 'postgres').toLowerCase() as DatabaseType;
|
|
129
|
+
return dbImplementation.db_migrate(model, dbType);
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Database Configuration
|
|
2
|
-
# Set DATABASE_TYPE to one of: sqlite, postgres, mysql
|
|
2
|
+
# Set DATABASE_TYPE or DB_TYPE to one of: sqlite, postgres, mysql
|
|
3
3
|
DATABASE_TYPE=sqlite
|
|
4
|
+
# DB_TYPE=postgres
|
|
4
5
|
|
|
5
6
|
# SQLite Configuration
|
|
6
7
|
# Option 1: Specify full database path (recommended)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sitepaige-mcp-server",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.6",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for generating web applications using SitePaige AI. Generate frontend (FREE/12 credits) then optionally add backend (50 credits)",
|
|
6
6
|
"keywords": [
|