准考证编排
This commit is contained in:
@@ -114,6 +114,64 @@ export function createSqliteAdapter(context) {
|
||||
connection.exec('CREATE UNIQUE INDEX IF NOT EXISTS uq_users_candidate_number ON users(candidate_number)');
|
||||
|
||||
const existingSystem = connection.prepare('SELECT * FROM schema_metadata WHERE id = 1').get();
|
||||
if (existingSystem && Number(existingSystem.schema_version || 1) < 9) {
|
||||
const extension = seed();
|
||||
connection.exec('PRAGMA foreign_keys = OFF;');
|
||||
connection.exec('BEGIN IMMEDIATE');
|
||||
try {
|
||||
connection.exec(`
|
||||
DROP TABLE IF EXISTS admit_card_subjects;
|
||||
DROP TABLE IF EXISTS admit_cards;
|
||||
DROP TABLE IF EXISTS exam_arrangement_plans;
|
||||
DROP TABLE IF EXISTS admission_number_rules;
|
||||
CREATE TABLE admission_number_rules (
|
||||
id TEXT PRIMARY KEY, code TEXT NOT NULL UNIQUE, name TEXT NOT NULL, description TEXT NOT NULL,
|
||||
separator TEXT NOT NULL DEFAULT '', segments_json TEXT NOT NULL, example TEXT NOT NULL,
|
||||
active INTEGER NOT NULL DEFAULT 1 CHECK (active IN (0, 1)), created_at TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE TABLE exam_arrangement_plans (
|
||||
id TEXT PRIMARY KEY, exam_id TEXT NOT NULL UNIQUE REFERENCES exams(id) ON DELETE CASCADE,
|
||||
number_rule_id TEXT NOT NULL REFERENCES admission_number_rules(id),
|
||||
mixing_scope TEXT NOT NULL CHECK (mixing_scope IN ('class', 'school', 'district', 'city', 'province')),
|
||||
random_seed TEXT NOT NULL, candidate_count INTEGER NOT NULL CHECK (candidate_count >= 0),
|
||||
center_count INTEGER NOT NULL CHECK (center_count >= 0),
|
||||
subject_assignment_count INTEGER NOT NULL CHECK (subject_assignment_count >= 0),
|
||||
subject_combination_count INTEGER NOT NULL CHECK (subject_combination_count >= 0),
|
||||
same_school_center_rate REAL NOT NULL, warnings_json TEXT NOT NULL,
|
||||
generated_by TEXT REFERENCES users(id) ON DELETE SET NULL, generated_at TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE TABLE admit_cards (
|
||||
registration_id TEXT PRIMARY KEY REFERENCES registrations(id) ON DELETE CASCADE,
|
||||
plan_id TEXT NOT NULL REFERENCES exam_arrangement_plans(id) ON DELETE CASCADE,
|
||||
card_number TEXT NOT NULL UNIQUE, center_id TEXT REFERENCES test_centers(id) ON DELETE SET NULL,
|
||||
test_center TEXT NOT NULL, generated_at TEXT NOT NULL
|
||||
) STRICT;
|
||||
CREATE TABLE admit_card_subjects (
|
||||
registration_id TEXT NOT NULL REFERENCES admit_cards(registration_id) ON DELETE CASCADE,
|
||||
subject_id TEXT NOT NULL REFERENCES exam_subjects(id) ON DELETE CASCADE,
|
||||
room_id TEXT REFERENCES test_rooms(id) ON DELETE SET NULL, room TEXT NOT NULL, room_code TEXT NOT NULL,
|
||||
exam_room_code TEXT NOT NULL, seat TEXT NOT NULL, subject_signature TEXT NOT NULL,
|
||||
PRIMARY KEY (registration_id, subject_id), UNIQUE (subject_id, room_id, seat)
|
||||
) STRICT;
|
||||
CREATE INDEX idx_arrangement_plans_exam ON exam_arrangement_plans(exam_id, generated_at);
|
||||
CREATE INDEX idx_admit_subjects_room ON admit_card_subjects(subject_id, room_id, seat);
|
||||
`);
|
||||
for (const rule of extension.admissionNumberRules) connection.prepare(
|
||||
`INSERT INTO admission_number_rules (
|
||||
id, code, name, description, separator, segments_json, example, active, created_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
||||
).run(rule.id, rule.code, rule.name, rule.description, rule.separator || '', JSON.stringify(rule.segments || []),
|
||||
rule.example || '', rule.active === false ? 0 : 1, rule.createdAt);
|
||||
connection.prepare('UPDATE schema_metadata SET schema_version = 9, app_version = 9 WHERE id = 1').run();
|
||||
connection.exec('COMMIT');
|
||||
} catch (error) {
|
||||
connection.exec('ROLLBACK');
|
||||
connection.close();
|
||||
throw error;
|
||||
} finally {
|
||||
try { connection.exec('PRAGMA foreign_keys = ON;'); } catch {}
|
||||
}
|
||||
}
|
||||
if (existingSystem && Number(existingSystem.app_version || 1) < 2) {
|
||||
const extension = seed();
|
||||
connection.exec('BEGIN IMMEDIATE');
|
||||
@@ -271,7 +329,7 @@ export function createSqliteAdapter(context) {
|
||||
try {
|
||||
connection.prepare(`
|
||||
INSERT INTO schema_metadata (id, schema_version, app_version, self_registration_enabled, created_at)
|
||||
VALUES (1, 7, ?, ?, ?)
|
||||
VALUES (1, 9, ?, ?, ?)
|
||||
`).run(Number(initialState.meta?.version || 1), initialState.settings?.selfRegistrationEnabled ? 1 : 0, initialState.meta?.createdAt || new Date().toISOString());
|
||||
for (const item of buildSeedOperations(initialState)) connection.prepare(item.sql).run(...item.params);
|
||||
connection.exec('COMMIT');
|
||||
|
||||
Reference in New Issue
Block a user