mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
latest
This commit is contained in:
1 parent
e3fb29ab1d
commit
2485f71dd7
95 files changed
+41842
No files matched your search
@@ -0,0 +1,271 @@
|
||||
-- Current sql file was generated after introspecting the database
|
||||
-- If you want to run this migration please uncomment this code before executing migrations
|
||||
/*
|
||||
CREATE TABLE "deliveries" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"order_id" integer,
|
||||
"supplier_id" integer NOT NULL,
|
||||
"group_id" integer NOT NULL,
|
||||
"delivered_date" timestamp,
|
||||
"quantity" integer NOT NULL,
|
||||
"unit" varchar NOT NULL,
|
||||
"status" varchar DEFAULT 'planned' NOT NULL,
|
||||
"created_by" varchar NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"bl_number" varchar,
|
||||
"bl_amount" numeric(10, 2),
|
||||
"invoice_reference" varchar,
|
||||
"invoice_amount" numeric(10, 2),
|
||||
"reconciled" boolean DEFAULT false,
|
||||
"scheduled_date" date NOT NULL,
|
||||
"notes" text,
|
||||
"validated_at" timestamp,
|
||||
CONSTRAINT "deliveries_status_check_fixed" CHECK ((status)::text = ANY ((ARRAY['planned'::character varying, 'delivered'::character varying])::text[]))
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "orders" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"supplier_id" integer NOT NULL,
|
||||
"group_id" integer NOT NULL,
|
||||
"planned_date" date NOT NULL,
|
||||
"quantity" integer,
|
||||
"unit" varchar,
|
||||
"status" varchar DEFAULT 'pending' NOT NULL,
|
||||
"created_by" varchar NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"notes" text,
|
||||
CONSTRAINT "orders_status_check" CHECK ((status)::text = ANY ((ARRAY['pending'::character varying, 'planned'::character varying, 'delivered'::character varying])::text[]))
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "groups" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar NOT NULL,
|
||||
"color" varchar NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"nocodb_config_id" integer,
|
||||
"nocodb_table_id" varchar,
|
||||
"nocodb_table_name" varchar,
|
||||
"invoice_column_name" varchar DEFAULT 'Ref Facture'
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "sessions" (
|
||||
"sid" varchar PRIMARY KEY NOT NULL,
|
||||
"sess" jsonb NOT NULL,
|
||||
"expire" timestamp NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "suppliers" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar NOT NULL,
|
||||
"contact" varchar,
|
||||
"phone" varchar,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"has_dlc" boolean DEFAULT false
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_groups" (
|
||||
"user_id" varchar NOT NULL,
|
||||
"group_id" integer NOT NULL,
|
||||
"created_at" timestamp DEFAULT now()
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "publicities" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"pub_number" varchar(255) NOT NULL,
|
||||
"designation" text NOT NULL,
|
||||
"start_date" date NOT NULL,
|
||||
"end_date" date NOT NULL,
|
||||
"year" integer NOT NULL,
|
||||
"created_by" varchar(255) NOT NULL,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "session" (
|
||||
"sid" varchar PRIMARY KEY NOT NULL,
|
||||
"sess" json NOT NULL,
|
||||
"expire" timestamp(6) NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "users" (
|
||||
"id" varchar PRIMARY KEY NOT NULL,
|
||||
"email" varchar,
|
||||
"first_name" varchar,
|
||||
"last_name" varchar,
|
||||
"profile_image_url" varchar,
|
||||
"role" varchar DEFAULT 'employee' NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"password" varchar,
|
||||
"username" varchar,
|
||||
"password_changed" boolean DEFAULT false,
|
||||
"name" varchar(255),
|
||||
CONSTRAINT "users_email_unique" UNIQUE("email"),
|
||||
CONSTRAINT "users_username_key" UNIQUE("username")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "roles" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar(100) NOT NULL,
|
||||
"display_name" varchar(200) NOT NULL,
|
||||
"description" text,
|
||||
"color" varchar(20) DEFAULT '#6b7280',
|
||||
"is_system" boolean DEFAULT false,
|
||||
"is_active" boolean DEFAULT true,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "roles_name_key" UNIQUE("name")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "permissions" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar(100) NOT NULL,
|
||||
"display_name" varchar(200) NOT NULL,
|
||||
"description" text,
|
||||
"category" varchar(50) NOT NULL,
|
||||
"action" varchar(50) NOT NULL,
|
||||
"resource" varchar(50) NOT NULL,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
"is_system" boolean DEFAULT false,
|
||||
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "permissions_name_key" UNIQUE("name")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "nocodb_config" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"name" varchar NOT NULL,
|
||||
"base_url" varchar NOT NULL,
|
||||
"api_token" varchar NOT NULL,
|
||||
"description" text,
|
||||
"is_active" boolean DEFAULT true,
|
||||
"created_by" varchar NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"project_id" varchar
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "customer_orders" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"order_taker" varchar NOT NULL,
|
||||
"customer_name" varchar NOT NULL,
|
||||
"customer_phone" varchar NOT NULL,
|
||||
"product_designation" text NOT NULL,
|
||||
"product_reference" varchar,
|
||||
"gencode" varchar,
|
||||
"status" varchar DEFAULT 'En attente de Commande' NOT NULL,
|
||||
"deposit" numeric(10, 2) DEFAULT '0.00',
|
||||
"is_promotional_price" boolean DEFAULT false,
|
||||
"customer_notified" boolean DEFAULT false,
|
||||
"group_id" integer NOT NULL,
|
||||
"created_by" varchar NOT NULL,
|
||||
"created_at" timestamp DEFAULT now(),
|
||||
"updated_at" timestamp DEFAULT now(),
|
||||
"supplier_id" integer,
|
||||
"quantity" integer DEFAULT 1 NOT NULL,
|
||||
"customer_email" varchar(255),
|
||||
"notes" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "dlc_products" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"product_name" varchar(255) NOT NULL,
|
||||
"expiry_date" date NOT NULL,
|
||||
"date_type" varchar(10) NOT NULL,
|
||||
"quantity" integer NOT NULL,
|
||||
"unit" varchar(50) NOT NULL,
|
||||
"supplier_id" integer NOT NULL,
|
||||
"location" varchar(255) NOT NULL,
|
||||
"status" varchar(20) DEFAULT 'en_cours' NOT NULL,
|
||||
"notes" text,
|
||||
"alert_threshold" integer DEFAULT 3 NOT NULL,
|
||||
"validated_at" timestamp,
|
||||
"validated_by" varchar(255),
|
||||
"group_id" integer NOT NULL,
|
||||
"created_by" varchar(255) NOT NULL,
|
||||
"created_at" timestamp DEFAULT now() NOT NULL,
|
||||
"updated_at" timestamp DEFAULT now() NOT NULL,
|
||||
"gencode" varchar,
|
||||
"name" varchar(255),
|
||||
"dlc_date" date,
|
||||
"product_code" varchar(255),
|
||||
"description" text,
|
||||
CONSTRAINT "dlc_products_date_type_check" CHECK ((date_type)::text = ANY ((ARRAY['dlc'::character varying, 'ddm'::character varying, 'dluo'::character varying])::text[])),
|
||||
CONSTRAINT "dlc_products_status_check" CHECK ((status)::text = ANY ((ARRAY['en_cours'::character varying, 'expires_soon'::character varying, 'expires'::character varying, 'valides'::character varying])::text[]))
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "tasks" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"description" text,
|
||||
"status" text DEFAULT 'pending' NOT NULL,
|
||||
"priority" text DEFAULT 'medium' NOT NULL,
|
||||
"due_date" timestamp,
|
||||
"group_id" integer NOT NULL,
|
||||
"created_by" text NOT NULL,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
||||
"completed_at" timestamp,
|
||||
"assigned_to" text DEFAULT '' NOT NULL,
|
||||
"completed_by" varchar(255),
|
||||
CONSTRAINT "tasks_status_check" CHECK (status = ANY (ARRAY['pending'::text, 'in_progress'::text, 'completed'::text, 'cancelled'::text])),
|
||||
CONSTRAINT "tasks_priority_check" CHECK (priority = ANY (ARRAY['low'::text, 'medium'::text, 'high'::text, 'urgent'::text]))
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "publicity_participations" (
|
||||
"publicity_id" integer NOT NULL,
|
||||
"group_id" integer NOT NULL,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "publicity_participations_pkey" PRIMARY KEY("publicity_id","group_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "role_permissions" (
|
||||
"role_id" integer NOT NULL,
|
||||
"permission_id" integer NOT NULL,
|
||||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "role_permissions_pkey" PRIMARY KEY("role_id","permission_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
CREATE TABLE "user_roles" (
|
||||
"user_id" varchar(255) NOT NULL,
|
||||
"role_id" integer NOT NULL,
|
||||
"assigned_by" varchar(255) NOT NULL,
|
||||
"assigned_at" timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
CONSTRAINT "user_roles_pkey" PRIMARY KEY("user_id","role_id")
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "dlc_products" ADD CONSTRAINT "dlc_products_supplier_id_fkey" FOREIGN KEY ("supplier_id") REFERENCES "public"."suppliers"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "dlc_products" ADD CONSTRAINT "dlc_products_validated_by_fkey" FOREIGN KEY ("validated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "dlc_products" ADD CONSTRAINT "dlc_products_group_id_fkey" FOREIGN KEY ("group_id") REFERENCES "public"."groups"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "dlc_products" ADD CONSTRAINT "dlc_products_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_completed_by_fkey" FOREIGN KEY ("completed_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_group_id_fkey" FOREIGN KEY ("group_id") REFERENCES "public"."groups"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "tasks" ADD CONSTRAINT "tasks_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "publicity_participations" ADD CONSTRAINT "publicity_participations_publicity_id_fkey" FOREIGN KEY ("publicity_id") REFERENCES "public"."publicities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "publicity_participations" ADD CONSTRAINT "publicity_participations_group_id_fkey" FOREIGN KEY ("group_id") REFERENCES "public"."groups"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "public"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "role_permissions" ADD CONSTRAINT "role_permissions_permission_id_fkey" FOREIGN KEY ("permission_id") REFERENCES "public"."permissions"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_role_id_fkey" FOREIGN KEY ("role_id") REFERENCES "public"."roles"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE INDEX "idx_deliveries_bl_number" ON "deliveries" USING btree ("bl_number" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_deliveries_group_id" ON "deliveries" USING btree ("group_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_deliveries_invoice_ref" ON "deliveries" USING btree ("invoice_reference" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_deliveries_status" ON "deliveries" USING btree ("status" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_orders_group_id" ON "orders" USING btree ("group_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_orders_status" ON "orders" USING btree ("status" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "IDX_session_expire" ON "sessions" USING btree ("expire" timestamp_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_publicities_start_date" ON "publicities" USING btree ("start_date" date_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_publicities_year" ON "publicities" USING btree ("year" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_dlc_products_expiry_date" ON "dlc_products" USING btree ("expiry_date" date_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_dlc_products_group_id" ON "dlc_products" USING btree ("group_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_dlc_products_status" ON "dlc_products" USING btree ("status" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_dlc_products_supplier_id" ON "dlc_products" USING btree ("supplier_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_role_permissions_permission_id" ON "role_permissions" USING btree ("permission_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_role_permissions_role_id" ON "role_permissions" USING btree ("role_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_user_roles_assigned_by" ON "user_roles" USING btree ("assigned_by" text_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_user_roles_role_id" ON "user_roles" USING btree ("role_id" int4_ops);--> statement-breakpoint
|
||||
CREATE INDEX "idx_user_roles_user_id" ON "user_roles" USING btree ("user_id" text_ops);
|
||||
*/
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1752862907657,
|
||||
"tag": "0000_flashy_blur",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
import { relations } from "drizzle-orm/relations";
|
||||
import { suppliers, dlcProducts, users, groups, tasks, publicities, publicityParticipations, roles, rolePermissions, permissions, userRoles } from "./schema";
|
||||
|
||||
export const dlcProductsRelations = relations(dlcProducts, ({one}) => ({
|
||||
supplier: one(suppliers, {
|
||||
fields: [dlcProducts.supplierId],
|
||||
references: [suppliers.id]
|
||||
}),
|
||||
user_validatedBy: one(users, {
|
||||
fields: [dlcProducts.validatedBy],
|
||||
references: [users.id],
|
||||
relationName: "dlcProducts_validatedBy_users_id"
|
||||
}),
|
||||
group: one(groups, {
|
||||
fields: [dlcProducts.groupId],
|
||||
references: [groups.id]
|
||||
}),
|
||||
user_createdBy: one(users, {
|
||||
fields: [dlcProducts.createdBy],
|
||||
references: [users.id],
|
||||
relationName: "dlcProducts_createdBy_users_id"
|
||||
}),
|
||||
}));
|
||||
|
||||
export const suppliersRelations = relations(suppliers, ({many}) => ({
|
||||
dlcProducts: many(dlcProducts),
|
||||
}));
|
||||
|
||||
export const usersRelations = relations(users, ({many}) => ({
|
||||
dlcProducts_validatedBy: many(dlcProducts, {
|
||||
relationName: "dlcProducts_validatedBy_users_id"
|
||||
}),
|
||||
dlcProducts_createdBy: many(dlcProducts, {
|
||||
relationName: "dlcProducts_createdBy_users_id"
|
||||
}),
|
||||
tasks_completedBy: many(tasks, {
|
||||
relationName: "tasks_completedBy_users_id"
|
||||
}),
|
||||
tasks_createdBy: many(tasks, {
|
||||
relationName: "tasks_createdBy_users_id"
|
||||
}),
|
||||
userRoles: many(userRoles),
|
||||
}));
|
||||
|
||||
export const groupsRelations = relations(groups, ({many}) => ({
|
||||
dlcProducts: many(dlcProducts),
|
||||
tasks: many(tasks),
|
||||
publicityParticipations: many(publicityParticipations),
|
||||
}));
|
||||
|
||||
export const tasksRelations = relations(tasks, ({one}) => ({
|
||||
user_completedBy: one(users, {
|
||||
fields: [tasks.completedBy],
|
||||
references: [users.id],
|
||||
relationName: "tasks_completedBy_users_id"
|
||||
}),
|
||||
group: one(groups, {
|
||||
fields: [tasks.groupId],
|
||||
references: [groups.id]
|
||||
}),
|
||||
user_createdBy: one(users, {
|
||||
fields: [tasks.createdBy],
|
||||
references: [users.id],
|
||||
relationName: "tasks_createdBy_users_id"
|
||||
}),
|
||||
}));
|
||||
|
||||
export const publicityParticipationsRelations = relations(publicityParticipations, ({one}) => ({
|
||||
publicity: one(publicities, {
|
||||
fields: [publicityParticipations.publicityId],
|
||||
references: [publicities.id]
|
||||
}),
|
||||
group: one(groups, {
|
||||
fields: [publicityParticipations.groupId],
|
||||
references: [groups.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const publicitiesRelations = relations(publicities, ({many}) => ({
|
||||
publicityParticipations: many(publicityParticipations),
|
||||
}));
|
||||
|
||||
export const rolePermissionsRelations = relations(rolePermissions, ({one}) => ({
|
||||
role: one(roles, {
|
||||
fields: [rolePermissions.roleId],
|
||||
references: [roles.id]
|
||||
}),
|
||||
permission: one(permissions, {
|
||||
fields: [rolePermissions.permissionId],
|
||||
references: [permissions.id]
|
||||
}),
|
||||
}));
|
||||
|
||||
export const rolesRelations = relations(roles, ({many}) => ({
|
||||
rolePermissions: many(rolePermissions),
|
||||
userRoles: many(userRoles),
|
||||
}));
|
||||
|
||||
export const permissionsRelations = relations(permissions, ({many}) => ({
|
||||
rolePermissions: many(rolePermissions),
|
||||
}));
|
||||
|
||||
export const userRolesRelations = relations(userRoles, ({one}) => ({
|
||||
user: one(users, {
|
||||
fields: [userRoles.userId],
|
||||
references: [users.id]
|
||||
}),
|
||||
role: one(roles, {
|
||||
fields: [userRoles.roleId],
|
||||
references: [roles.id]
|
||||
}),
|
||||
}));
|
||||
@@ -0,0 +1,335 @@
|
||||
import { pgTable, index, check, serial, integer, timestamp, varchar, numeric, boolean, date, text, jsonb, json, unique, foreignKey, primaryKey } from "drizzle-orm/pg-core"
|
||||
import { sql } from "drizzle-orm"
|
||||
|
||||
|
||||
|
||||
export const deliveries = pgTable("deliveries", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
orderId: integer("order_id"),
|
||||
supplierId: integer("supplier_id").notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
deliveredDate: timestamp("delivered_date", { mode: 'string' }),
|
||||
quantity: integer().notNull(),
|
||||
unit: varchar().notNull(),
|
||||
status: varchar().default('planned').notNull(),
|
||||
createdBy: varchar("created_by").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
blNumber: varchar("bl_number"),
|
||||
blAmount: numeric("bl_amount", { precision: 10, scale: 2 }),
|
||||
invoiceReference: varchar("invoice_reference"),
|
||||
invoiceAmount: numeric("invoice_amount", { precision: 10, scale: 2 }),
|
||||
reconciled: boolean().default(false),
|
||||
scheduledDate: date("scheduled_date").notNull(),
|
||||
notes: text(),
|
||||
validatedAt: timestamp("validated_at", { mode: 'string' }),
|
||||
}, (table) => [
|
||||
index("idx_deliveries_bl_number").using("btree", table.blNumber.asc().nullsLast().op("text_ops")),
|
||||
index("idx_deliveries_group_id").using("btree", table.groupId.asc().nullsLast().op("int4_ops")),
|
||||
index("idx_deliveries_invoice_ref").using("btree", table.invoiceReference.asc().nullsLast().op("text_ops")),
|
||||
index("idx_deliveries_status").using("btree", table.status.asc().nullsLast().op("text_ops")),
|
||||
check("deliveries_status_check_fixed", sql`(status)::text = ANY ((ARRAY['planned'::character varying, 'delivered'::character varying])::text[])`),
|
||||
]);
|
||||
|
||||
export const orders = pgTable("orders", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
supplierId: integer("supplier_id").notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
plannedDate: date("planned_date").notNull(),
|
||||
quantity: integer(),
|
||||
unit: varchar(),
|
||||
status: varchar().default('pending').notNull(),
|
||||
createdBy: varchar("created_by").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
notes: text(),
|
||||
}, (table) => [
|
||||
index("idx_orders_group_id").using("btree", table.groupId.asc().nullsLast().op("int4_ops")),
|
||||
index("idx_orders_status").using("btree", table.status.asc().nullsLast().op("text_ops")),
|
||||
check("orders_status_check", sql`(status)::text = ANY ((ARRAY['pending'::character varying, 'planned'::character varying, 'delivered'::character varying])::text[])`),
|
||||
]);
|
||||
|
||||
export const groups = pgTable("groups", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: varchar().notNull(),
|
||||
color: varchar().notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
nocodbConfigId: integer("nocodb_config_id"),
|
||||
nocodbTableId: varchar("nocodb_table_id"),
|
||||
nocodbTableName: varchar("nocodb_table_name"),
|
||||
invoiceColumnName: varchar("invoice_column_name").default('Ref Facture'),
|
||||
});
|
||||
|
||||
export const sessions = pgTable("sessions", {
|
||||
sid: varchar().primaryKey().notNull(),
|
||||
sess: jsonb().notNull(),
|
||||
expire: timestamp({ mode: 'string' }).notNull(),
|
||||
}, (table) => [
|
||||
index("IDX_session_expire").using("btree", table.expire.asc().nullsLast().op("timestamp_ops")),
|
||||
]);
|
||||
|
||||
export const suppliers = pgTable("suppliers", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: varchar().notNull(),
|
||||
contact: varchar(),
|
||||
phone: varchar(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
hasDlc: boolean("has_dlc").default(false),
|
||||
});
|
||||
|
||||
export const userGroups = pgTable("user_groups", {
|
||||
userId: varchar("user_id").notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
});
|
||||
|
||||
export const publicities = pgTable("publicities", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
pubNumber: varchar("pub_number", { length: 255 }).notNull(),
|
||||
designation: text().notNull(),
|
||||
startDate: date("start_date").notNull(),
|
||||
endDate: date("end_date").notNull(),
|
||||
year: integer().notNull(),
|
||||
createdBy: varchar("created_by", { length: 255 }).notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
index("idx_publicities_start_date").using("btree", table.startDate.asc().nullsLast().op("date_ops")),
|
||||
index("idx_publicities_year").using("btree", table.year.asc().nullsLast().op("int4_ops")),
|
||||
]);
|
||||
|
||||
export const session = pgTable("session", {
|
||||
sid: varchar().primaryKey().notNull(),
|
||||
sess: json().notNull(),
|
||||
expire: timestamp({ precision: 6, mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const users = pgTable("users", {
|
||||
id: varchar().primaryKey().notNull(),
|
||||
email: varchar(),
|
||||
firstName: varchar("first_name"),
|
||||
lastName: varchar("last_name"),
|
||||
profileImageUrl: varchar("profile_image_url"),
|
||||
role: varchar().default('employee').notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
password: varchar(),
|
||||
username: varchar(),
|
||||
passwordChanged: boolean("password_changed").default(false),
|
||||
name: varchar({ length: 255 }),
|
||||
}, (table) => [
|
||||
unique("users_email_unique").on(table.email),
|
||||
unique("users_username_key").on(table.username),
|
||||
]);
|
||||
|
||||
export const roles = pgTable("roles", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: varchar({ length: 100 }).notNull(),
|
||||
displayName: varchar("display_name", { length: 200 }).notNull(),
|
||||
description: text(),
|
||||
color: varchar({ length: 20 }).default('#6b7280'),
|
||||
isSystem: boolean("is_system").default(false),
|
||||
isActive: boolean("is_active").default(true),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
unique("roles_name_key").on(table.name),
|
||||
]);
|
||||
|
||||
export const permissions = pgTable("permissions", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: varchar({ length: 100 }).notNull(),
|
||||
displayName: varchar("display_name", { length: 200 }).notNull(),
|
||||
description: text(),
|
||||
category: varchar({ length: 50 }).notNull(),
|
||||
action: varchar({ length: 50 }).notNull(),
|
||||
resource: varchar({ length: 50 }).notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
isSystem: boolean("is_system").default(false),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
unique("permissions_name_key").on(table.name),
|
||||
]);
|
||||
|
||||
export const nocodbConfig = pgTable("nocodb_config", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
name: varchar().notNull(),
|
||||
baseUrl: varchar("base_url").notNull(),
|
||||
apiToken: varchar("api_token").notNull(),
|
||||
description: text(),
|
||||
isActive: boolean("is_active").default(true),
|
||||
createdBy: varchar("created_by").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
projectId: varchar("project_id"),
|
||||
});
|
||||
|
||||
export const customerOrders = pgTable("customer_orders", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
orderTaker: varchar("order_taker").notNull(),
|
||||
customerName: varchar("customer_name").notNull(),
|
||||
customerPhone: varchar("customer_phone").notNull(),
|
||||
productDesignation: text("product_designation").notNull(),
|
||||
productReference: varchar("product_reference"),
|
||||
gencode: varchar(),
|
||||
status: varchar().default('En attente de Commande').notNull(),
|
||||
deposit: numeric({ precision: 10, scale: 2 }).default('0.00'),
|
||||
isPromotionalPrice: boolean("is_promotional_price").default(false),
|
||||
customerNotified: boolean("customer_notified").default(false),
|
||||
groupId: integer("group_id").notNull(),
|
||||
createdBy: varchar("created_by").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow(),
|
||||
supplierId: integer("supplier_id"),
|
||||
quantity: integer().default(1).notNull(),
|
||||
customerEmail: varchar("customer_email", { length: 255 }),
|
||||
notes: text(),
|
||||
});
|
||||
|
||||
export const dlcProducts = pgTable("dlc_products", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
productName: varchar("product_name", { length: 255 }).notNull(),
|
||||
expiryDate: date("expiry_date").notNull(),
|
||||
dateType: varchar("date_type", { length: 10 }).notNull(),
|
||||
quantity: integer().notNull(),
|
||||
unit: varchar({ length: 50 }).notNull(),
|
||||
supplierId: integer("supplier_id").notNull(),
|
||||
location: varchar({ length: 255 }).notNull(),
|
||||
status: varchar({ length: 20 }).default('en_cours').notNull(),
|
||||
notes: text(),
|
||||
alertThreshold: integer("alert_threshold").default(3).notNull(),
|
||||
validatedAt: timestamp("validated_at", { mode: 'string' }),
|
||||
validatedBy: varchar("validated_by", { length: 255 }),
|
||||
groupId: integer("group_id").notNull(),
|
||||
createdBy: varchar("created_by", { length: 255 }).notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).defaultNow().notNull(),
|
||||
gencode: varchar(),
|
||||
name: varchar({ length: 255 }),
|
||||
dlcDate: date("dlc_date"),
|
||||
productCode: varchar("product_code", { length: 255 }),
|
||||
description: text(),
|
||||
}, (table) => [
|
||||
index("idx_dlc_products_expiry_date").using("btree", table.expiryDate.asc().nullsLast().op("date_ops")),
|
||||
index("idx_dlc_products_group_id").using("btree", table.groupId.asc().nullsLast().op("int4_ops")),
|
||||
index("idx_dlc_products_status").using("btree", table.status.asc().nullsLast().op("text_ops")),
|
||||
index("idx_dlc_products_supplier_id").using("btree", table.supplierId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.supplierId],
|
||||
foreignColumns: [suppliers.id],
|
||||
name: "dlc_products_supplier_id_fkey"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.validatedBy],
|
||||
foreignColumns: [users.id],
|
||||
name: "dlc_products_validated_by_fkey"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.groupId],
|
||||
foreignColumns: [groups.id],
|
||||
name: "dlc_products_group_id_fkey"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.createdBy],
|
||||
foreignColumns: [users.id],
|
||||
name: "dlc_products_created_by_fkey"
|
||||
}),
|
||||
check("dlc_products_date_type_check", sql`(date_type)::text = ANY ((ARRAY['dlc'::character varying, 'ddm'::character varying, 'dluo'::character varying])::text[])`),
|
||||
check("dlc_products_status_check", sql`(status)::text = ANY ((ARRAY['en_cours'::character varying, 'expires_soon'::character varying, 'expires'::character varying, 'valides'::character varying])::text[])`),
|
||||
]);
|
||||
|
||||
export const tasks = pgTable("tasks", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
title: text().notNull(),
|
||||
description: text(),
|
||||
status: text().default('pending').notNull(),
|
||||
priority: text().default('medium').notNull(),
|
||||
dueDate: timestamp("due_date", { mode: 'string' }),
|
||||
groupId: integer("group_id").notNull(),
|
||||
createdBy: text("created_by").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
updatedAt: timestamp("updated_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`).notNull(),
|
||||
completedAt: timestamp("completed_at", { mode: 'string' }),
|
||||
assignedTo: text("assigned_to").default(').notNull(),
|
||||
completedBy: varchar("completed_by", { length: 255 }),
|
||||
}, (table) => [
|
||||
foreignKey({
|
||||
columns: [table.completedBy],
|
||||
foreignColumns: [users.id],
|
||||
name: "tasks_completed_by_fkey"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.groupId],
|
||||
foreignColumns: [groups.id],
|
||||
name: "tasks_group_id_fkey"
|
||||
}),
|
||||
foreignKey({
|
||||
columns: [table.createdBy],
|
||||
foreignColumns: [users.id],
|
||||
name: "tasks_created_by_fkey"
|
||||
}),
|
||||
check("tasks_status_check", sql`status = ANY (ARRAY['pending'::text, 'in_progress'::text, 'completed'::text, 'cancelled'::text])`),
|
||||
check("tasks_priority_check", sql`priority = ANY (ARRAY['low'::text, 'medium'::text, 'high'::text, 'urgent'::text])`),
|
||||
]);
|
||||
|
||||
export const publicityParticipations = pgTable("publicity_participations", {
|
||||
publicityId: integer("publicity_id").notNull(),
|
||||
groupId: integer("group_id").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
foreignKey({
|
||||
columns: [table.publicityId],
|
||||
foreignColumns: [publicities.id],
|
||||
name: "publicity_participations_publicity_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
foreignKey({
|
||||
columns: [table.groupId],
|
||||
foreignColumns: [groups.id],
|
||||
name: "publicity_participations_group_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
primaryKey({ columns: [table.publicityId, table.groupId], name: "publicity_participations_pkey"}),
|
||||
]);
|
||||
|
||||
export const rolePermissions = pgTable("role_permissions", {
|
||||
roleId: integer("role_id").notNull(),
|
||||
permissionId: integer("permission_id").notNull(),
|
||||
createdAt: timestamp("created_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
index("idx_role_permissions_permission_id").using("btree", table.permissionId.asc().nullsLast().op("int4_ops")),
|
||||
index("idx_role_permissions_role_id").using("btree", table.roleId.asc().nullsLast().op("int4_ops")),
|
||||
foreignKey({
|
||||
columns: [table.roleId],
|
||||
foreignColumns: [roles.id],
|
||||
name: "role_permissions_role_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
foreignKey({
|
||||
columns: [table.permissionId],
|
||||
foreignColumns: [permissions.id],
|
||||
name: "role_permissions_permission_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
primaryKey({ columns: [table.roleId, table.permissionId], name: "role_permissions_pkey"}),
|
||||
]);
|
||||
|
||||
export const userRoles = pgTable("user_roles", {
|
||||
userId: varchar("user_id", { length: 255 }).notNull(),
|
||||
roleId: integer("role_id").notNull(),
|
||||
assignedBy: varchar("assigned_by", { length: 255 }).notNull(),
|
||||
assignedAt: timestamp("assigned_at", { mode: 'string' }).default(sql`CURRENT_TIMESTAMP`),
|
||||
}, (table) => [
|
||||
index("idx_user_roles_assigned_by").using("btree", table.assignedBy.asc().nullsLast().op("text_ops")),
|
||||
index("idx_user_roles_role_id").using("btree", table.roleId.asc().nullsLast().op("int4_ops")),
|
||||
index("idx_user_roles_user_id").using("btree", table.userId.asc().nullsLast().op("text_ops")),
|
||||
foreignKey({
|
||||
columns: [table.userId],
|
||||
foreignColumns: [users.id],
|
||||
name: "user_roles_user_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
foreignKey({
|
||||
columns: [table.roleId],
|
||||
foreignColumns: [roles.id],
|
||||
name: "user_roles_role_id_fkey"
|
||||
}).onDelete("cascade"),
|
||||
primaryKey({ columns: [table.userId, table.roleId], name: "user_roles_pkey"}),
|
||||
]);
|
||||
Reference in new issue
Block a user