This commit is contained in:
2026-01-23 20:35:40 +03:00
parent cf3b0e48ec
commit 66c151653e
137 changed files with 41495 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
-- CreateTable
CREATE TABLE "users" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"username" TEXT NOT NULL,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
"status" TEXT NOT NULL DEFAULT 'active',
"authLevel" INTEGER NOT NULL,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"editDate" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "customers" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"phone" TEXT,
"email" TEXT,
"address" TEXT,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "vehicles" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"plateNumber" TEXT NOT NULL,
"bodyType" TEXT NOT NULL,
"manufacturer" TEXT NOT NULL,
"model" TEXT NOT NULL,
"trim" TEXT,
"year" INTEGER NOT NULL,
"transmission" TEXT NOT NULL,
"fuel" TEXT NOT NULL,
"cylinders" INTEGER,
"engineDisplacement" REAL,
"useType" TEXT NOT NULL,
"ownerId" INTEGER NOT NULL,
"lastVisitDate" DATETIME,
"suggestedNextVisitDate" DATETIME,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "vehicles_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "customers" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "maintenance_visits" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"vehicleId" INTEGER NOT NULL,
"customerId" INTEGER NOT NULL,
"maintenanceType" TEXT NOT NULL,
"description" TEXT NOT NULL,
"cost" REAL NOT NULL,
"paymentStatus" TEXT NOT NULL DEFAULT 'pending',
"kilometers" INTEGER NOT NULL,
"visitDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"nextVisitDelay" INTEGER NOT NULL,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "maintenance_visits_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "maintenance_visits_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customers" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateTable
CREATE TABLE "expenses" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"description" TEXT NOT NULL,
"category" TEXT NOT NULL,
"amount" REAL NOT NULL,
"expenseDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL
);
-- CreateTable
CREATE TABLE "income" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"maintenanceVisitId" INTEGER NOT NULL,
"amount" REAL NOT NULL,
"incomeDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "income_maintenanceVisitId_fkey" FOREIGN KEY ("maintenanceVisitId") REFERENCES "maintenance_visits" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- CreateIndex
CREATE UNIQUE INDEX "users_username_key" ON "users"("username");
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE UNIQUE INDEX "vehicles_plateNumber_key" ON "vehicles"("plateNumber");

View File

@@ -0,0 +1,45 @@
/*
Warnings:
- You are about to drop the column `maintenanceType` on the `maintenance_visits` table. All the data in the column will be lost.
- Added the required column `maintenanceTypeId` to the `maintenance_visits` table without a default value. This is not possible if the table is not empty.
*/
-- CreateTable
CREATE TABLE "maintenance_types" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"description" TEXT,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL
);
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_maintenance_visits" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"vehicleId" INTEGER NOT NULL,
"customerId" INTEGER NOT NULL,
"maintenanceTypeId" INTEGER NOT NULL,
"description" TEXT NOT NULL,
"cost" REAL NOT NULL,
"paymentStatus" TEXT NOT NULL DEFAULT 'pending',
"kilometers" INTEGER NOT NULL,
"visitDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"nextVisitDelay" INTEGER NOT NULL,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "maintenance_visits_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "maintenance_visits_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customers" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "maintenance_visits_maintenanceTypeId_fkey" FOREIGN KEY ("maintenanceTypeId") REFERENCES "maintenance_types" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
INSERT INTO "new_maintenance_visits" ("cost", "createdDate", "customerId", "description", "id", "kilometers", "nextVisitDelay", "paymentStatus", "updateDate", "vehicleId", "visitDate") SELECT "cost", "createdDate", "customerId", "description", "id", "kilometers", "nextVisitDelay", "paymentStatus", "updateDate", "vehicleId", "visitDate" FROM "maintenance_visits";
DROP TABLE "maintenance_visits";
ALTER TABLE "new_maintenance_visits" RENAME TO "maintenance_visits";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;
-- CreateIndex
CREATE UNIQUE INDEX "maintenance_types_name_key" ON "maintenance_types"("name");

View File

@@ -0,0 +1,31 @@
/*
Warnings:
- You are about to drop the column `maintenanceTypeId` on the `maintenance_visits` table. All the data in the column will be lost.
- Added the required column `maintenanceJobs` to the `maintenance_visits` table without a default value. This is not possible if the table is not empty.
*/
-- RedefineTables
PRAGMA defer_foreign_keys=ON;
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_maintenance_visits" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"vehicleId" INTEGER NOT NULL,
"customerId" INTEGER NOT NULL,
"maintenanceJobs" TEXT NOT NULL,
"description" TEXT NOT NULL,
"cost" REAL NOT NULL,
"paymentStatus" TEXT NOT NULL DEFAULT 'pending',
"kilometers" INTEGER NOT NULL,
"visitDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"nextVisitDelay" INTEGER NOT NULL,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "maintenance_visits_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "maintenance_visits_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customers" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
INSERT INTO "new_maintenance_visits" ("cost", "createdDate", "customerId", "description", "id", "kilometers", "nextVisitDelay", "paymentStatus", "updateDate", "vehicleId", "visitDate") SELECT "cost", "createdDate", "customerId", "description", "id", "kilometers", "nextVisitDelay", "paymentStatus", "updateDate", "vehicleId", "visitDate" FROM "maintenance_visits";
DROP TABLE "maintenance_visits";
ALTER TABLE "new_maintenance_visits" RENAME TO "maintenance_visits";
PRAGMA foreign_keys=ON;
PRAGMA defer_foreign_keys=OFF;

