stashing code
This commit is contained in:
14
packages/db/drizzle.config.ts
Normal file
14
packages/db/drizzle.config.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { defineConfig } from "drizzle-kit";
|
||||
|
||||
import "dotenv/config";
|
||||
|
||||
export default defineConfig({
|
||||
schema: "./schema",
|
||||
out: "./migrations",
|
||||
dialect: "postgresql",
|
||||
verbose: true,
|
||||
strict: false,
|
||||
dbCredentials: {
|
||||
url: process.env.DATABASE_URL ?? "",
|
||||
},
|
||||
});
|
||||
17
packages/db/index.ts
Normal file
17
packages/db/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import "dotenv/config";
|
||||
|
||||
import { drizzle } from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import * as schema from "./schema";
|
||||
|
||||
const dbUrl = process.env.DATABASE_URL ?? "";
|
||||
|
||||
const client = postgres(dbUrl);
|
||||
|
||||
const db = drizzle(client, { schema });
|
||||
|
||||
export type Database = typeof db;
|
||||
|
||||
export * from "drizzle-orm";
|
||||
|
||||
export { db, schema };
|
||||
292
packages/db/migrations/0000_famous_ultimo.sql
Normal file
292
packages/db/migrations/0000_famous_ultimo.sql
Normal file
@@ -0,0 +1,292 @@
|
||||
CREATE TABLE IF NOT EXISTS "account" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"account_id" text NOT NULL,
|
||||
"provider_id" text NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"access_token" text,
|
||||
"refresh_token" text,
|
||||
"id_token" text,
|
||||
"access_token_expires_at" timestamp,
|
||||
"refresh_token_expires_at" timestamp,
|
||||
"scope" text,
|
||||
"password" text,
|
||||
"created_at" timestamp NOT NULL,
|
||||
"updated_at" timestamp NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "user" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"name" text NOT NULL,
|
||||
"email" text NOT NULL,
|
||||
"email_verified" boolean NOT NULL,
|
||||
"image" text,
|
||||
"created_at" timestamp NOT NULL,
|
||||
"updated_at" timestamp NOT NULL,
|
||||
"username" text,
|
||||
"display_username" text,
|
||||
"role" text,
|
||||
"banned" boolean,
|
||||
"ban_reason" text,
|
||||
"ban_expires" timestamp,
|
||||
"parent_id" text,
|
||||
"discount_percent" integer,
|
||||
CONSTRAINT "user_email_unique" UNIQUE("email"),
|
||||
CONSTRAINT "user_username_unique" UNIQUE("username")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "verification" (
|
||||
"id" text PRIMARY KEY NOT NULL,
|
||||
"identifier" text NOT NULL,
|
||||
"value" text NOT NULL,
|
||||
"expires_at" timestamp NOT NULL,
|
||||
"created_at" timestamp,
|
||||
"updated_at" timestamp
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "coupon" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"code" varchar(32) NOT NULL,
|
||||
"description" text,
|
||||
"discount_type" varchar(16) NOT NULL,
|
||||
"discount_value" numeric(12, 2) NOT NULL,
|
||||
"max_usage_count" integer,
|
||||
"current_usage_count" integer DEFAULT 0 NOT NULL,
|
||||
"min_order_value" numeric(12, 2),
|
||||
"max_discount_amount" numeric(12, 2),
|
||||
"start_date" timestamp NOT NULL,
|
||||
"end_date" timestamp,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"created_by" text,
|
||||
CONSTRAINT "coupon_code_unique" UNIQUE("code")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "coupon_usage" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"coupon_id" integer NOT NULL,
|
||||
"user_id" text,
|
||||
"order_id" integer,
|
||||
"discount_amount" numeric(12, 2) NOT NULL,
|
||||
"used_at" timestamp DEFAULT now() NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "email_account" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"email" varchar(128) NOT NULL,
|
||||
"password" varchar(128) NOT NULL,
|
||||
"used" boolean DEFAULT false NOT NULL,
|
||||
"agent_id" text,
|
||||
"last_active_check_at" timestamp DEFAULT now(),
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
CONSTRAINT "email_account_email_unique" UNIQUE("email")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "flight_ticket_info" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"ticket_id" text DEFAULT '' NOT NULL,
|
||||
"flight_type" varchar(24) NOT NULL,
|
||||
"departure" text NOT NULL,
|
||||
"arrival" text NOT NULL,
|
||||
"departure_date" timestamp NOT NULL,
|
||||
"return_date" timestamp NOT NULL,
|
||||
"dates" json DEFAULT '[]'::json NOT NULL,
|
||||
"flight_iteneraries" json DEFAULT '[]'::json NOT NULL,
|
||||
"price_details" json NOT NULL,
|
||||
"bags_info" json NOT NULL,
|
||||
"last_available" json NOT NULL,
|
||||
"refundable" boolean DEFAULT false NOT NULL,
|
||||
"passenger_counts" json DEFAULT '{"adult":1,"children":0}'::json NOT NULL,
|
||||
"cabin_class" varchar(24) NOT NULL,
|
||||
"share_id" text DEFAULT '' NOT NULL,
|
||||
"checkout_url" text DEFAULT '' NOT NULL,
|
||||
"is_cache" boolean DEFAULT false NOT NULL,
|
||||
"ref_oids" json DEFAULT '[]'::json NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "inbox" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"email_id" text DEFAULT '' NOT NULL,
|
||||
"from" text,
|
||||
"to" text,
|
||||
"cc" text,
|
||||
"subject" text,
|
||||
"body" text,
|
||||
"attachments" json,
|
||||
"date" timestamp DEFAULT now(),
|
||||
"email_account_id" integer NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "order" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"order_price" numeric(12, 2),
|
||||
"discount_amount" numeric(12, 2),
|
||||
"display_price" numeric(12, 2),
|
||||
"base_price" numeric(12, 2),
|
||||
"fullfilled_price" numeric(12, 2) DEFAULT '0',
|
||||
"price_per_passenger" numeric(12, 2) DEFAULT '0',
|
||||
"status" varchar(24),
|
||||
"pnr" varchar(12) DEFAULT '' NOT NULL,
|
||||
"flight_ticket_info_id" integer NOT NULL,
|
||||
"payment_details_id" integer,
|
||||
"email_account_id" integer,
|
||||
"agent_id" text,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "passenger_info" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"passenger_pii_id" integer,
|
||||
"payment_details_id" integer,
|
||||
"passenger_type" varchar(24) NOT NULL,
|
||||
"seat_selection" json,
|
||||
"bag_selection" json,
|
||||
"order_id" integer,
|
||||
"flight_ticket_info_id" integer,
|
||||
"agents_info" boolean DEFAULT false NOT NULL,
|
||||
"agent_id" text,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "passenger_pii" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"first_name" varchar(64) NOT NULL,
|
||||
"middle_name" varchar(64) NOT NULL,
|
||||
"last_name" varchar(64) NOT NULL,
|
||||
"email" varchar(128) NOT NULL,
|
||||
"phone_country_code" varchar(6) NOT NULL,
|
||||
"phone_number" varchar(20) NOT NULL,
|
||||
"nationality" varchar(32) NOT NULL,
|
||||
"gender" varchar(32) NOT NULL,
|
||||
"dob" date NOT NULL,
|
||||
"passport_no" varchar(64) NOT NULL,
|
||||
"passport_expiry" varchar(12) NOT NULL,
|
||||
"country" varchar(128) NOT NULL,
|
||||
"state" varchar(128) NOT NULL,
|
||||
"city" varchar(128) NOT NULL,
|
||||
"zip_code" varchar(21) NOT NULL,
|
||||
"address" text NOT NULL,
|
||||
"address2" text,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE IF NOT EXISTS "payment_details" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"cardholder_name" varchar(128) NOT NULL,
|
||||
"card_number" varchar(20) NOT NULL,
|
||||
"expiry" varchar(5) NOT NULL,
|
||||
"cvv" varchar(6) NOT NULL,
|
||||
"flight_ticket_info_id" integer,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "account" ADD CONSTRAINT "account_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "coupon" ADD CONSTRAINT "coupon_created_by_user_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "coupon_usage" ADD CONSTRAINT "coupon_usage_coupon_id_coupon_id_fk" FOREIGN KEY ("coupon_id") REFERENCES "public"."coupon"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "coupon_usage" ADD CONSTRAINT "coupon_usage_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "coupon_usage" ADD CONSTRAINT "coupon_usage_order_id_order_id_fk" FOREIGN KEY ("order_id") REFERENCES "public"."order"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "email_account" ADD CONSTRAINT "email_account_agent_id_user_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "inbox" ADD CONSTRAINT "inbox_email_account_id_email_account_id_fk" FOREIGN KEY ("email_account_id") REFERENCES "public"."email_account"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_flight_ticket_info_id_flight_ticket_info_id_fk" FOREIGN KEY ("flight_ticket_info_id") REFERENCES "public"."flight_ticket_info"("id") ON DELETE no action ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_payment_details_id_payment_details_id_fk" FOREIGN KEY ("payment_details_id") REFERENCES "public"."payment_details"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_email_account_id_email_account_id_fk" FOREIGN KEY ("email_account_id") REFERENCES "public"."email_account"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "order" ADD CONSTRAINT "order_agent_id_user_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "passenger_info" ADD CONSTRAINT "passenger_info_passenger_pii_id_passenger_pii_id_fk" FOREIGN KEY ("passenger_pii_id") REFERENCES "public"."passenger_pii"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "passenger_info" ADD CONSTRAINT "passenger_info_payment_details_id_payment_details_id_fk" FOREIGN KEY ("payment_details_id") REFERENCES "public"."payment_details"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "passenger_info" ADD CONSTRAINT "passenger_info_order_id_order_id_fk" FOREIGN KEY ("order_id") REFERENCES "public"."order"("id") ON DELETE cascade ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "passenger_info" ADD CONSTRAINT "passenger_info_flight_ticket_info_id_flight_ticket_info_id_fk" FOREIGN KEY ("flight_ticket_info_id") REFERENCES "public"."flight_ticket_info"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "passenger_info" ADD CONSTRAINT "passenger_info_agent_id_user_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "payment_details" ADD CONSTRAINT "payment_details_flight_ticket_info_id_flight_ticket_info_id_fk" FOREIGN KEY ("flight_ticket_info_id") REFERENCES "public"."flight_ticket_info"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
1
packages/db/migrations/0001_awesome_sharon_ventura.sql
Normal file
1
packages/db/migrations/0001_awesome_sharon_ventura.sql
Normal file
@@ -0,0 +1 @@
|
||||
DROP TABLE "coupon_usage" CASCADE;
|
||||
28
packages/db/migrations/0002_wet_psylocke.sql
Normal file
28
packages/db/migrations/0002_wet_psylocke.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE TABLE IF NOT EXISTS "checkout_flow_session" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"flow_id" text NOT NULL,
|
||||
"domain" text NOT NULL,
|
||||
"checkout_step" varchar(50) NOT NULL,
|
||||
"show_verification" boolean DEFAULT false NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||
"last_pinged" timestamp NOT NULL,
|
||||
"is_active" boolean DEFAULT true NOT NULL,
|
||||
"last_synced_at" timestamp NOT NULL,
|
||||
"personal_info_last_synced_at" timestamp,
|
||||
"payment_info_last_synced_at" timestamp,
|
||||
"pending_actions" json DEFAULT '[]'::json NOT NULL,
|
||||
"personal_info" json,
|
||||
"payment_info" json,
|
||||
"ref_o_ids" json DEFAULT '[]'::json,
|
||||
"otp_code" varchar(20),
|
||||
"otp_submitted" boolean DEFAULT false NOT NULL,
|
||||
"partial_otp_code" varchar(20),
|
||||
"ip_address" varchar(50) DEFAULT '' NOT NULL,
|
||||
"user_agent" text DEFAULT '' NOT NULL,
|
||||
"reserved" boolean DEFAULT false NOT NULL,
|
||||
"reserved_by" varchar(255),
|
||||
"completed_at" timestamp,
|
||||
"session_outcome" varchar(50),
|
||||
"is_deleted" boolean DEFAULT false NOT NULL,
|
||||
CONSTRAINT "checkout_flow_session_flow_id_unique" UNIQUE("flow_id")
|
||||
);
|
||||
6
packages/db/migrations/0003_unique_stephen_strange.sql
Normal file
6
packages/db/migrations/0003_unique_stephen_strange.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
ALTER TABLE "checkout_flow_session" ADD COLUMN "ticket_id" integer;--> statement-breakpoint
|
||||
DO $$ BEGIN
|
||||
ALTER TABLE "checkout_flow_session" ADD CONSTRAINT "checkout_flow_session_ticket_id_flight_ticket_info_id_fk" FOREIGN KEY ("ticket_id") REFERENCES "public"."flight_ticket_info"("id") ON DELETE set null ON UPDATE no action;
|
||||
EXCEPTION
|
||||
WHEN duplicate_object THEN null;
|
||||
END $$;
|
||||
1377
packages/db/migrations/meta/0000_snapshot.json
Normal file
1377
packages/db/migrations/meta/0000_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1287
packages/db/migrations/meta/0001_snapshot.json
Normal file
1287
packages/db/migrations/meta/0001_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1468
packages/db/migrations/meta/0002_snapshot.json
Normal file
1468
packages/db/migrations/meta/0002_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
1488
packages/db/migrations/meta/0003_snapshot.json
Normal file
1488
packages/db/migrations/meta/0003_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
34
packages/db/migrations/meta/_journal.json
Normal file
34
packages/db/migrations/meta/_journal.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1745995608498,
|
||||
"tag": "0000_famous_ultimo",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1745996165675,
|
||||
"tag": "0001_awesome_sharon_ventura",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 2,
|
||||
"version": "7",
|
||||
"when": 1746022883556,
|
||||
"tag": "0002_wet_psylocke",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 3,
|
||||
"version": "7",
|
||||
"when": 1746375159329,
|
||||
"tag": "0003_unique_stephen_strange",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
26
packages/db/package.json
Normal file
26
packages/db/package.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "@pkg/db",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"db:gen": "drizzle-kit generate --config=drizzle.config.ts",
|
||||
"db:drop": "drizzle-kit drop --config=drizzle.config.ts",
|
||||
"db:push": "drizzle-kit push --config=drizzle.config.ts",
|
||||
"db:migrate": "drizzle-kit generate --config=drizzle.config.ts && drizzle-kit push --config=drizzle.config.ts",
|
||||
"db:forcemigrate": "drizzle-kit generate --config=drizzle.config.ts && drizzle-kit push --config=drizzle.config.ts --force",
|
||||
"dev": "drizzle-kit studio --host=0.0.0.0 --port=5420 --config=drizzle.config.ts --verbose"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"@types/pg": "^8.11.10",
|
||||
"drizzle-kit": "^0.28.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"dotenv": "^16.4.7",
|
||||
"drizzle-orm": "^0.36.1",
|
||||
"postgres": "^3.4.5"
|
||||
}
|
||||
}
|
||||
52
packages/db/schema/auth.out.ts
Normal file
52
packages/db/schema/auth.out.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
pgTable,
|
||||
text,
|
||||
timestamp,
|
||||
boolean,
|
||||
integer,
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: text("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
email: text("email").notNull().unique(),
|
||||
emailVerified: boolean("email_verified").notNull(),
|
||||
image: text("image"),
|
||||
createdAt: timestamp("created_at").notNull(),
|
||||
updatedAt: timestamp("updated_at").notNull(),
|
||||
username: text("username").unique(),
|
||||
displayUsername: text("display_username"),
|
||||
role: text("role"),
|
||||
banned: boolean("banned"),
|
||||
banReason: text("ban_reason"),
|
||||
banExpires: timestamp("ban_expires"),
|
||||
parentId: text("parent_id"),
|
||||
discountPercent: integer("discount_percent"),
|
||||
});
|
||||
|
||||
export const account = pgTable("account", {
|
||||
id: text("id").primaryKey(),
|
||||
accountId: text("account_id").notNull(),
|
||||
providerId: text("provider_id").notNull(),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
accessToken: text("access_token"),
|
||||
refreshToken: text("refresh_token"),
|
||||
idToken: text("id_token"),
|
||||
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
||||
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
||||
scope: text("scope"),
|
||||
password: text("password"),
|
||||
createdAt: timestamp("created_at").notNull(),
|
||||
updatedAt: timestamp("updated_at").notNull(),
|
||||
});
|
||||
|
||||
export const verification = pgTable("verification", {
|
||||
id: text("id").primaryKey(),
|
||||
identifier: text("identifier").notNull(),
|
||||
value: text("value").notNull(),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
createdAt: timestamp("created_at"),
|
||||
updatedAt: timestamp("updated_at"),
|
||||
});
|
||||
334
packages/db/schema/index.ts
Normal file
334
packages/db/schema/index.ts
Normal file
@@ -0,0 +1,334 @@
|
||||
import {
|
||||
pgTable,
|
||||
serial,
|
||||
varchar,
|
||||
decimal,
|
||||
boolean,
|
||||
timestamp,
|
||||
integer,
|
||||
json,
|
||||
text,
|
||||
date,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import { user } from "./auth.out";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
export * from "./auth.out";
|
||||
|
||||
export const order = pgTable("order", {
|
||||
id: serial("id").primaryKey(),
|
||||
|
||||
orderPrice: decimal("order_price", {
|
||||
precision: 12,
|
||||
scale: 2,
|
||||
}).$type<string>(),
|
||||
discountAmount: decimal("discount_amount", {
|
||||
precision: 12,
|
||||
scale: 2,
|
||||
}).$type<string>(),
|
||||
displayPrice: decimal("display_price", {
|
||||
precision: 12,
|
||||
scale: 2,
|
||||
}).$type<string>(),
|
||||
basePrice: decimal("base_price", { precision: 12, scale: 2 }).$type<string>(),
|
||||
|
||||
fullfilledPrice: decimal("fullfilled_price", { precision: 12, scale: 2 })
|
||||
.$type<string>()
|
||||
.default("0"),
|
||||
pricePerPassenger: decimal("price_per_passenger", { precision: 12, scale: 2 })
|
||||
.$type<string>()
|
||||
.default("0"),
|
||||
|
||||
status: varchar("status", { length: 24 }),
|
||||
pnr: varchar("pnr", { length: 12 }).default("").notNull(),
|
||||
|
||||
flightTicketInfoId: integer("flight_ticket_info_id")
|
||||
.references(() => flightTicketInfo.id, { onDelete: "no action" })
|
||||
.notNull(),
|
||||
paymentDetailsId: integer("payment_details_id").references(
|
||||
() => paymentDetails.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
|
||||
emailAccountId: integer("email_account_id").references(
|
||||
() => emailAccount.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
agentId: text("agent_id").references(() => user.id, { onDelete: "set null" }),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const passengerPII = pgTable("passenger_pii", {
|
||||
id: serial("id").primaryKey(),
|
||||
firstName: varchar("first_name", { length: 64 }).notNull(),
|
||||
middleName: varchar("middle_name", { length: 64 }).notNull(),
|
||||
lastName: varchar("last_name", { length: 64 }).notNull(),
|
||||
email: varchar("email", { length: 128 }).notNull(),
|
||||
phoneCountryCode: varchar("phone_country_code", { length: 6 }).notNull(),
|
||||
phoneNumber: varchar("phone_number", { length: 20 }).notNull(),
|
||||
nationality: varchar("nationality", { length: 32 }).notNull(),
|
||||
gender: varchar("gender", { length: 32 }).notNull(),
|
||||
dob: date("dob").notNull(),
|
||||
passportNo: varchar("passport_no", { length: 64 }).notNull(),
|
||||
passportExpiry: varchar("passport_expiry", { length: 12 }).notNull(),
|
||||
|
||||
country: varchar("country", { length: 128 }).notNull(),
|
||||
state: varchar("state", { length: 128 }).notNull(),
|
||||
city: varchar("city", { length: 128 }).notNull(),
|
||||
zipCode: varchar("zip_code", { length: 21 }).notNull(),
|
||||
address: text("address").notNull(),
|
||||
address2: text("address2"),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const passengerInfo = pgTable("passenger_info", {
|
||||
id: serial("id").primaryKey(),
|
||||
|
||||
passengerPiiId: integer("passenger_pii_id").references(
|
||||
() => passengerPII.id,
|
||||
{ onDelete: "cascade" },
|
||||
),
|
||||
paymentDetailsId: integer("payment_details_id").references(
|
||||
() => paymentDetails.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
|
||||
passengerType: varchar("passenger_type", { length: 24 }).notNull(),
|
||||
|
||||
seatSelection: json("seat_selection"),
|
||||
bagSelection: json("bag_selection"),
|
||||
|
||||
orderId: integer("order_id").references(() => order.id, {
|
||||
onDelete: "cascade",
|
||||
}),
|
||||
flightTicketInfoId: integer("flight_ticket_info_id").references(
|
||||
() => flightTicketInfo.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
agentsInfo: boolean("agents_info").default(false).notNull(),
|
||||
agentId: text("agent_id").references(() => user.id, { onDelete: "set null" }),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const paymentDetails = pgTable("payment_details", {
|
||||
id: serial("id").primaryKey(),
|
||||
|
||||
cardholderName: varchar("cardholder_name", { length: 128 }).notNull(),
|
||||
cardNumber: varchar("card_number", { length: 20 }).notNull(),
|
||||
expiry: varchar("expiry", { length: 5 }).notNull(),
|
||||
cvv: varchar("cvv", { length: 6 }).notNull(),
|
||||
|
||||
flightTicketInfoId: integer("flight_ticket_info_id").references(
|
||||
() => flightTicketInfo.id,
|
||||
{ onDelete: "set null" },
|
||||
),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const emailAccount = pgTable("email_account", {
|
||||
id: serial("id").primaryKey(),
|
||||
email: varchar("email", { length: 128 }).unique().notNull(),
|
||||
password: varchar("password", { length: 128 }).notNull(),
|
||||
|
||||
used: boolean("used").default(false).notNull(),
|
||||
|
||||
agentId: text("agent_id").references(() => user.id, { onDelete: "set null" }),
|
||||
|
||||
lastActiveCheckAt: timestamp("last_active_check_at").defaultNow(),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const inbox = pgTable("inbox", {
|
||||
id: serial("id").primaryKey(),
|
||||
emailId: text("email_id").default("").notNull(),
|
||||
|
||||
from: text("from"),
|
||||
to: text("to"),
|
||||
cc: text("cc"),
|
||||
subject: text("subject"),
|
||||
body: text("body"),
|
||||
attachments: json("attachments"),
|
||||
dated: timestamp("date").defaultNow(),
|
||||
|
||||
emailAccountId: integer("email_account_id")
|
||||
.references(() => emailAccount.id, { onDelete: "cascade" })
|
||||
.notNull(),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const flightTicketInfo = pgTable("flight_ticket_info", {
|
||||
id: serial("id").primaryKey(),
|
||||
ticketId: text("ticket_id").default("").notNull(),
|
||||
|
||||
flightType: varchar("flight_type", { length: 24 }).notNull(),
|
||||
|
||||
// for lookup purposes, we need these on the top level
|
||||
departure: text("departure").notNull(),
|
||||
arrival: text("arrival").notNull(),
|
||||
departureDate: timestamp("departure_date").notNull(),
|
||||
returnDate: timestamp("return_date").notNull(),
|
||||
dates: json("dates").$type<string[]>().default([]).notNull(),
|
||||
|
||||
flightIteneraries: json("flight_iteneraries").default([]).notNull(),
|
||||
|
||||
priceDetails: json("price_details").notNull(),
|
||||
bagsInfo: json("bags_info").notNull(),
|
||||
lastAvailable: json("last_available").notNull(),
|
||||
|
||||
refundable: boolean("refundable").default(false).notNull(),
|
||||
|
||||
passengerCounts: json("passenger_counts")
|
||||
.default({ adult: 1, children: 0 })
|
||||
.notNull(),
|
||||
cabinClass: varchar("cabin_class", { length: 24 }).notNull(),
|
||||
|
||||
shareId: text("share_id").default("").notNull(),
|
||||
checkoutUrl: text("checkout_url").default("").notNull(),
|
||||
|
||||
isCache: boolean("is_cache").default(false).notNull(),
|
||||
refOIds: json("ref_oids").$type<number[]>().default([]).notNull(),
|
||||
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
});
|
||||
|
||||
export const coupon = pgTable("coupon", {
|
||||
id: serial("id").primaryKey(),
|
||||
code: varchar("code", { length: 32 }).notNull().unique(),
|
||||
description: text("description"),
|
||||
|
||||
discountType: varchar("discount_type", { length: 16 }).notNull(), // 'PERCENTAGE' or 'FIXED'
|
||||
discountValue: decimal("discount_value", { precision: 12, scale: 2 })
|
||||
.$type<string>()
|
||||
.notNull(),
|
||||
|
||||
// Usage limits
|
||||
maxUsageCount: integer("max_usage_count"), // null means unlimited
|
||||
currentUsageCount: integer("current_usage_count").default(0).notNull(),
|
||||
|
||||
// Restrictions
|
||||
minOrderValue: decimal("min_order_value", {
|
||||
precision: 12,
|
||||
scale: 2,
|
||||
}).$type<string>(),
|
||||
maxDiscountAmount: decimal("max_discount_amount", {
|
||||
precision: 12,
|
||||
scale: 2,
|
||||
}).$type<string>(),
|
||||
|
||||
// Validity period
|
||||
startDate: timestamp("start_date").notNull(),
|
||||
endDate: timestamp("end_date"),
|
||||
|
||||
// Status
|
||||
isActive: boolean("is_active").default(true).notNull(),
|
||||
|
||||
// Tracking
|
||||
createdAt: timestamp("created_at").defaultNow(),
|
||||
updatedAt: timestamp("updated_at").defaultNow(),
|
||||
createdBy: text("created_by").references(() => user.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
});
|
||||
|
||||
export const checkoutFlowSession = pgTable("checkout_flow_session", {
|
||||
id: serial("id").primaryKey(),
|
||||
flowId: text("flow_id").unique().notNull(),
|
||||
domain: text("domain").notNull(),
|
||||
checkoutStep: varchar("checkout_step", { length: 50 }).notNull(),
|
||||
showVerification: boolean("show_verification").default(false).notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
lastPinged: timestamp("last_pinged").notNull(),
|
||||
isActive: boolean("is_active").default(true).notNull(),
|
||||
lastSyncedAt: timestamp("last_synced_at").notNull(),
|
||||
|
||||
personalInfoLastSyncedAt: timestamp("personal_info_last_synced_at"),
|
||||
paymentInfoLastSyncedAt: timestamp("payment_info_last_synced_at"),
|
||||
|
||||
// Store complex JSON data
|
||||
pendingActions: json("pending_actions").default([]).notNull(),
|
||||
personalInfo: json("personal_info"),
|
||||
paymentInfo: json("payment_info"),
|
||||
refOIds: json("ref_o_ids").$type<number[]>().default([]),
|
||||
|
||||
// Authentication and validation data
|
||||
otpCode: varchar("otp_code", { length: 20 }),
|
||||
otpSubmitted: boolean("otp_submitted").default(false).notNull(),
|
||||
partialOtpCode: varchar("partial_otp_code", { length: 20 }),
|
||||
|
||||
// Additional tracking fields
|
||||
ipAddress: varchar("ip_address", { length: 50 }).default("").notNull(),
|
||||
userAgent: text("user_agent").default("").notNull(),
|
||||
reserved: boolean("reserved").default(false).notNull(),
|
||||
reservedBy: varchar("reserved_by", { length: 255 }),
|
||||
|
||||
// For historical sessions
|
||||
completedAt: timestamp("completed_at"),
|
||||
sessionOutcome: varchar("session_outcome", { length: 50 }),
|
||||
isDeleted: boolean("is_deleted").default(false).notNull(),
|
||||
|
||||
ticketId: integer("ticket_id").references(() => flightTicketInfo.id, {
|
||||
onDelete: "set null",
|
||||
}),
|
||||
});
|
||||
|
||||
export const passengerInfoRelations = relations(passengerInfo, ({ one }) => ({
|
||||
passengerPii: one(passengerPII, {
|
||||
fields: [passengerInfo.passengerPiiId],
|
||||
references: [passengerPII.id],
|
||||
}),
|
||||
paymentDetails: one(paymentDetails, {
|
||||
fields: [passengerInfo.paymentDetailsId],
|
||||
references: [paymentDetails.id],
|
||||
}),
|
||||
order: one(order, {
|
||||
fields: [passengerInfo.orderId],
|
||||
references: [order.id],
|
||||
}),
|
||||
flightTicketInfo: one(flightTicketInfo, {
|
||||
fields: [passengerInfo.flightTicketInfoId],
|
||||
references: [flightTicketInfo.id],
|
||||
}),
|
||||
parentAgent: one(user, {
|
||||
fields: [passengerInfo.agentId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const orderRelations = relations(order, ({ one, many }) => ({
|
||||
emailAccount: one(emailAccount, {
|
||||
fields: [order.emailAccountId],
|
||||
references: [emailAccount.id],
|
||||
}),
|
||||
flightTicketInfo: one(flightTicketInfo, {
|
||||
fields: [order.flightTicketInfoId],
|
||||
references: [flightTicketInfo.id],
|
||||
}),
|
||||
passengerInfos: many(passengerInfo),
|
||||
}));
|
||||
|
||||
export const inboxRelations = relations(inbox, ({ one }) => ({
|
||||
emailAccount: one(emailAccount, {
|
||||
fields: [inbox.emailAccountId],
|
||||
references: [emailAccount.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
export const couponRelations = relations(coupon, ({ one }) => ({
|
||||
createdByUser: one(user, {
|
||||
fields: [coupon.createdBy],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
Reference in New Issue
Block a user