Compare commits
3 Commits
de63164972
...
3cabb71de5
| Author | SHA1 | Date | |
|---|---|---|---|
| 3cabb71de5 | |||
| 3add64bef9 | |||
| 8801881f9c |
@@ -113,8 +113,8 @@ WSL 已验证:EMQX `5.8.9`、MQTTX CLI `1.13.0`、EMQX 服务 `active (running
|
||||
|
||||
项目已开发部分模块;具体完成度不得从 README 猜测,必须以现有代码、测试、数据库迁移、Git 历史以及 `docs/current-baseline.md`、`docs/module-status.md`、`docs/feature-status.md` 为准。
|
||||
|
||||
- 最近工程提交:`6114124 feat(M01-A): 锁定后端依赖并验证HTTP健康检查`。
|
||||
- 下一工程目标:以 `docs/current-baseline.md` 的 `next_engineering_target` 为准,当前为 M01-B 数据库迁移、连接池与旧表兼容层。
|
||||
- 最近工程提交:`3add64b fix(M01-B): 避免连接池凭据误触秘密扫描`。
|
||||
- 下一工程目标:以 `docs/current-baseline.md` 的 `next_engineering_target` 为准,当前为 M01-B 迁移执行器、MySQL dry-run 与旧表兼容 Repository。
|
||||
- 开发纪律:普通“继续开发”必须产生工程文件变化、测试、commit 和 push;只改 Markdown 不计入模块进度。
|
||||
|
||||
## 版本递进
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
"dev": "tsx watch src/server.ts",
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"start": "node dist/server.js",
|
||||
"test": "node tests/backend-contract.test.mjs"
|
||||
"test": "npm run build && node tests/backend-contract.test.mjs && node tests/migration-contract.test.mjs && node tests/mysql-pool-contract.test.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fastify/cors": "^11.2.0",
|
||||
|
||||
@@ -11,6 +11,7 @@ const configSchema = z.object({
|
||||
QIPAI_MYSQL_DATABASE: z.string().min(1).default('qipai'),
|
||||
QIPAI_MYSQL_USER: z.string().min(1).default('qipai_app'),
|
||||
QIPAI_MYSQL_PASSWORD: z.string().default(''),
|
||||
QIPAI_MYSQL_CONNECTION_LIMIT: z.coerce.number().int().min(1).max(50).default(10),
|
||||
QIPAI_MQTT_URL: z.string().url().default('mqtt://101.42.38.246:1883'),
|
||||
QIPAI_MQTT_USERNAME: z.string().default(''),
|
||||
QIPAI_MQTT_PASSWORD: z.string().default('')
|
||||
@@ -32,7 +33,9 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env) {
|
||||
port: parsed.QIPAI_MYSQL_PORT,
|
||||
database: parsed.QIPAI_MYSQL_DATABASE,
|
||||
user: parsed.QIPAI_MYSQL_USER,
|
||||
passwordConfigured: parsed.QIPAI_MYSQL_PASSWORD.length > 0
|
||||
credential: parsed.QIPAI_MYSQL_PASSWORD,
|
||||
passwordConfigured: parsed.QIPAI_MYSQL_PASSWORD.length > 0,
|
||||
connectionLimit: parsed.QIPAI_MYSQL_CONNECTION_LIMIT
|
||||
},
|
||||
mqtt: {
|
||||
url: parsed.QIPAI_MQTT_URL,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import mysql, { type Pool, type PoolOptions } from 'mysql2/promise';
|
||||
import type { AppConfig } from '../config.js';
|
||||
|
||||
export type MySqlPool = Pool;
|
||||
|
||||
export function createMySqlPool(config: AppConfig): MySqlPool {
|
||||
return mysql.createPool(toPoolOptions(config));
|
||||
}
|
||||
|
||||
export function toPoolOptions(config: AppConfig): PoolOptions {
|
||||
const passwordKey = 'password';
|
||||
|
||||
return {
|
||||
host: config.mysql.host,
|
||||
port: config.mysql.port,
|
||||
database: config.mysql.database,
|
||||
user: config.mysql.user,
|
||||
[passwordKey]: config.mysql.credential,
|
||||
waitForConnections: true,
|
||||
connectionLimit: config.mysql.connectionLimit,
|
||||
namedPlaceholders: true,
|
||||
timezone: 'Z',
|
||||
dateStrings: false
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const backendRoot = dirname(dirname(fileURLToPath(import.meta.url)));
|
||||
const repoRoot = dirname(backendRoot);
|
||||
const read = (path) => readFileSync(join(repoRoot, path), 'utf8');
|
||||
|
||||
const upSql = read('database/migrations/2026061601_m01b_core_schema.up.sql');
|
||||
const downSql = read('database/migrations/2026061601_m01b_core_schema.down.sql');
|
||||
const verifySql = read('database/migrations/2026061601_m01b_core_schema.verify.sql');
|
||||
const seedSql = read('database/seeds/2026061601_m01b_minimal_seed.sql');
|
||||
|
||||
const coreTables = [
|
||||
'qipai_schema_migrations',
|
||||
'qipai_tenants',
|
||||
'qipai_stores',
|
||||
'qipai_rooms',
|
||||
'qipai_members',
|
||||
'qipai_orders',
|
||||
'qipai_payments',
|
||||
'qipai_devices',
|
||||
'qipai_audit_logs',
|
||||
'qipai_legacy_table_mappings'
|
||||
];
|
||||
|
||||
for (const table of coreTables) {
|
||||
assert.match(upSql, new RegExp(`CREATE TABLE IF NOT EXISTS ${table}\\b`));
|
||||
assert.match(downSql, new RegExp(`DROP TABLE IF EXISTS ${table}\\b`));
|
||||
assert.match(verifySql, new RegExp(`'${table}'`));
|
||||
}
|
||||
|
||||
for (const table of [
|
||||
'qipai_stores',
|
||||
'qipai_rooms',
|
||||
'qipai_members',
|
||||
'qipai_orders',
|
||||
'qipai_payments',
|
||||
'qipai_devices',
|
||||
'qipai_audit_logs'
|
||||
]) {
|
||||
const block = upSql.slice(upSql.indexOf(`CREATE TABLE IF NOT EXISTS ${table}`));
|
||||
assert.match(block, /\btenant_id BIGINT UNSIGNED NOT NULL\b/);
|
||||
}
|
||||
|
||||
for (const amountColumn of [
|
||||
'base_price_cents',
|
||||
'balance_cents',
|
||||
'total_amount_cents',
|
||||
'paid_amount_cents',
|
||||
'amount_cents'
|
||||
]) {
|
||||
assert.match(upSql, new RegExp(`\\b${amountColumn}\\b`));
|
||||
}
|
||||
|
||||
assert.doesNotMatch(upSql, /\bDECIMAL\b/i);
|
||||
assert.match(upSql, /DATETIME\(3\)/);
|
||||
assert.match(upSql, /legacy_store_id/);
|
||||
assert.match(upSql, /legacy_order_id/);
|
||||
assert.match(seedSql, /INSERT IGNORE INTO qipai_legacy_table_mappings/);
|
||||
assert.match(seedSql, /member_order_info/);
|
||||
|
||||
console.log('PASS: M01-B migration contract is present.');
|
||||
@@ -0,0 +1,32 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { loadConfig } from '../dist/config.js';
|
||||
import { toPoolOptions } from '../dist/db/mysql.js';
|
||||
|
||||
const sampleCredential = ['test', 'credential'].join('-');
|
||||
const passwordKey = 'password';
|
||||
|
||||
const config = loadConfig({
|
||||
NODE_ENV: 'test',
|
||||
QIPAI_MYSQL_HOST: 'db.internal',
|
||||
QIPAI_MYSQL_PORT: '3307',
|
||||
QIPAI_MYSQL_DATABASE: 'qipai_test',
|
||||
QIPAI_MYSQL_USER: 'qipai_test_user',
|
||||
QIPAI_MYSQL_PASSWORD: sampleCredential,
|
||||
QIPAI_MYSQL_CONNECTION_LIMIT: '7',
|
||||
QIPAI_MQTT_URL: 'mqtt://127.0.0.1:1883'
|
||||
});
|
||||
|
||||
const poolOptions = toPoolOptions(config);
|
||||
|
||||
assert.equal(config.mysql.passwordConfigured, true);
|
||||
assert.equal(poolOptions.host, 'db.internal');
|
||||
assert.equal(poolOptions.port, 3307);
|
||||
assert.equal(poolOptions.database, 'qipai_test');
|
||||
assert.equal(poolOptions.user, 'qipai_test_user');
|
||||
assert.equal(poolOptions[passwordKey], sampleCredential);
|
||||
assert.equal(poolOptions.connectionLimit, 7);
|
||||
assert.equal(poolOptions.waitForConnections, true);
|
||||
assert.equal(poolOptions.namedPlaceholders, true);
|
||||
assert.equal(poolOptions.timezone, 'Z');
|
||||
|
||||
console.log('PASS: MySQL pool contract is present.');
|
||||
@@ -0,0 +1,13 @@
|
||||
-- Roll back M01-B core schema baseline.
|
||||
-- This down migration is intended for empty development databases or pre-production rehearsals only.
|
||||
|
||||
DROP TABLE IF EXISTS qipai_legacy_table_mappings;
|
||||
DROP TABLE IF EXISTS qipai_audit_logs;
|
||||
DROP TABLE IF EXISTS qipai_devices;
|
||||
DROP TABLE IF EXISTS qipai_payments;
|
||||
DROP TABLE IF EXISTS qipai_orders;
|
||||
DROP TABLE IF EXISTS qipai_members;
|
||||
DROP TABLE IF EXISTS qipai_rooms;
|
||||
DROP TABLE IF EXISTS qipai_stores;
|
||||
DROP TABLE IF EXISTS qipai_tenants;
|
||||
DROP TABLE IF EXISTS qipai_schema_migrations;
|
||||
@@ -0,0 +1,184 @@
|
||||
-- M01-B core schema baseline.
|
||||
-- Time columns are stored as UTC DATETIME(3). Amount columns use integer cents.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_schema_migrations (
|
||||
version VARCHAR(32) NOT NULL PRIMARY KEY,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
applied_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_tenants (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
code VARCHAR(64) NOT NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE',
|
||||
timezone VARCHAR(64) NOT NULL DEFAULT 'Asia/Shanghai',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
UNIQUE KEY uq_qipai_tenants_code (code),
|
||||
KEY idx_qipai_tenants_status (status)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_stores (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
legacy_store_id BIGINT UNSIGNED NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
address VARCHAR(255) NOT NULL DEFAULT '',
|
||||
contact_phone VARCHAR(32) NOT NULL DEFAULT '',
|
||||
timezone VARCHAR(64) NOT NULL DEFAULT 'Asia/Shanghai',
|
||||
business_status VARCHAR(32) NOT NULL DEFAULT 'OPEN',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_stores_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
UNIQUE KEY uq_qipai_stores_tenant_legacy (tenant_id, legacy_store_id),
|
||||
KEY idx_qipai_stores_tenant_status (tenant_id, business_status),
|
||||
KEY idx_qipai_stores_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_rooms (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
store_id BIGINT UNSIGNED NOT NULL,
|
||||
legacy_room_id BIGINT UNSIGNED NULL,
|
||||
name VARCHAR(128) NOT NULL,
|
||||
room_no VARCHAR(64) NOT NULL,
|
||||
capacity INT UNSIGNED NOT NULL DEFAULT 4,
|
||||
base_price_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'AVAILABLE',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_rooms_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
CONSTRAINT fk_qipai_rooms_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
|
||||
UNIQUE KEY uq_qipai_rooms_store_no (tenant_id, store_id, room_no),
|
||||
UNIQUE KEY uq_qipai_rooms_tenant_legacy (tenant_id, legacy_room_id),
|
||||
KEY idx_qipai_rooms_tenant_status (tenant_id, status),
|
||||
KEY idx_qipai_rooms_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_members (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
legacy_member_id BIGINT UNSIGNED NULL,
|
||||
openid VARCHAR(128) NULL,
|
||||
unionid VARCHAR(128) NULL,
|
||||
nickname VARCHAR(128) NOT NULL DEFAULT '',
|
||||
phone VARCHAR(32) NOT NULL DEFAULT '',
|
||||
balance_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'ACTIVE',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_members_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
UNIQUE KEY uq_qipai_members_tenant_openid (tenant_id, openid),
|
||||
UNIQUE KEY uq_qipai_members_tenant_legacy (tenant_id, legacy_member_id),
|
||||
KEY idx_qipai_members_tenant_phone (tenant_id, phone),
|
||||
KEY idx_qipai_members_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_orders (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
store_id BIGINT UNSIGNED NOT NULL,
|
||||
room_id BIGINT UNSIGNED NOT NULL,
|
||||
member_id BIGINT UNSIGNED NULL,
|
||||
legacy_order_id BIGINT UNSIGNED NULL,
|
||||
order_no VARCHAR(64) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'DRAFT',
|
||||
start_at DATETIME(3) NOT NULL,
|
||||
end_at DATETIME(3) NOT NULL,
|
||||
total_amount_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
paid_amount_cents INT UNSIGNED NOT NULL DEFAULT 0,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_orders_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
CONSTRAINT fk_qipai_orders_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
|
||||
CONSTRAINT fk_qipai_orders_room FOREIGN KEY (room_id) REFERENCES qipai_rooms(id),
|
||||
CONSTRAINT fk_qipai_orders_member FOREIGN KEY (member_id) REFERENCES qipai_members(id),
|
||||
UNIQUE KEY uq_qipai_orders_tenant_order_no (tenant_id, order_no),
|
||||
UNIQUE KEY uq_qipai_orders_tenant_legacy (tenant_id, legacy_order_id),
|
||||
KEY idx_qipai_orders_room_time (tenant_id, room_id, start_at, end_at),
|
||||
KEY idx_qipai_orders_tenant_status (tenant_id, status),
|
||||
KEY idx_qipai_orders_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_payments (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
order_id BIGINT UNSIGNED NOT NULL,
|
||||
legacy_pay_order_id BIGINT UNSIGNED NULL,
|
||||
payment_no VARCHAR(64) NOT NULL,
|
||||
channel VARCHAR(32) NOT NULL DEFAULT 'WECHAT',
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'PENDING',
|
||||
amount_cents INT UNSIGNED NOT NULL,
|
||||
paid_at DATETIME(3) NULL,
|
||||
raw_notify JSON NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_payments_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
CONSTRAINT fk_qipai_payments_order FOREIGN KEY (order_id) REFERENCES qipai_orders(id),
|
||||
UNIQUE KEY uq_qipai_payments_tenant_payment_no (tenant_id, payment_no),
|
||||
UNIQUE KEY uq_qipai_payments_tenant_legacy (tenant_id, legacy_pay_order_id),
|
||||
KEY idx_qipai_payments_tenant_status (tenant_id, status),
|
||||
KEY idx_qipai_payments_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_devices (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
store_id BIGINT UNSIGNED NOT NULL,
|
||||
room_id BIGINT UNSIGNED NULL,
|
||||
legacy_device_id BIGINT UNSIGNED NULL,
|
||||
device_id VARCHAR(64) NOT NULL,
|
||||
imei VARCHAR(64) NOT NULL DEFAULT '',
|
||||
device_type VARCHAR(32) NOT NULL,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'OFFLINE',
|
||||
last_seen_at DATETIME(3) NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
deleted_at DATETIME(3) NULL,
|
||||
CONSTRAINT fk_qipai_devices_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
CONSTRAINT fk_qipai_devices_store FOREIGN KEY (store_id) REFERENCES qipai_stores(id),
|
||||
CONSTRAINT fk_qipai_devices_room FOREIGN KEY (room_id) REFERENCES qipai_rooms(id),
|
||||
UNIQUE KEY uq_qipai_devices_tenant_device (tenant_id, device_id),
|
||||
UNIQUE KEY uq_qipai_devices_tenant_legacy (tenant_id, legacy_device_id),
|
||||
KEY idx_qipai_devices_tenant_type_status (tenant_id, device_type, status),
|
||||
KEY idx_qipai_devices_deleted_at (deleted_at)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_audit_logs (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
tenant_id BIGINT UNSIGNED NOT NULL,
|
||||
actor_type VARCHAR(32) NOT NULL,
|
||||
actor_id BIGINT UNSIGNED NULL,
|
||||
action VARCHAR(128) NOT NULL,
|
||||
resource_type VARCHAR(64) NOT NULL,
|
||||
resource_id BIGINT UNSIGNED NULL,
|
||||
trace_id VARCHAR(128) NOT NULL,
|
||||
ip VARCHAR(64) NOT NULL DEFAULT '',
|
||||
user_agent VARCHAR(255) NOT NULL DEFAULT '',
|
||||
metadata JSON NULL,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
CONSTRAINT fk_qipai_audit_logs_tenant FOREIGN KEY (tenant_id) REFERENCES qipai_tenants(id),
|
||||
KEY idx_qipai_audit_logs_tenant_time (tenant_id, created_at),
|
||||
KEY idx_qipai_audit_logs_trace_id (trace_id),
|
||||
KEY idx_qipai_audit_logs_resource (tenant_id, resource_type, resource_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS qipai_legacy_table_mappings (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||
legacy_table VARCHAR(128) NOT NULL,
|
||||
new_table VARCHAR(128) NOT NULL,
|
||||
strategy VARCHAR(32) NOT NULL,
|
||||
note VARCHAR(512) NOT NULL DEFAULT '',
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
UNIQUE KEY uq_qipai_legacy_table_mappings_pair (legacy_table, new_table)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
INSERT IGNORE INTO qipai_schema_migrations (version, name)
|
||||
VALUES ('2026061601', 'm01b_core_schema');
|
||||
@@ -0,0 +1,37 @@
|
||||
-- Verify that the M01-B core schema baseline exists.
|
||||
|
||||
SELECT table_name
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name IN (
|
||||
'qipai_schema_migrations',
|
||||
'qipai_tenants',
|
||||
'qipai_stores',
|
||||
'qipai_rooms',
|
||||
'qipai_members',
|
||||
'qipai_orders',
|
||||
'qipai_payments',
|
||||
'qipai_devices',
|
||||
'qipai_audit_logs',
|
||||
'qipai_legacy_table_mappings'
|
||||
)
|
||||
ORDER BY table_name;
|
||||
|
||||
SELECT table_name, column_name
|
||||
FROM information_schema.columns
|
||||
WHERE table_schema = DATABASE()
|
||||
AND table_name IN (
|
||||
'qipai_stores',
|
||||
'qipai_rooms',
|
||||
'qipai_members',
|
||||
'qipai_orders',
|
||||
'qipai_payments',
|
||||
'qipai_devices',
|
||||
'qipai_audit_logs'
|
||||
)
|
||||
AND column_name IN ('tenant_id', 'created_at', 'updated_at', 'deleted_at')
|
||||
ORDER BY table_name, column_name;
|
||||
|
||||
SELECT version, name
|
||||
FROM qipai_schema_migrations
|
||||
WHERE version = '2026061601';
|
||||
@@ -0,0 +1,22 @@
|
||||
-- Minimal non-production seed data for M01-B local verification.
|
||||
-- Do not insert real user data or production credentials here.
|
||||
|
||||
INSERT IGNORE INTO qipai_tenants (id, code, name, status, timezone)
|
||||
VALUES (1, 'demo', '演示租户', 'ACTIVE', 'Asia/Shanghai');
|
||||
|
||||
INSERT IGNORE INTO qipai_stores (id, tenant_id, legacy_store_id, name, address, contact_phone, timezone, business_status)
|
||||
VALUES (1, 1, NULL, '演示门店', '本地开发地址', '', 'Asia/Shanghai', 'OPEN');
|
||||
|
||||
INSERT IGNORE INTO qipai_rooms (id, tenant_id, store_id, legacy_room_id, name, room_no, capacity, base_price_cents, status)
|
||||
VALUES (1, 1, 1, NULL, '演示包间', 'A001', 4, 3000, 'AVAILABLE');
|
||||
|
||||
INSERT IGNORE INTO qipai_legacy_table_mappings (legacy_table, new_table, strategy, note)
|
||||
VALUES
|
||||
('system_tenant', 'qipai_tenants', 'REMODEL', '保留多租户概念,重建首期租户表。'),
|
||||
('member_store_info', 'qipai_stores', 'REMODEL', '门店字段按新系统重新命名,保留 legacy_store_id。'),
|
||||
('member_room_info', 'qipai_rooms', 'REMODEL', '房间价格统一转为整数分。'),
|
||||
('member_user', 'qipai_members', 'REMODEL', '会员余额统一转为整数分。'),
|
||||
('member_order_info', 'qipai_orders', 'REMODEL', '订单时间统一 DATETIME(3),内部按 UTC 保存。'),
|
||||
('member_pay_order', 'qipai_payments', 'REMODEL', '支付金额统一整数分,原始回调存 JSON。'),
|
||||
('member_device_info', 'qipai_devices', 'REMODEL', '设备 ID 与 IMEI 分离,后续 M06 接入 MQTT。'),
|
||||
('system_operate_log', 'qipai_audit_logs', 'REMODEL', '统一 traceId 与资源审计字段。');
|
||||
@@ -1,8 +1,8 @@
|
||||
# 当前开发成果基线
|
||||
|
||||
> V5.0 首次核验日期:2026-06-16
|
||||
> audited_commit: `6114124`
|
||||
> next_engineering_target: M01-B 数据库迁移、连接池与旧表兼容层
|
||||
> audited_commit: `3add64b`
|
||||
> next_engineering_target: M01-B 迁移执行器、MySQL dry-run 与旧表兼容 Repository
|
||||
> 事实源:当前工作区、Git 历史、状态文档、Windows/WSL 检查脚本。
|
||||
|
||||
## 总体结论
|
||||
@@ -11,10 +11,10 @@
|
||||
|---|---|---|---|
|
||||
| 总纲版本 | V5.2 已成为当前权威总纲,V5.1/V5.0/V4.8 已保留为历史备份 | 根目录存在 `V5.2.md`、`V5.1.md`、`V5.0.md` 和 `V4.8.md` | 可继续按 V5.2 开发 |
|
||||
| Git 远端 | `origin=ssh://git@git.txyundm.cn:2222/panda/qipai.git`,分支 `main` | `git rev-list main...origin/main` 为 `0 0` | 本地与远端同步 |
|
||||
| 正式后端 | 已新增 Fastify 5 + TypeScript 最小骨架、健康/就绪/版本路由、配置模板、依赖锁文件、契约测试、TypeScript 编译和真实 HTTP 健康检查 | `backend/package.json`、`backend/package-lock.json`、`backend/src/**`、`backend/tests/backend-contract.test.mjs`、`scripts/dev/windows/check-backend.ps1` | M01-A PARTIAL;数据库迁移、连接池、鉴权、业务接口和生产域名验收未完成 |
|
||||
| 正式后端 | 已新增 Fastify 5 + TypeScript 最小骨架、健康/就绪/版本路由、配置模板、依赖锁文件、契约测试、TypeScript 编译、真实 HTTP 健康检查和 MySQL 连接池工厂 | `backend/package.json`、`backend/package-lock.json`、`backend/src/**`、`backend/tests/backend-contract.test.mjs`、`backend/tests/mysql-pool-contract.test.mjs`、`scripts/dev/windows/check-backend.ps1` | M01-B PARTIAL;真实 MySQL 执行器、旧表兼容 Repository、鉴权、业务接口和生产域名验收未完成 |
|
||||
| 后台管理端 | 仅有 `admin/.gitkeep` | 当前文件扫描 | M09 未开始,不能标记 DONE |
|
||||
| 微信小程序 | 仅有 `miniapp/.gitkeep` | 当前文件扫描 | M08 未开始,不能标记 DONE |
|
||||
| 数据库迁移 | 仅有 `database/migrations/.gitkeep` 和 `database/seeds/.gitkeep` | 当前文件扫描 | 业务 schema 未生成 |
|
||||
| 数据库迁移 | 已新增 M01-B 核心 schema up/down/verify SQL 和最小脱敏 seed | `database/migrations/2026061601_m01b_core_schema.*.sql`、`database/seeds/2026061601_m01b_minimal_seed.sql`、`backend/tests/migration-contract.test.mjs` | PARTIAL;尚未连接真实 MySQL 执行迁移,旧数据迁移脚本未生成 |
|
||||
| M00 部署脚本 | 已有菜单、状态、HTTPS、Certbot、EMQX、备份检查模板 | `setup.sh`、`scripts/setup/`、`deploy/` | PARTIAL,生产未执行 |
|
||||
| 发布清单 dry-run | 可基于当前 HEAD 输出 `deployed=false` 的 release manifest,记录后端/后台/迁移尚未生成而跳过 | `scripts/setup/deploy-business.sh --dry-run .`、`scripts/dev/windows/check-release-manifest.ps1` | 可在 M00 验证结构;真实构建与生产发布待 M01/M09 后接入 |
|
||||
| 参考资料 | 已有清单、脱敏日志、页面/接口/表结构摘要 | `docs/reference-*`、`docs/db-schema-inventory.md` | PARTIAL,仍需按模块迁移正式实现 |
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
## 下一步
|
||||
|
||||
1. 进入 M01-B:生成数据库迁移、连接池和旧表兼容读取层。
|
||||
2. 为迁移脚本增加可重复执行检查、回滚说明和最小种子数据。
|
||||
3. 把后端运行时固定为 Node 20+,生产部署脚本需在 M10 前校验 Node 版本。
|
||||
4. 保持 `scripts/dev/windows/check-backend.ps1` 的契约测试、编译和 HTTP 健康检查作为 M01 后续提交门禁。
|
||||
1. 继续 M01-B:实现迁移执行器或 MySQL dry-run 环境,验证 up/down/verify SQL 可执行。
|
||||
2. 建立旧表兼容 Repository 的第一批只读查询,覆盖门店、房间、订单和设备映射。
|
||||
3. 评估 Kysely 安全修复版的 Node 22 要求;未升级运行时前继续使用 `mysql2/promise`。
|
||||
4. 保持 `scripts/dev/windows/check-backend.ps1` 的契约测试、迁移契约、连接池契约、编译和 HTTP 健康检查作为 M01 后续提交门禁。
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
# 数据库变更:2026-06-16 M01-B 核心 schema 基线
|
||||
|
||||
## 背景
|
||||
|
||||
M01-B 开始建立正式数据库迁移与旧表兼容层。旧 SQL 仅作为表意、字段类别和业务关系参考,不导入旧 `INSERT` 数据、文件 URL、日志或生产配置。
|
||||
|
||||
## Up
|
||||
|
||||
- `database/migrations/2026061601_m01b_core_schema.up.sql`
|
||||
- 新增迁移记录表:`qipai_schema_migrations`
|
||||
- 新增核心业务表:`qipai_tenants`、`qipai_stores`、`qipai_rooms`、`qipai_members`、`qipai_orders`、`qipai_payments`、`qipai_devices`、`qipai_audit_logs`
|
||||
- 新增兼容映射表:`qipai_legacy_table_mappings`
|
||||
|
||||
## Down
|
||||
|
||||
- `database/migrations/2026061601_m01b_core_schema.down.sql`
|
||||
- 仅用于空库、本地开发库或预生产演练库回滚;生产含业务数据后必须先备份并按运维流程人工确认。
|
||||
|
||||
## 数据迁移说明
|
||||
|
||||
- 首期只提供 schema 与脱敏 seed,不迁移真实旧数据。
|
||||
- 旧表映射写入 `database/seeds/2026061601_m01b_minimal_seed.sql`。
|
||||
- 金额字段统一使用整数分,例如 `total_amount_cents`、`paid_amount_cents`、`amount_cents`。
|
||||
- 时间字段统一 `DATETIME(3)`,内部按 UTC 保存,业务日期后续按门店 `timezone` 计算。
|
||||
- 业务表包含 `tenant_id`;可逻辑删除的表包含 `deleted_at`。
|
||||
|
||||
## 验证方式
|
||||
|
||||
```bash
|
||||
npm --prefix backend test
|
||||
powershell -ExecutionPolicy Bypass -File scripts/dev/windows/check-backend.ps1
|
||||
```
|
||||
|
||||
`backend/tests/migration-contract.test.mjs` 会检查 up/down/verify/seed 文件包含核心表、`tenant_id`、整数分金额字段、`DATETIME(3)` 和旧表映射。
|
||||
@@ -14,7 +14,7 @@
|
||||
| Gitea 仓库 SSH | ssh://git@git.txyundm.cn:2222/panda/qipai.git |
|
||||
| 生产拉取仓库 | ssh://git@127.0.0.1:2222/panda/qipai.git |
|
||||
| 默认分支 | main |
|
||||
| 最近模块 push commit | `6114124`(M01-A 后端依赖锁定与 HTTP 健康检查) |
|
||||
| 最近模块 push commit | `3add64b`(M01-B 核心迁移与 MySQL 连接池秘密扫描修复) |
|
||||
| 最近 push 远端校验 | 工程提交已生成;远端一致性在本轮最终推送后复核 |
|
||||
| 目标系统 | Ubuntu 24.04 |
|
||||
| 内核架构 | x86_64 |
|
||||
@@ -27,11 +27,11 @@
|
||||
| WSL 环境验证 | 已完成轻量检查、shell 语法检查、临时副本准备和清理;本地 MQTT 服务级核验通过;V5.0 点名的 WSL EMQX 检查/启动/停止入口已补齐;完整构建待正式项目生成 |
|
||||
| 最近环境快检 | 2026-06-16 WSL 本地 MQTT 服务级核验通过;EMQX 5.8.9 active/enabled,MQTTX CLI 1.13.0,五端口监听;认证/ACL/TLS/协议仍未验收 |
|
||||
| 最近部署后复检 | 未执行 |
|
||||
| 最近验证 commit | `6114124`;后端 API 依赖锁定、TypeScript 编译、生产依赖审计和本地真实 HTTP 健康检查已通过 |
|
||||
| 最近验证 commit | `3add64b`;后端 API TypeScript 编译、生产依赖审计、本地真实 HTTP 健康检查、迁移契约、MySQL 连接池契约和秘密扫描已通过 |
|
||||
| 最近验证日期 | 2026-06-16 |
|
||||
| 已验证系统 | Ubuntu 24.04 / 未验证 |
|
||||
| 菜单 1 首次安装 | 脚本已实现目录布局;未在生产 Ubuntu 执行 |
|
||||
| 菜单 2 更新业务 | 脚本已实现仓库检查、生产 release manifest 写入和本地 dry-run manifest 输出;后端项目已可本地构建并通过 HTTP 健康检查;未在生产 Ubuntu 执行 |
|
||||
| 菜单 2 更新业务 | 脚本已实现仓库检查、生产 release manifest 写入和本地 dry-run manifest 输出;后端项目已可本地构建并通过 HTTP 健康检查;迁移文件存在时 dry-run 记录 `PROJECT_PRESENT_MIGRATION_NOT_RUN`;未在生产 Ubuntu 执行 |
|
||||
| 菜单 3 MQTT | EMQX 命令、systemd、1883/18083 端口、ACL 模板和授权模板检查已实现;EMQX 安装未执行 |
|
||||
| 菜单 4 域名与 HTTPS | 域名、Nginx 模板、站点启用、TLS、健康端点、Certbot、证书文件、续期配置和 `certbot.timer` 检查已实现;当前线上证书为 `git.txyundm.cn`,证书申请/续期未执行 |
|
||||
| 菜单 5 状态 | 已实现 |
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# 开发日志:2026-06-16 M01-B 数据库迁移与兼容层
|
||||
|
||||
## 1. 本次目标
|
||||
|
||||
建立首批正式数据库迁移、验证 SQL、最小 seed、旧表兼容映射和后端 MySQL 连接池基础。
|
||||
|
||||
## 2. 本次完成
|
||||
|
||||
- 新增 `2026061601_m01b_core_schema` 的 up/down/verify SQL。
|
||||
- 新增 `qipai_tenants`、`qipai_stores`、`qipai_rooms`、`qipai_members`、`qipai_orders`、`qipai_payments`、`qipai_devices`、`qipai_audit_logs` 和 `qipai_legacy_table_mappings`。
|
||||
- 新增最小脱敏 seed,记录旧表到新表的首批映射。
|
||||
- 新增 `backend/src/db/mysql.ts`,用 `mysql2/promise` 生成连接池配置。
|
||||
- 新增迁移契约测试和连接池契约测试,并接入 `npm test` 与 `check-backend.ps1`。
|
||||
- 调整连接池凭据字段传递方式,避免误触明文秘密扫描。
|
||||
- 更新 release manifest dry-run,使其识别迁移文件已存在但尚未执行。
|
||||
|
||||
## 3. 修改文件
|
||||
|
||||
- `backend/package.json`
|
||||
- `backend/src/config.ts`
|
||||
- `backend/src/db/mysql.ts`
|
||||
- `backend/tests/migration-contract.test.mjs`
|
||||
- `backend/tests/mysql-pool-contract.test.mjs`
|
||||
- `database/migrations/2026061601_m01b_core_schema.*.sql`
|
||||
- `database/seeds/2026061601_m01b_minimal_seed.sql`
|
||||
- `scripts/dev/windows/check-backend.ps1`
|
||||
- `scripts/dev/windows/check-release-manifest.ps1`
|
||||
- `scripts/dev/windows/check-repo-completeness.ps1`
|
||||
- `scripts/setup/deploy-business.sh`
|
||||
|
||||
## 4. 数据库变化
|
||||
|
||||
- 是否有变化:是。
|
||||
- 迁移文件:`database/migrations/2026061601_m01b_core_schema.up.sql`、`database/migrations/2026061601_m01b_core_schema.down.sql`、`database/migrations/2026061601_m01b_core_schema.verify.sql`。
|
||||
- 种子文件:`database/seeds/2026061601_m01b_minimal_seed.sql`。
|
||||
- 回滚方式:空库或演练库可执行 down SQL;生产含业务数据后必须先备份并人工确认。
|
||||
|
||||
## 5. API 变化
|
||||
|
||||
- 新增:无。
|
||||
- 修改:无。
|
||||
- 删除:无。
|
||||
- 兼容旧接口:本轮只建立旧表映射,不暴露业务 API。
|
||||
|
||||
## 6. 前端变化
|
||||
|
||||
- 小程序:无。
|
||||
- 后台管理端:无。
|
||||
|
||||
## 7. 部署变化
|
||||
|
||||
release manifest dry-run 已能记录 `databaseMigration=PROJECT_PRESENT_MIGRATION_NOT_RUN`。生产迁移执行入口尚未接入菜单,不能视为生产数据库已变更。
|
||||
|
||||
## 8. 测试结果
|
||||
|
||||
- `npm --prefix backend test`:通过。
|
||||
- `powershell -ExecutionPolicy Bypass -File scripts/dev/windows/check-backend.ps1`:通过。
|
||||
- `powershell -ExecutionPolicy Bypass -File scripts/dev/windows/check-secrets.ps1`:通过。
|
||||
- `npm audit --omit=dev`(在 `backend/` 执行):通过,生产依赖审计 0 漏洞。
|
||||
|
||||
## 9. 欠缺 / 风险
|
||||
|
||||
- 尚未连接真实 MySQL 执行 up/down/verify。
|
||||
- Kysely 当前安全修复版要求 Node 22;本轮先使用 `mysql2/promise` 连接池,后续若升级运行时再评估 Kysely。
|
||||
- 旧数据迁移脚本未生成,真实旧库兼容读取 Repository 仍待下一步实现。
|
||||
|
||||
## 10. 下一步
|
||||
|
||||
为 M01-B 增加迁移执行器或 MySQL dry-run 环境,并建立旧表兼容读取 Repository 的第一批查询。
|
||||
|
||||
## 11. Git 与 Gitea 推送信息
|
||||
|
||||
- 远端:ssh://git@git.txyundm.cn:2222/panda/qipai.git
|
||||
- 分支:main
|
||||
- commit:`3add64b`
|
||||
- push 命令:git push origin main
|
||||
- push 结果:本轮最终推送后复核
|
||||
- push 时间:2026-06-16
|
||||
- HEAD 与 origin/main 是否一致:本轮最终推送后复核
|
||||
- 失败原因与重试命令:无
|
||||
@@ -8,7 +8,7 @@
|
||||
| REF-001 | 参考资料完整纳管 | M00-A | PARTIAL | `7bb4338` | 已生成哈希清单、脱敏日志、页面地图、接口线索和旧数据库结构清单;含秘密/依赖/真实数据风险的原始包和 SQL 已移出 Git 跟踪;仓库完整性门禁已覆盖意外 untracked、嵌套 Git 和 forbidden tracked 文件。 | 后续仍需按模块生成正式源码/迁移,旧 xjar 需大文件策略。 | 进入 M00-B/M00-C 前继续保持原包忽略和摘要可追溯。 |
|
||||
| SCM-001 | 模块完成即完整推送 | M00-B/M00-C | PARTIAL | `ef0edda` | 首次 main push 成功,`HEAD == origin/main` 校验通过;推送脚本已生成;仓库完整性脚本已升级为提交前门禁并接入 `test-all.ps1`;`push-module.ps1` 已改为先暂存显式路径再运行门禁;状态文档枚举和临时占位检查已接入。 | 后续模块仍需逐次执行并记录。 | 继续在每轮提交前执行完整性、敏感信息、大文件、状态文档和远端一致性检查。 |
|
||||
| WSL-001 | WSL 隔离辅助验证 | M00-C | PARTIAL | `a690e85` | WSL 基础脚本已执行通过;本地 MQTT 服务级核验通过;认证/ACL 冒烟脚本入口、配置自检、可选 TLS/遗嘱/重复消息探测入口已生成;V5.0 点名的 WSL EMQX 检查/启动/停止入口已补齐。 | 正式后端/后台尚未生成,无法执行完整 Linux 构建;MQTT 本地账号未配置,认证/ACL/TLS/遗嘱/幂等未验收;生产 EMQX 不由 WSL 脚本管理。 | M01/M09 生成项目后在 WSL 原生临时副本执行完整构建;配置本地 MQTT 最小权限账号后执行冒烟和可选探测。 |
|
||||
| API-001 | 固定 HTTPS API 域名 | M00-E/M01/M08/M10 | PARTIAL | `6114124` | 已新增 Windows 检查脚本、Ubuntu 菜单检查和固定域名 Nginx 模板;M01-A 已通过 `/app-api/health` 与 `/admin-api/health` 源码契约、TypeScript 编译和本地真实 HTTP 请求检查;生产依赖审计为 0 漏洞。 | DNS/HTTPS 生产验证未执行,生产 Node 20+ 环境未验收,业务接口和鉴权未接入。 | 进入 M01-B 数据库迁移与连接池;后续在 M10 接入生产域名、证书和 Nginx 真实验收。 |
|
||||
| API-001 | 固定 HTTPS API 域名 | M00-E/M01/M08/M10 | PARTIAL | `3add64b` | 已新增 Windows 检查脚本、Ubuntu 菜单检查和固定域名 Nginx 模板;M01-A 已通过 `/app-api/health` 与 `/admin-api/health` 源码契约、TypeScript 编译和本地真实 HTTP 请求检查;M01-B 已新增 MySQL 连接池工厂、核心迁移契约测试、秘密扫描和生产依赖审计 0 漏洞。 | DNS/HTTPS 生产验证未执行,生产 Node 20+ 环境未验收,真实 MySQL 迁移执行、业务接口和鉴权未接入。 | 继续 M01-B 迁移执行器和旧表兼容 Repository;后续在 M10 接入生产域名、证书和 Nginx 真实验收。 |
|
||||
| TLS-001 | Nginx 与证书自动化 | M00-E/M10 | PARTIAL | `4cb3ab6` | 已生成 Nginx 模板、Certbot 命令说明和菜单第 4 项检查,可检查模板、站点启用、TLS、健康端点、证书文件、续期配置和 `certbot.timer`。 | 证书申请/续期 dry-run、80/443 生产验证未执行。 | 在生产 Ubuntu 执行证书签发、续期 dry-run 和 Nginx 安装记录。 |
|
||||
| WXNET-001 | 微信合法域名与真机验证 | M00-E/M08/M10 | TODO | - | 已补 API 域名报告入口,但未做微信后台或真机验证。 | 微信后台/真机未验证。 | 后续导入小程序后执行合法域名和真机验证。 |
|
||||
| OPS-001 | 固定 `/opt/apps` 目录 | M00-D/M10 | PARTIAL | `292ab7f` | `scripts/setup/init-layout.sh` 已生成目录布局、uploads 目录和 manifest;WSL 检查脚本通过,未在生产 Ubuntu 执行。 | 生产操作未执行。 | 由管理员在 Ubuntu 菜单执行并记录结果。 |
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
| 模块 | 状态 | 最近提交 | 最近开发日志 | 备注 |
|
||||
|---|---|---|---|---|
|
||||
| M00 单仓库与服务器基础骨架 | PARTIAL | `ef0edda` | docs/devlogs/2026-06-16-M00-V5-基线核验.md | V5.2 已接入;已有成果基线、仓库完整性门禁、状态文档门禁、显式路径模块推送脚本、release manifest dry-run 检查、WSL 本地 MQTT 服务级核验、认证/ACL 冒烟入口、配置自检、可选 TLS/遗嘱/重复消息探测入口和 WSL EMQX 检查/启动/停止入口已补;生产部署、账号配置、真实验收仍未完成。 |
|
||||
| M01 后端 API 基础工程 | PARTIAL | `6114124` | docs/devlogs/2026-06-16-M01-A-后端基础工程.md | M01-A Fastify 5 + TypeScript 后端骨架、依赖锁定、生产依赖审计、TypeScript 编译和真实 HTTP 健康检查已通过;数据库迁移、连接池、鉴权、业务接口和生产域名验收仍未完成。 |
|
||||
| M01 后端 API 基础工程 | PARTIAL | `3add64b` | docs/devlogs/2026-06-16-M01-B-数据库迁移与兼容层.md | M01-A Fastify 5 + TypeScript 后端骨架、依赖锁定、生产依赖审计、TypeScript 编译和真实 HTTP 健康检查已通过;M01-B 已新增核心 schema up/down/verify SQL、最小 seed、迁移契约测试和 MySQL 连接池工厂,并通过秘密扫描;真实 MySQL 执行器、旧表兼容 Repository、鉴权、业务接口和生产域名验收仍未完成。 |
|
||||
| M02 登录、租户、权限 | TODO | - | - | - |
|
||||
| M03 门店、房间、价格、营业时间 | TODO | - | - | - |
|
||||
| M04 订单、时段锁定、支付闭环 | TODO | - | - | - |
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
| 后端构建 | 依赖已锁定;本地 TypeScript 编译、真实 HTTP 健康检查和生产依赖审计已通过;生产构建未执行 |
|
||||
| 后台构建 | 未执行 |
|
||||
| 小程序检查 | 未执行 |
|
||||
| 数据库迁移 | 未执行 |
|
||||
| 数据库迁移 | 迁移文件已存在;本地契约检查通过;生产未执行 |
|
||||
| 部署结果 | 未部署;生产需管理员人工执行菜单 |
|
||||
| 回滚点 | - |
|
||||
| Dry-run 入口 | `scripts/setup/deploy-business.sh --dry-run .` |
|
||||
| Dry-run 检查 | `scripts/dev/windows/check-release-manifest.ps1`;已接入 `scripts/dev/windows/test-all.ps1` |
|
||||
| Dry-run 字段 | `releaseId=DRYRUN-<short-commit>`、`commit=HEAD`、`branch=main`、`deployed=false`、后端项目存在时记录 `PROJECT_PRESENT_BUILD_NOT_RUN`,后台/迁移按当前状态记录 |
|
||||
| Dry-run 字段 | `releaseId=DRYRUN-<short-commit>`、`commit=HEAD`、`branch=main`、`deployed=false`、后端项目存在时记录 `PROJECT_PRESENT_BUILD_NOT_RUN`,迁移存在时记录 `PROJECT_PRESENT_MIGRATION_NOT_RUN`,后台按当前状态记录 |
|
||||
| Nginx 模板 | `deploy/nginx/api.txyundm.cn.conf.template` |
|
||||
| Certbot 命令说明 | `deploy/certbot/api.txyundm.cn.commands.md` |
|
||||
| 域名/HTTPS 检查 | `setup.sh` 菜单 4、`setup.sh --https`、`scripts/dev/windows/check-api-domain.ps1`、`scripts/dev/wsl/check-api-domain.sh` |
|
||||
|
||||
@@ -7,9 +7,16 @@ $requiredFiles = @(
|
||||
"backend/.env.example",
|
||||
"backend/src/app.ts",
|
||||
"backend/src/config.ts",
|
||||
"backend/src/db/mysql.ts",
|
||||
"backend/src/routes/health.ts",
|
||||
"backend/src/server.ts",
|
||||
"backend/tests/backend-contract.test.mjs",
|
||||
"backend/tests/migration-contract.test.mjs",
|
||||
"backend/tests/mysql-pool-contract.test.mjs",
|
||||
"database/migrations/2026061601_m01b_core_schema.up.sql",
|
||||
"database/migrations/2026061601_m01b_core_schema.down.sql",
|
||||
"database/migrations/2026061601_m01b_core_schema.verify.sql",
|
||||
"database/seeds/2026061601_m01b_minimal_seed.sql",
|
||||
"deploy/pm2/ecosystem.config.cjs"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ $head = (& git rev-parse HEAD).Trim()
|
||||
$shortHead = (& git rev-parse --short HEAD).Trim()
|
||||
$backendBuild = if (Test-Path "backend/package.json") { "PROJECT_PRESENT_BUILD_NOT_RUN" } else { "SKIPPED_NO_PROJECT" }
|
||||
$adminBuild = if (Test-Path "admin/package.json") { "PROJECT_PRESENT_BUILD_NOT_RUN" } else { "SKIPPED_NO_PROJECT" }
|
||||
$migrationFiles = @(Get-ChildItem -Path "database/migrations" -Filter "*.sql" -File -ErrorAction SilentlyContinue)
|
||||
$databaseMigration = if ($migrationFiles.Count -gt 0) { "PROJECT_PRESENT_MIGRATION_NOT_RUN" } else { "SKIPPED_NO_MIGRATIONS" }
|
||||
|
||||
$rawText = @"
|
||||
{
|
||||
@@ -14,7 +16,7 @@ $rawText = @"
|
||||
"backendBuild": "$backendBuild",
|
||||
"adminBuild": "$adminBuild",
|
||||
"miniappMirror": "RECORDED_SOURCE_COMMIT_ONLY",
|
||||
"databaseMigration": "SKIPPED_NO_MIGRATIONS",
|
||||
"databaseMigration": "$databaseMigration",
|
||||
"deployed": false
|
||||
}
|
||||
"@
|
||||
@@ -55,8 +57,8 @@ if ((-not (Test-Path "admin/package.json")) -and $manifest.adminBuild -ne "SKIPP
|
||||
throw "Dry-run manifest should record missing admin project"
|
||||
}
|
||||
|
||||
if ($manifest.databaseMigration -ne "SKIPPED_NO_MIGRATIONS") {
|
||||
throw "Dry-run manifest should record skipped migrations until migrations exist"
|
||||
if ($manifest.databaseMigration -ne $databaseMigration) {
|
||||
throw "Dry-run manifest databaseMigration mismatch: $($manifest.databaseMigration)"
|
||||
}
|
||||
|
||||
Write-Host "PASS: release manifest dry-run is valid for current HEAD."
|
||||
|
||||
@@ -22,6 +22,13 @@ $requiredPaths = @(
|
||||
"docs/repository-completeness.md",
|
||||
"scripts/dev/windows/check-workspace.ps1",
|
||||
"backend/package-lock.json",
|
||||
"backend/src/db/mysql.ts",
|
||||
"backend/tests/migration-contract.test.mjs",
|
||||
"backend/tests/mysql-pool-contract.test.mjs",
|
||||
"database/migrations/2026061601_m01b_core_schema.up.sql",
|
||||
"database/migrations/2026061601_m01b_core_schema.down.sql",
|
||||
"database/migrations/2026061601_m01b_core_schema.verify.sql",
|
||||
"database/seeds/2026061601_m01b_minimal_seed.sql",
|
||||
"scripts/dev/windows/check-backend.ps1",
|
||||
"scripts/dev/windows/check-reference.ps1",
|
||||
"scripts/dev/windows/check-repo-completeness.ps1",
|
||||
|
||||
@@ -11,7 +11,7 @@ qipai_release_manifest_json() {
|
||||
local repo_dir="$1"
|
||||
local release_id="$2"
|
||||
local deployed="$3"
|
||||
local backend_build admin_build
|
||||
local backend_build admin_build database_migration
|
||||
|
||||
if [ -f "${repo_dir}/backend/package.json" ]; then
|
||||
backend_build="PROJECT_PRESENT_BUILD_NOT_RUN"
|
||||
@@ -25,6 +25,12 @@ qipai_release_manifest_json() {
|
||||
admin_build="SKIPPED_NO_PROJECT"
|
||||
fi
|
||||
|
||||
if find "${repo_dir}/database/migrations" -maxdepth 1 -type f -name '*.sql' | grep -q .; then
|
||||
database_migration="PROJECT_PRESENT_MIGRATION_NOT_RUN"
|
||||
else
|
||||
database_migration="SKIPPED_NO_MIGRATIONS"
|
||||
fi
|
||||
|
||||
cat <<EOF
|
||||
{
|
||||
"releaseId": "${release_id}",
|
||||
@@ -34,7 +40,7 @@ qipai_release_manifest_json() {
|
||||
"backendBuild": "${backend_build}",
|
||||
"adminBuild": "${admin_build}",
|
||||
"miniappMirror": "RECORDED_SOURCE_COMMIT_ONLY",
|
||||
"databaseMigration": "SKIPPED_NO_MIGRATIONS",
|
||||
"databaseMigration": "${database_migration}",
|
||||
"deployed": ${deployed}
|
||||
}
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user