feat: Add project type and status fields to project forms and views, including database migrations

This commit is contained in:
Chop
2025-06-04 22:53:33 +02:00
parent e136c9f0e8
commit 49d49b42f1
6 changed files with 138 additions and 6 deletions

View File

@@ -30,6 +30,8 @@ export default function initializeDatabase() {
wp TEXT,
contact TEXT,
notes TEXT,
project_type TEXT CHECK(project_type IN ('design', 'construction', 'design+construction')) DEFAULT 'design',
project_status TEXT CHECK(project_status IN ('registered', 'in_progress_design', 'in_progress_construction', 'fulfilled')) DEFAULT 'registered',
FOREIGN KEY (contract_id) REFERENCES contracts(contract_id)
);
@@ -98,4 +100,22 @@ export default function initializeDatabase() {
} catch (e) {
// Column already exists, ignore error
}
// Migration: Add project_type column to projects table
try {
db.exec(`
ALTER TABLE projects ADD COLUMN project_type TEXT CHECK(project_type IN ('design', 'construction', 'design+construction')) DEFAULT 'design';
`);
} catch (e) {
// Column already exists, ignore error
}
// Migration: Add project_status column to projects table
try {
db.exec(`
ALTER TABLE projects ADD COLUMN project_status TEXT CHECK(project_status IN ('registered', 'in_progress_design', 'in_progress_construction', 'fulfilled')) DEFAULT 'registered';
`);
} catch (e) {
// Column already exists, ignore error
}
}

View File

@@ -42,8 +42,8 @@ export function createProject(data) {
const stmt = db.prepare(`
INSERT INTO projects (
contract_id, project_name, project_number, address, plot, district, unit, city, investment_number, finish_date,
wp, contact, notes
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
wp, contact, notes, project_type, project_status
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`);
stmt.run(
data.contract_id,
@@ -58,7 +58,9 @@ export function createProject(data) {
data.finish_date,
data.wp,
data.contact,
data.notes
data.notes,
data.project_type || "design",
data.project_status || "registered"
);
}
@@ -66,7 +68,7 @@ export function updateProject(id, data) {
const stmt = db.prepare(`
UPDATE projects SET
contract_id = ?, project_name = ?, project_number = ?, address = ?, plot = ?, district = ?, unit = ?, city = ?,
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?
investment_number = ?, finish_date = ?, wp = ?, contact = ?, notes = ?, project_type = ?, project_status = ?
WHERE project_id = ?
`);
stmt.run(
@@ -83,6 +85,8 @@ export function updateProject(id, data) {
data.wp,
data.contact,
data.notes,
data.project_type || "design",
data.project_status || "registered",
id
);
}