first commit
This commit is contained in:
parent
e7365b06ac
commit
a9e21cbe3c
9 changed files with 874 additions and 320 deletions
235
scripts/migrate_vehicles.js
Normal file
235
scripts/migrate_vehicles.js
Normal file
|
|
@ -0,0 +1,235 @@
|
|||
import "dotenv/config";
|
||||
import mysql from "mysql2/promise";
|
||||
|
||||
const vehicles = [
|
||||
{
|
||||
name: "Audi A6 Premium",
|
||||
type: "LUXURY",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "audi_a6",
|
||||
baseFarePerDay: 12000,
|
||||
driverAllowancePerDay: 600,
|
||||
extraKmRate: 45,
|
||||
includedKmPerDay: 250,
|
||||
badge: "Executive",
|
||||
features: JSON.stringify(["Leather Interior", "Dual Climate", "Premium Audio", "Sunroof"])
|
||||
},
|
||||
{
|
||||
name: "BMW 7 Series",
|
||||
type: "LUXURY",
|
||||
seats: "4+1",
|
||||
luggage: "3 Bags",
|
||||
image: "bmw_7_series",
|
||||
baseFarePerDay: 25000,
|
||||
driverAllowancePerDay: 800,
|
||||
extraKmRate: 85,
|
||||
includedKmPerDay: 200,
|
||||
badge: "VVIP Choice",
|
||||
features: JSON.stringify(["Rear-seat Entertainment", "Massage Seats", "Quiet Cabin", "Chauffeur Driven"])
|
||||
},
|
||||
{
|
||||
name: "Mercedes S-Class",
|
||||
type: "LUXURY",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "mercedes_s_class",
|
||||
baseFarePerDay: 28000,
|
||||
driverAllowancePerDay: 800,
|
||||
extraKmRate: 90,
|
||||
includedKmPerDay: 200,
|
||||
badge: "Ultimate Luxury",
|
||||
features: JSON.stringify(["Ambient Lighting", "Burmester Sound", "Premium Chauffeur"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Fortuner 4x4",
|
||||
type: "SUV",
|
||||
seats: "6+1",
|
||||
luggage: "4 Bags",
|
||||
image: "fortuner",
|
||||
baseFarePerDay: 6500,
|
||||
driverAllowancePerDay: 500,
|
||||
extraKmRate: 25,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Advanture King",
|
||||
features: JSON.stringify(["Off-road capable", "Powerful AC", "Spacious", "Rugged Built"])
|
||||
},
|
||||
{
|
||||
name: "Innova Crysta",
|
||||
type: "MUV",
|
||||
seats: "7+1",
|
||||
luggage: "3 Bags",
|
||||
image: "innova_crysta",
|
||||
baseFarePerDay: 4500,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 18,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Best Seller",
|
||||
features: JSON.stringify(["Clean Interiors", "Captain Seats", "Smooth Ride", "Carrier Available"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Innova",
|
||||
type: "MUV",
|
||||
seats: "7+1",
|
||||
luggage: "2 Bags",
|
||||
image: "innova",
|
||||
baseFarePerDay: 3800,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 16,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Value MUV",
|
||||
features: JSON.stringify(["Comfortable", "Spacious", "Economical for Family"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Camry",
|
||||
type: "SEDAN",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "camry",
|
||||
baseFarePerDay: 4200,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 18,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Corporate Elite",
|
||||
features: JSON.stringify(["Hybrid Tech", "Quiet Ride", "Executive Space"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Etios",
|
||||
type: "SEDAN",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "etios",
|
||||
baseFarePerDay: 2800,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 13,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Economic",
|
||||
features: JSON.stringify(["Spacious Boot", "Good Legroom", "Standard AC"])
|
||||
},
|
||||
{
|
||||
name: "Swift Dzire",
|
||||
type: "SEDAN",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "dzire",
|
||||
baseFarePerDay: 2600,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 13,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Economic Choice",
|
||||
features: JSON.stringify(["Popular", "Quick Maneuver", "Efficient AC"])
|
||||
},
|
||||
{
|
||||
name: "Audi Q7 Luxury SUV",
|
||||
type: "SUV",
|
||||
seats: "6+1",
|
||||
luggage: "4 Bags",
|
||||
image: "audi_q7",
|
||||
baseFarePerDay: 15000,
|
||||
driverAllowancePerDay: 700,
|
||||
extraKmRate: 55,
|
||||
includedKmPerDay: 250,
|
||||
badge: "Luxury SUV",
|
||||
features: JSON.stringify(["Quattro 4x4", "Panoramic Sunroof", "Premium Audio", "Heated Seats"])
|
||||
},
|
||||
{
|
||||
name: "BMW 5 Series",
|
||||
type: "LUXURY",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "bmw_5_series",
|
||||
baseFarePerDay: 14000,
|
||||
driverAllowancePerDay: 600,
|
||||
extraKmRate: 50,
|
||||
includedKmPerDay: 250,
|
||||
badge: "Business Class",
|
||||
features: JSON.stringify(["Dynamic Drive", "Luxury Interiors", "Silent Hybrid", "Touchscreen Control"])
|
||||
},
|
||||
{
|
||||
name: "Mercedes E-Class",
|
||||
type: "LUXURY",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "mercedes_e_class",
|
||||
baseFarePerDay: 14500,
|
||||
driverAllowancePerDay: 600,
|
||||
extraKmRate: 52,
|
||||
includedKmPerDay: 250,
|
||||
badge: "Timeless Elegance",
|
||||
features: JSON.stringify(["Soft Close Doors", "Ambient Light", "Professional Driver", "WIFI Enabled"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Corolla Altis",
|
||||
type: "SEDAN",
|
||||
seats: "4+1",
|
||||
luggage: "2 Bags",
|
||||
image: "corolla_altis",
|
||||
baseFarePerDay: 3800,
|
||||
driverAllowancePerDay: 400,
|
||||
extraKmRate: 16,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Executive Sedan",
|
||||
features: JSON.stringify(["Durable", "Comfortable Suspension", "Clean Air Filter"])
|
||||
},
|
||||
{
|
||||
name: "Toyota Commuter",
|
||||
type: "VAN",
|
||||
seats: "12+1",
|
||||
luggage: "6 Bags",
|
||||
image: "toyota_commuter",
|
||||
baseFarePerDay: 8500,
|
||||
driverAllowancePerDay: 600,
|
||||
extraKmRate: 28,
|
||||
includedKmPerDay: 300,
|
||||
badge: "Large Group",
|
||||
features: JSON.stringify(["12 Seater", "High Ceiling", "Multiple Bags Space"])
|
||||
}
|
||||
];
|
||||
|
||||
async function runMigration() {
|
||||
const pool = mysql.createPool({
|
||||
host: process.env.DB_HOST || "localhost",
|
||||
user: process.env.DB_USER || "root",
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME || "roadrentals",
|
||||
});
|
||||
|
||||
try {
|
||||
console.log("Creating Vehicles table...");
|
||||
await pool.execute(`
|
||||
CREATE TABLE IF NOT EXISTS Vehicles (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
name VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(50),
|
||||
seats VARCHAR(20),
|
||||
luggage VARCHAR(50),
|
||||
image VARCHAR(255),
|
||||
baseFarePerDay INT,
|
||||
driverAllowancePerDay INT,
|
||||
extraKmRate INT,
|
||||
includedKmPerDay INT,
|
||||
badge VARCHAR(100),
|
||||
features TEXT,
|
||||
isAvailable BOOLEAN DEFAULT TRUE,
|
||||
createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
console.log("Seeding vehicles...");
|
||||
for (const v of vehicles) {
|
||||
await pool.execute(
|
||||
`INSERT INTO Vehicles (name, type, seats, luggage, image, baseFarePerDay, driverAllowancePerDay, extraKmRate, includedKmPerDay, badge, features)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[v.name, v.type, v.seats, v.luggage, v.image, v.baseFarePerDay, v.driverAllowancePerDay, v.extraKmRate, v.includedKmPerDay, v.badge, v.features]
|
||||
);
|
||||
}
|
||||
|
||||
console.log("Migration successful!");
|
||||
} catch (error) {
|
||||
console.error("Migration failed:", error);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
runMigration();
|
||||
Loading…
Add table
Add a link
Reference in a new issue