@delpa/mt-prisma 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,55 @@ enum FuelType {
63
63
  GAS
64
64
  }
65
65
 
66
+ enum PackagingType {
67
+ BOX
68
+ PALLET
69
+ CRATE
70
+ BARREL
71
+ BAG
72
+ ROLL
73
+ BUNDLE
74
+ CONTAINER
75
+ LOOSE
76
+ OTHER
77
+ }
78
+
79
+ enum ProductCategory {
80
+ ELECTRONICS
81
+ FOOD_BEVERAGE
82
+ PHARMACEUTICALS
83
+ TEXTILES
84
+ MACHINERY
85
+ CHEMICALS
86
+ CONSTRUCTION
87
+ AUTOMOTIVE
88
+ AGRICULTURE
89
+ FURNITURE
90
+ PAPER
91
+ PLASTICS
92
+ METALS
93
+ GLASS
94
+ OTHER
95
+ }
96
+
97
+ enum ProductSubcategory {
98
+ RAW_MATERIALS
99
+ FINISHED_GOODS
100
+ SEMI_FINISHED
101
+ SPARE_PARTS
102
+ CONSUMABLES
103
+ HAZARDOUS
104
+ FRAGILE
105
+ PERISHABLE
106
+ REFRIGERATED
107
+ FROZEN
108
+ BULK
109
+ LIQUID
110
+ OVERSIZED
111
+ HIGH_VALUE
112
+ OTHER
113
+ }
114
+
66
115
  enum AddressType {
67
116
  PICKUP
68
117
  DELIVERY
@@ -105,6 +154,33 @@ enum GpsProviders {
105
154
  SASCAR
106
155
  }
107
156
 
157
+ model Product {
158
+ id String @id @default(uuid()) @db.Uuid
159
+ client_id String @db.Uuid
160
+ description String
161
+ sku String @unique
162
+ quantity Int @default(0)
163
+ packaging_type PackagingType @default(BOX)
164
+ category ProductCategory @default(OTHER)
165
+ subcategory ProductSubcategory @default(OTHER)
166
+ dimension_unit DimensionUnits @default(CM)
167
+ length Float?
168
+ width Float?
169
+ height Float?
170
+ weight_unit WeightUnits @default(KG)
171
+ weight Float?
172
+ is_active Boolean @default(true)
173
+ created_at DateTime @default(now())
174
+ updated_at DateTime @updatedAt
175
+
176
+ client Client @relation(fields: [client_id], references: [id], onDelete: Cascade)
177
+
178
+ @@index([client_id])
179
+ @@index([sku])
180
+ @@index([category])
181
+ @@map("products")
182
+ }
183
+
108
184
  model Client {
109
185
  id String @id @default(uuid()) @db.Uuid
110
186
  tax_id String?
@@ -122,6 +198,7 @@ model Client {
122
198
  contacts ClientContact[]
123
199
  orders_as_shipper Order[] @relation("shipper_client")
124
200
  handling_units_as_consignee HandlingUnit[]
201
+ products Product[]
125
202
 
126
203
  @@index([company_id])
127
204
  @@index([created_by])
@@ -199,6 +276,9 @@ model companies {
199
276
  vehicles Vehicle[]
200
277
  user_companies UserCompany[]
201
278
  equipments Equipment[]
279
+ form_templates FormTemplate[]
280
+ form_responses FormResponse[]
281
+ forms Form[]
202
282
 
203
283
  @@map("companies")
204
284
  }
@@ -249,10 +329,13 @@ model User {
249
329
  created_at DateTime @default(now())
250
330
  updated_at DateTime @updatedAt
251
331
 
252
- routes Route[]
253
- user_companies UserCompany[]
254
- sessions Session[]
255
- driverLocations DriverLocation[]
332
+ routes Route[]
333
+ user_companies UserCompany[]
334
+ sessions Session[]
335
+ driverLocations DriverLocation[]
336
+ form_templates_created FormTemplate[]
337
+ form_responses FormResponse[]
338
+ forms_created Form[] @relation("FormCreator")
256
339
 
257
340
  @@map("users")
258
341
  }
@@ -553,3 +636,180 @@ model DriverLocation {
553
636
  @@index([created_at])
554
637
  @@map("driver_locations")
555
638
  }
639
+
640
+ // ============================================
641
+ // FORMS - Form Templates, Fields and Responses
642
+ // ============================================
643
+
644
+ enum FieldType {
645
+ TEXT
646
+ TEXTAREA
647
+ NUMBER
648
+ EMAIL
649
+ PHONE
650
+ DATE
651
+ DATETIME
652
+ TIME
653
+ SELECT
654
+ MULTISELECT
655
+ CHECKBOX
656
+ RADIO
657
+ FILE
658
+ IMAGE
659
+ SIGNATURE
660
+ LOCATION
661
+ }
662
+
663
+ enum FormResponseStatus {
664
+ DRAFT
665
+ SUBMITTED
666
+ APPROVED
667
+ REJECTED
668
+ }
669
+
670
+ model FormTemplate {
671
+ id String @id @default(uuid()) @db.Uuid
672
+ name String
673
+ description String?
674
+ company_id String? @db.Uuid
675
+ is_active Boolean @default(true)
676
+ is_global Boolean @default(false)
677
+ category String?
678
+ version Int @default(1)
679
+ created_by String? @db.Uuid
680
+ created_at DateTime @default(now())
681
+ updated_at DateTime @updatedAt
682
+
683
+ company companies? @relation(fields: [company_id], references: [id], onDelete: SetNull)
684
+ created_by_user User? @relation(fields: [created_by], references: [id], onDelete: SetNull)
685
+ fields TemplateField[]
686
+ responses FormResponse[]
687
+ forms Form[]
688
+
689
+ @@index([company_id])
690
+ @@index([is_global])
691
+ @@index([category])
692
+ @@index([is_active])
693
+ @@map("form_templates")
694
+ }
695
+
696
+ model TemplateField {
697
+ id String @id @default(uuid()) @db.Uuid
698
+ template_id String @db.Uuid
699
+ label String
700
+ field_type FieldType
701
+ placeholder String?
702
+ help_text String?
703
+ is_required Boolean @default(false)
704
+ order Int @default(0)
705
+ options Json?
706
+ validations Json?
707
+ default_value String?
708
+ conditional_logic Json?
709
+ created_at DateTime @default(now())
710
+ updated_at DateTime @updatedAt
711
+
712
+ template FormTemplate @relation(fields: [template_id], references: [id], onDelete: Cascade)
713
+
714
+ @@index([template_id])
715
+ @@map("template_fields")
716
+ }
717
+
718
+ model FormResponse {
719
+ id String @id @default(uuid()) @db.Uuid
720
+ template_id String? @db.Uuid
721
+ form_id String? @db.Uuid
722
+ entity_type String
723
+ entity_id String @db.Uuid
724
+ company_id String? @db.Uuid
725
+ respondent_id String? @db.Uuid
726
+ responses Json
727
+ status FormResponseStatus @default(DRAFT)
728
+ submitted_at DateTime?
729
+ created_at DateTime @default(now())
730
+ updated_at DateTime @updatedAt
731
+
732
+ template FormTemplate? @relation(fields: [template_id], references: [id])
733
+ form Form? @relation(fields: [form_id], references: [id])
734
+ company companies? @relation(fields: [company_id], references: [id], onDelete: SetNull)
735
+ respondent User? @relation(fields: [respondent_id], references: [id], onDelete: SetNull)
736
+
737
+ @@index([template_id])
738
+ @@index([form_id])
739
+ @@index([entity_type, entity_id])
740
+ @@index([company_id])
741
+ @@index([status])
742
+ @@map("form_responses")
743
+ }
744
+
745
+ // ============================================
746
+ // FORMS - Created forms from templates
747
+ // ============================================
748
+
749
+ enum FormTargetType {
750
+ DRIVER
751
+ VEHICLE
752
+ COMPANY_PARTNER
753
+ CLIENT
754
+ ORDER
755
+ ROUTE
756
+ }
757
+
758
+ enum FormStatus {
759
+ ACTIVE
760
+ COMPLETED
761
+ CANCELLED
762
+ EXPIRED
763
+ }
764
+
765
+ model Form {
766
+ id String @id @default(uuid()) @db.Uuid
767
+ name String
768
+ description String?
769
+ template_id String? @db.Uuid
770
+ company_id String? @db.Uuid
771
+ target_type FormTargetType
772
+ target_ids String[] @db.Uuid
773
+ is_required Boolean @default(false)
774
+ due_date DateTime?
775
+ status FormStatus @default(ACTIVE)
776
+ created_by String? @db.Uuid
777
+ created_at DateTime @default(now())
778
+ updated_at DateTime @updatedAt
779
+
780
+ template FormTemplate? @relation(fields: [template_id], references: [id], onDelete: SetNull)
781
+ company companies? @relation(fields: [company_id], references: [id], onDelete: SetNull)
782
+ created_by_user User? @relation("FormCreator", fields: [created_by], references: [id], onDelete: SetNull)
783
+ fields FormField[]
784
+ responses FormResponse[]
785
+
786
+ @@index([company_id])
787
+ @@index([template_id])
788
+ @@index([target_type])
789
+ @@index([status])
790
+ @@index([due_date])
791
+ @@map("forms")
792
+ }
793
+
794
+ model FormField {
795
+ id String @id @default(uuid()) @db.Uuid
796
+ form_id String @db.Uuid
797
+ source_field_id String? @db.Uuid
798
+ label String
799
+ field_type FieldType
800
+ placeholder String?
801
+ help_text String?
802
+ is_required Boolean @default(false)
803
+ order Int @default(0)
804
+ options Json?
805
+ validations Json?
806
+ default_value String?
807
+ conditional_logic Json?
808
+ created_at DateTime @default(now())
809
+ updated_at DateTime @updatedAt
810
+
811
+ form Form @relation(fields: [form_id], references: [id], onDelete: Cascade)
812
+
813
+ @@index([form_id])
814
+ @@map("form_fields")
815
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delpa/mt-prisma",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Prisma ORM package for Moving Truck microservices",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -0,0 +1,104 @@
1
+ -- CreateEnum
2
+ CREATE TYPE "FieldType" AS ENUM ('TEXT', 'TEXTAREA', 'NUMBER', 'EMAIL', 'PHONE', 'DATE', 'DATETIME', 'TIME', 'SELECT', 'MULTISELECT', 'CHECKBOX', 'RADIO', 'FILE', 'IMAGE', 'SIGNATURE', 'LOCATION');
3
+
4
+ -- CreateEnum
5
+ CREATE TYPE "FormResponseStatus" AS ENUM ('DRAFT', 'SUBMITTED', 'APPROVED', 'REJECTED');
6
+
7
+ -- CreateTable
8
+ CREATE TABLE "form_templates" (
9
+ "id" UUID NOT NULL,
10
+ "name" TEXT NOT NULL,
11
+ "description" TEXT,
12
+ "company_id" UUID,
13
+ "is_active" BOOLEAN NOT NULL DEFAULT true,
14
+ "is_global" BOOLEAN NOT NULL DEFAULT false,
15
+ "category" TEXT,
16
+ "version" INTEGER NOT NULL DEFAULT 1,
17
+ "created_by" UUID,
18
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
19
+ "updated_at" TIMESTAMP(3) NOT NULL,
20
+
21
+ CONSTRAINT "form_templates_pkey" PRIMARY KEY ("id")
22
+ );
23
+
24
+ -- CreateTable
25
+ CREATE TABLE "form_fields" (
26
+ "id" UUID NOT NULL,
27
+ "template_id" UUID NOT NULL,
28
+ "label" TEXT NOT NULL,
29
+ "field_type" "FieldType" NOT NULL,
30
+ "placeholder" TEXT,
31
+ "help_text" TEXT,
32
+ "is_required" BOOLEAN NOT NULL DEFAULT false,
33
+ "order" INTEGER NOT NULL DEFAULT 0,
34
+ "options" JSONB,
35
+ "validations" JSONB,
36
+ "default_value" TEXT,
37
+ "conditional_logic" JSONB,
38
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
39
+ "updated_at" TIMESTAMP(3) NOT NULL,
40
+
41
+ CONSTRAINT "form_fields_pkey" PRIMARY KEY ("id")
42
+ );
43
+
44
+ -- CreateTable
45
+ CREATE TABLE "form_responses" (
46
+ "id" UUID NOT NULL,
47
+ "template_id" UUID NOT NULL,
48
+ "entity_type" TEXT NOT NULL,
49
+ "entity_id" UUID NOT NULL,
50
+ "company_id" UUID,
51
+ "respondent_id" UUID,
52
+ "responses" JSONB NOT NULL,
53
+ "status" "FormResponseStatus" NOT NULL DEFAULT 'DRAFT',
54
+ "submitted_at" TIMESTAMP(3),
55
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
56
+ "updated_at" TIMESTAMP(3) NOT NULL,
57
+
58
+ CONSTRAINT "form_responses_pkey" PRIMARY KEY ("id")
59
+ );
60
+
61
+ -- CreateIndex
62
+ CREATE INDEX "form_templates_company_id_idx" ON "form_templates"("company_id");
63
+
64
+ -- CreateIndex
65
+ CREATE INDEX "form_templates_is_global_idx" ON "form_templates"("is_global");
66
+
67
+ -- CreateIndex
68
+ CREATE INDEX "form_templates_category_idx" ON "form_templates"("category");
69
+
70
+ -- CreateIndex
71
+ CREATE INDEX "form_templates_is_active_idx" ON "form_templates"("is_active");
72
+
73
+ -- CreateIndex
74
+ CREATE INDEX "form_fields_template_id_idx" ON "form_fields"("template_id");
75
+
76
+ -- CreateIndex
77
+ CREATE INDEX "form_responses_template_id_idx" ON "form_responses"("template_id");
78
+
79
+ -- CreateIndex
80
+ CREATE INDEX "form_responses_entity_type_entity_id_idx" ON "form_responses"("entity_type", "entity_id");
81
+
82
+ -- CreateIndex
83
+ CREATE INDEX "form_responses_company_id_idx" ON "form_responses"("company_id");
84
+
85
+ -- CreateIndex
86
+ CREATE INDEX "form_responses_status_idx" ON "form_responses"("status");
87
+
88
+ -- AddForeignKey
89
+ ALTER TABLE "form_templates" ADD CONSTRAINT "form_templates_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
90
+
91
+ -- AddForeignKey
92
+ ALTER TABLE "form_templates" ADD CONSTRAINT "form_templates_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
93
+
94
+ -- AddForeignKey
95
+ ALTER TABLE "form_fields" ADD CONSTRAINT "form_fields_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;
96
+
97
+ -- AddForeignKey
98
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
99
+
100
+ -- AddForeignKey
101
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
102
+
103
+ -- AddForeignKey
104
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_respondent_id_fkey" FOREIGN KEY ("respondent_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,91 @@
1
+ -- CreateEnum
2
+ CREATE TYPE "AssignmentTargetType" AS ENUM ('DRIVER', 'VEHICLE', 'COMPANY_PARTNER', 'CLIENT', 'ORDER', 'ROUTE');
3
+
4
+ -- CreateEnum
5
+ CREATE TYPE "FormAssignmentStatus" AS ENUM ('ACTIVE', 'COMPLETED', 'CANCELLED', 'EXPIRED');
6
+
7
+ -- DropForeignKey
8
+ ALTER TABLE "form_responses" DROP CONSTRAINT "form_responses_template_id_fkey";
9
+
10
+ -- AlterTable
11
+ ALTER TABLE "form_responses" ADD COLUMN "assignment_id" UUID,
12
+ ALTER COLUMN "template_id" DROP NOT NULL;
13
+
14
+ -- CreateTable
15
+ CREATE TABLE "form_assignments" (
16
+ "id" UUID NOT NULL,
17
+ "name" TEXT NOT NULL,
18
+ "description" TEXT,
19
+ "template_id" UUID,
20
+ "company_id" UUID,
21
+ "target_type" "AssignmentTargetType" NOT NULL,
22
+ "target_ids" UUID[],
23
+ "is_required" BOOLEAN NOT NULL DEFAULT false,
24
+ "due_date" TIMESTAMP(3),
25
+ "status" "FormAssignmentStatus" NOT NULL DEFAULT 'ACTIVE',
26
+ "created_by" UUID,
27
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
28
+ "updated_at" TIMESTAMP(3) NOT NULL,
29
+
30
+ CONSTRAINT "form_assignments_pkey" PRIMARY KEY ("id")
31
+ );
32
+
33
+ -- CreateTable
34
+ CREATE TABLE "form_assignment_fields" (
35
+ "id" UUID NOT NULL,
36
+ "assignment_id" UUID NOT NULL,
37
+ "source_field_id" UUID,
38
+ "label" TEXT NOT NULL,
39
+ "field_type" "FieldType" NOT NULL,
40
+ "placeholder" TEXT,
41
+ "help_text" TEXT,
42
+ "is_required" BOOLEAN NOT NULL DEFAULT false,
43
+ "order" INTEGER NOT NULL DEFAULT 0,
44
+ "options" JSONB,
45
+ "validations" JSONB,
46
+ "default_value" TEXT,
47
+ "conditional_logic" JSONB,
48
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
49
+ "updated_at" TIMESTAMP(3) NOT NULL,
50
+
51
+ CONSTRAINT "form_assignment_fields_pkey" PRIMARY KEY ("id")
52
+ );
53
+
54
+ -- CreateIndex
55
+ CREATE INDEX "form_assignments_company_id_idx" ON "form_assignments"("company_id");
56
+
57
+ -- CreateIndex
58
+ CREATE INDEX "form_assignments_template_id_idx" ON "form_assignments"("template_id");
59
+
60
+ -- CreateIndex
61
+ CREATE INDEX "form_assignments_target_type_idx" ON "form_assignments"("target_type");
62
+
63
+ -- CreateIndex
64
+ CREATE INDEX "form_assignments_status_idx" ON "form_assignments"("status");
65
+
66
+ -- CreateIndex
67
+ CREATE INDEX "form_assignments_due_date_idx" ON "form_assignments"("due_date");
68
+
69
+ -- CreateIndex
70
+ CREATE INDEX "form_assignment_fields_assignment_id_idx" ON "form_assignment_fields"("assignment_id");
71
+
72
+ -- CreateIndex
73
+ CREATE INDEX "form_responses_assignment_id_idx" ON "form_responses"("assignment_id");
74
+
75
+ -- AddForeignKey
76
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE SET NULL ON UPDATE CASCADE;
77
+
78
+ -- AddForeignKey
79
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_assignment_id_fkey" FOREIGN KEY ("assignment_id") REFERENCES "form_assignments"("id") ON DELETE SET NULL ON UPDATE CASCADE;
80
+
81
+ -- AddForeignKey
82
+ ALTER TABLE "form_assignments" ADD CONSTRAINT "form_assignments_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE SET NULL ON UPDATE CASCADE;
83
+
84
+ -- AddForeignKey
85
+ ALTER TABLE "form_assignments" ADD CONSTRAINT "form_assignments_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
86
+
87
+ -- AddForeignKey
88
+ ALTER TABLE "form_assignments" ADD CONSTRAINT "form_assignments_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
89
+
90
+ -- AddForeignKey
91
+ ALTER TABLE "form_assignment_fields" ADD CONSTRAINT "form_assignment_fields_assignment_id_fkey" FOREIGN KEY ("assignment_id") REFERENCES "form_assignments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,141 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `template_id` on the `form_fields` table. All the data in the column will be lost.
5
+ - You are about to drop the column `assignment_id` on the `form_responses` table. All the data in the column will be lost.
6
+ - You are about to drop the `form_assignment_fields` table. If the table is not empty, all the data it contains will be lost.
7
+ - You are about to drop the `form_assignments` table. If the table is not empty, all the data it contains will be lost.
8
+ - Added the required column `form_id` to the `form_fields` table without a default value. This is not possible if the table is not empty.
9
+
10
+ */
11
+ -- CreateEnum
12
+ CREATE TYPE "FormTargetType" AS ENUM ('DRIVER', 'VEHICLE', 'COMPANY_PARTNER', 'CLIENT', 'ORDER', 'ROUTE');
13
+
14
+ -- CreateEnum
15
+ CREATE TYPE "FormStatus" AS ENUM ('ACTIVE', 'COMPLETED', 'CANCELLED', 'EXPIRED');
16
+
17
+ -- DropForeignKey
18
+ ALTER TABLE "form_assignment_fields" DROP CONSTRAINT "form_assignment_fields_assignment_id_fkey";
19
+
20
+ -- DropForeignKey
21
+ ALTER TABLE "form_assignments" DROP CONSTRAINT "form_assignments_company_id_fkey";
22
+
23
+ -- DropForeignKey
24
+ ALTER TABLE "form_assignments" DROP CONSTRAINT "form_assignments_created_by_fkey";
25
+
26
+ -- DropForeignKey
27
+ ALTER TABLE "form_assignments" DROP CONSTRAINT "form_assignments_template_id_fkey";
28
+
29
+ -- DropForeignKey
30
+ ALTER TABLE "form_fields" DROP CONSTRAINT "form_fields_template_id_fkey";
31
+
32
+ -- DropForeignKey
33
+ ALTER TABLE "form_responses" DROP CONSTRAINT "form_responses_assignment_id_fkey";
34
+
35
+ -- DropIndex
36
+ DROP INDEX "form_fields_template_id_idx";
37
+
38
+ -- DropIndex
39
+ DROP INDEX "form_responses_assignment_id_idx";
40
+
41
+ -- AlterTable
42
+ ALTER TABLE "form_fields" DROP COLUMN "template_id",
43
+ ADD COLUMN "form_id" UUID NOT NULL,
44
+ ADD COLUMN "source_field_id" UUID;
45
+
46
+ -- AlterTable
47
+ ALTER TABLE "form_responses" DROP COLUMN "assignment_id",
48
+ ADD COLUMN "form_id" UUID;
49
+
50
+ -- DropTable
51
+ DROP TABLE "form_assignment_fields";
52
+
53
+ -- DropTable
54
+ DROP TABLE "form_assignments";
55
+
56
+ -- DropEnum
57
+ DROP TYPE "AssignmentTargetType";
58
+
59
+ -- DropEnum
60
+ DROP TYPE "FormAssignmentStatus";
61
+
62
+ -- CreateTable
63
+ CREATE TABLE "template_fields" (
64
+ "id" UUID NOT NULL,
65
+ "template_id" UUID NOT NULL,
66
+ "label" TEXT NOT NULL,
67
+ "field_type" "FieldType" NOT NULL,
68
+ "placeholder" TEXT,
69
+ "help_text" TEXT,
70
+ "is_required" BOOLEAN NOT NULL DEFAULT false,
71
+ "order" INTEGER NOT NULL DEFAULT 0,
72
+ "options" JSONB,
73
+ "validations" JSONB,
74
+ "default_value" TEXT,
75
+ "conditional_logic" JSONB,
76
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
77
+ "updated_at" TIMESTAMP(3) NOT NULL,
78
+
79
+ CONSTRAINT "template_fields_pkey" PRIMARY KEY ("id")
80
+ );
81
+
82
+ -- CreateTable
83
+ CREATE TABLE "forms" (
84
+ "id" UUID NOT NULL,
85
+ "name" TEXT NOT NULL,
86
+ "description" TEXT,
87
+ "template_id" UUID,
88
+ "company_id" UUID,
89
+ "target_type" "FormTargetType" NOT NULL,
90
+ "target_ids" UUID[],
91
+ "is_required" BOOLEAN NOT NULL DEFAULT false,
92
+ "due_date" TIMESTAMP(3),
93
+ "status" "FormStatus" NOT NULL DEFAULT 'ACTIVE',
94
+ "created_by" UUID,
95
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
96
+ "updated_at" TIMESTAMP(3) NOT NULL,
97
+
98
+ CONSTRAINT "forms_pkey" PRIMARY KEY ("id")
99
+ );
100
+
101
+ -- CreateIndex
102
+ CREATE INDEX "template_fields_template_id_idx" ON "template_fields"("template_id");
103
+
104
+ -- CreateIndex
105
+ CREATE INDEX "forms_company_id_idx" ON "forms"("company_id");
106
+
107
+ -- CreateIndex
108
+ CREATE INDEX "forms_template_id_idx" ON "forms"("template_id");
109
+
110
+ -- CreateIndex
111
+ CREATE INDEX "forms_target_type_idx" ON "forms"("target_type");
112
+
113
+ -- CreateIndex
114
+ CREATE INDEX "forms_status_idx" ON "forms"("status");
115
+
116
+ -- CreateIndex
117
+ CREATE INDEX "forms_due_date_idx" ON "forms"("due_date");
118
+
119
+ -- CreateIndex
120
+ CREATE INDEX "form_fields_form_id_idx" ON "form_fields"("form_id");
121
+
122
+ -- CreateIndex
123
+ CREATE INDEX "form_responses_form_id_idx" ON "form_responses"("form_id");
124
+
125
+ -- AddForeignKey
126
+ ALTER TABLE "template_fields" ADD CONSTRAINT "template_fields_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE CASCADE ON UPDATE CASCADE;
127
+
128
+ -- AddForeignKey
129
+ ALTER TABLE "form_responses" ADD CONSTRAINT "form_responses_form_id_fkey" FOREIGN KEY ("form_id") REFERENCES "forms"("id") ON DELETE SET NULL ON UPDATE CASCADE;
130
+
131
+ -- AddForeignKey
132
+ ALTER TABLE "forms" ADD CONSTRAINT "forms_template_id_fkey" FOREIGN KEY ("template_id") REFERENCES "form_templates"("id") ON DELETE SET NULL ON UPDATE CASCADE;
133
+
134
+ -- AddForeignKey
135
+ ALTER TABLE "forms" ADD CONSTRAINT "forms_company_id_fkey" FOREIGN KEY ("company_id") REFERENCES "companies"("id") ON DELETE SET NULL ON UPDATE CASCADE;
136
+
137
+ -- AddForeignKey
138
+ ALTER TABLE "forms" ADD CONSTRAINT "forms_created_by_fkey" FOREIGN KEY ("created_by") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE;
139
+
140
+ -- AddForeignKey
141
+ ALTER TABLE "form_fields" ADD CONSTRAINT "form_fields_form_id_fkey" FOREIGN KEY ("form_id") REFERENCES "forms"("id") ON DELETE CASCADE ON UPDATE CASCADE;
@@ -0,0 +1,46 @@
1
+ -- CreateEnum
2
+ CREATE TYPE "PackagingType" AS ENUM ('BOX', 'PALLET', 'CRATE', 'BARREL', 'BAG', 'ROLL', 'BUNDLE', 'CONTAINER', 'LOOSE', 'OTHER');
3
+
4
+ -- CreateEnum
5
+ CREATE TYPE "ProductCategory" AS ENUM ('ELECTRONICS', 'FOOD_BEVERAGE', 'PHARMACEUTICALS', 'TEXTILES', 'MACHINERY', 'CHEMICALS', 'CONSTRUCTION', 'AUTOMOTIVE', 'AGRICULTURE', 'FURNITURE', 'PAPER', 'PLASTICS', 'METALS', 'GLASS', 'OTHER');
6
+
7
+ -- CreateEnum
8
+ CREATE TYPE "ProductSubcategory" AS ENUM ('RAW_MATERIALS', 'FINISHED_GOODS', 'SEMI_FINISHED', 'SPARE_PARTS', 'CONSUMABLES', 'HAZARDOUS', 'FRAGILE', 'PERISHABLE', 'REFRIGERATED', 'FROZEN', 'BULK', 'LIQUID', 'OVERSIZED', 'HIGH_VALUE', 'OTHER');
9
+
10
+ -- CreateTable
11
+ CREATE TABLE "products" (
12
+ "id" UUID NOT NULL,
13
+ "client_id" UUID NOT NULL,
14
+ "description" TEXT NOT NULL,
15
+ "sku" TEXT NOT NULL,
16
+ "quantity" INTEGER NOT NULL DEFAULT 0,
17
+ "packaging_type" "PackagingType" NOT NULL DEFAULT 'BOX',
18
+ "category" "ProductCategory" NOT NULL DEFAULT 'OTHER',
19
+ "subcategory" "ProductSubcategory" NOT NULL DEFAULT 'OTHER',
20
+ "dimension_unit" "DimensionUnits" NOT NULL DEFAULT 'CM',
21
+ "length" DOUBLE PRECISION,
22
+ "width" DOUBLE PRECISION,
23
+ "height" DOUBLE PRECISION,
24
+ "weight_unit" "WeightUnits" NOT NULL DEFAULT 'KG',
25
+ "weight" DOUBLE PRECISION,
26
+ "is_active" BOOLEAN NOT NULL DEFAULT true,
27
+ "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
28
+ "updated_at" TIMESTAMP(3) NOT NULL,
29
+
30
+ CONSTRAINT "products_pkey" PRIMARY KEY ("id")
31
+ );
32
+
33
+ -- CreateIndex
34
+ CREATE UNIQUE INDEX "products_sku_key" ON "products"("sku");
35
+
36
+ -- CreateIndex
37
+ CREATE INDEX "products_client_id_idx" ON "products"("client_id");
38
+
39
+ -- CreateIndex
40
+ CREATE INDEX "products_sku_idx" ON "products"("sku");
41
+
42
+ -- CreateIndex
43
+ CREATE INDEX "products_category_idx" ON "products"("category");
44
+
45
+ -- AddForeignKey
46
+ ALTER TABLE "products" ADD CONSTRAINT "products_client_id_fkey" FOREIGN KEY ("client_id") REFERENCES "clients"("id") ON DELETE CASCADE ON UPDATE CASCADE;