View File

@@ -0,0 +1,13 @@
-- CreateTable
CREATE TABLE "car_dataset" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"manufacturer" TEXT NOT NULL,
"model" TEXT NOT NULL,
"bodyType" TEXT NOT NULL,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "car_dataset_manufacturer_model_key" ON "car_dataset"("manufacturer", "model");

View File

@@ -0,0 +1,59 @@
-- CreateTable
CREATE TABLE "maintenance_types" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"name" TEXT NOT NULL,
"description" TEXT,
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL
);
-- CreateIndex
CREATE UNIQUE INDEX "maintenance_types_name_key" ON "maintenance_types"("name");
-- Add new column to maintenance_visits for JSON maintenance jobs
ALTER TABLE "maintenance_visits" ADD COLUMN "maintenanceJobs" TEXT;
-- Create default maintenance types (will be populated by seed script)
-- Note: The seed script will handle populating maintenance types
-- Convert existing maintenance visits to use JSON format
-- First, let's handle the case where maintenanceType column exists (old format)
UPDATE "maintenance_visits"
SET "maintenanceJobs" = '[{"typeId": 1, "job": "' || COALESCE("maintenanceType", 'صيانة عامة') || '", "notes": ""}]'
WHERE "maintenanceJobs" IS NULL;
-- Set default JSON for any remaining NULL values
UPDATE "maintenance_visits"
SET "maintenanceJobs" = '[{"typeId": 1, "job": "صيانة عامة", "notes": ""}]'
WHERE "maintenanceJobs" IS NULL OR "maintenanceJobs" = '';
-- Make maintenanceJobs NOT NULL and remove old maintenanceType column if it exists
-- Note: SQLite doesn't support ALTER COLUMN, so we need to recreate the table
CREATE TABLE "maintenance_visits_new" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"vehicleId" INTEGER NOT NULL,
"customerId" INTEGER NOT NULL,
"maintenanceJobs" TEXT NOT NULL,
"description" TEXT NOT NULL,
"cost" REAL NOT NULL,
"paymentStatus" TEXT NOT NULL DEFAULT 'pending',
"kilometers" INTEGER NOT NULL,
"visitDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"nextVisitDelay" INTEGER NOT NULL,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL,
CONSTRAINT "maintenance_visits_vehicleId_fkey" FOREIGN KEY ("vehicleId") REFERENCES "vehicles" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT "maintenance_visits_customerId_fkey" FOREIGN KEY ("customerId") REFERENCES "customers" ("id") ON DELETE CASCADE ON UPDATE CASCADE
);
-- Copy data from old table to new table (excluding old maintenanceType column)
INSERT INTO "maintenance_visits_new"
SELECT "id", "vehicleId", "customerId", "maintenanceJobs", "description", "cost", "paymentStatus", "kilometers", "visitDate", "nextVisitDelay", "createdDate", "updateDate"
FROM "maintenance_visits";
-- Drop old table and rename new table
DROP TABLE "maintenance_visits";
ALTER TABLE "maintenance_visits_new" RENAME TO "maintenance_visits";
-- Note: Income table foreign key constraint should still work as it references maintenance_visits(id)

View File

@@ -0,0 +1,19 @@
-- Migration: Add Settings Table
-- Description: Creates settings table for application configuration (date format, currency, number format)
CREATE TABLE IF NOT EXISTS "settings" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"key" TEXT NOT NULL UNIQUE,
"value" TEXT NOT NULL,
"description" TEXT,
"createdDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updateDate" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Insert default settings
INSERT OR IGNORE INTO "settings" ("key", "value", "description") VALUES
('dateFormat', 'ar-SA', 'Date format locale (ar-SA or en-US)'),
('currency', 'JOD', 'Currency code (JOD, USD, EUR, etc.)'),
('numberFormat', 'ar-SA', 'Number format locale (ar-SA or en-US)'),
('currencySymbol', 'د.أ', 'Currency symbol display'),
('dateDisplayFormat', 'dd/MM/yyyy', 'Date display format pattern');

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "sqlite"