Rename to hkt.sh
This commit is contained in:
31
aff-monitor/db/migrate-003-public-fields.js
Normal file
31
aff-monitor/db/migrate-003-public-fields.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Migration 003 — 前台展示字段
|
||||
*
|
||||
* - is_public: 是否在前台展示 (0/1, 默认 1)
|
||||
* - is_featured: 是否推荐 (0/1, 默认 0)
|
||||
* - sort_order: 排序值 (数字越小越靠前, 默认 100)
|
||||
*/
|
||||
const Database = require('better-sqlite3');
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.join(__dirname, '..', '.env') });
|
||||
|
||||
const dbPath = path.resolve(__dirname, '..', process.env.DB_PATH || 'db/monitor.sqlite');
|
||||
const db = new Database(dbPath);
|
||||
db.pragma('journal_mode = WAL');
|
||||
|
||||
function ensureColumn(table, column, sql) {
|
||||
const cols = db.prepare(`PRAGMA table_info(${table})`).all().map(c => c.name);
|
||||
if (!cols.includes(column)) {
|
||||
db.exec(`ALTER TABLE ${table} ADD COLUMN ${sql}`);
|
||||
console.log(`+ ${table}.${column}`);
|
||||
} else {
|
||||
console.log(` ${table}.${column} (already exists)`);
|
||||
}
|
||||
}
|
||||
|
||||
ensureColumn('products', 'is_public', 'is_public INTEGER DEFAULT 1');
|
||||
ensureColumn('products', 'is_featured', 'is_featured INTEGER DEFAULT 0');
|
||||
ensureColumn('products', 'sort_order', 'sort_order INTEGER DEFAULT 100');
|
||||
|
||||
console.log('✅ migration-003 done:', dbPath);
|
||||
db.close();
|
||||
Reference in New Issue
Block a user