1
- import { randomUUID } from "crypto" ;
1
+ import { randomUUID } from "node: crypto" ;
2
2
3
3
import { explain } from "@drizzle-lab/api/extensions" ;
4
4
import { relations , sql , getTableColumns } from "drizzle-orm" ;
5
+ import type { AnyPgColumn } from "drizzle-orm/pg-core" ;
5
6
import {
6
7
pgTable ,
7
8
serial ,
@@ -13,6 +14,7 @@ import {
13
14
primaryKey ,
14
15
check ,
15
16
pgView ,
17
+ numeric ,
16
18
} from "drizzle-orm/pg-core" ;
17
19
18
20
import { info } from "@/example/pg/external" ;
@@ -149,3 +151,149 @@ export const postsRelations = relations(posts, ({ one }) => ({
149
151
relationName : "reviewer" ,
150
152
} ) ,
151
153
} ) ) ;
154
+
155
+ export const products = pgTable ( "products" , {
156
+ id : serial ( "id" ) . primaryKey ( ) ,
157
+ name : text ( "name" ) . notNull ( ) ,
158
+ price : numeric ( "price" , { precision : 10 , scale : 2 } ) . notNull ( ) ,
159
+ description : text ( "description" ) ,
160
+ categoryId : integer ( "category_id" ) . references ( ( ) => categories . id ) ,
161
+ } ) ;
162
+
163
+ export const categories = pgTable ( "categories" , {
164
+ id : serial ( "id" ) . primaryKey ( ) ,
165
+ name : text ( "name" ) . notNull ( ) ,
166
+ parentId : integer ( "parent_id" ) . references ( ( ) : AnyPgColumn => categories . id ) ,
167
+ } ) ;
168
+
169
+ export const orders = pgTable ( "orders" , {
170
+ id : serial ( "id" ) . primaryKey ( ) ,
171
+ userId : integer ( "user_id" )
172
+ . references ( ( ) => users . id )
173
+ . notNull ( ) ,
174
+ status : text ( "status" , {
175
+ enum : [ "pending" , "processing" , "shipped" , "delivered" ] ,
176
+ } ) . notNull ( ) ,
177
+ orderDate : timestamp ( "order_date" ) . defaultNow ( ) ,
178
+ } ) ;
179
+
180
+ export const orderItems = pgTable ( "order_items" , {
181
+ id : serial ( "id" ) . primaryKey ( ) ,
182
+ orderId : integer ( "order_id" )
183
+ . references ( ( ) => orders . id )
184
+ . notNull ( ) ,
185
+ productId : integer ( "product_id" )
186
+ . references ( ( ) => products . id )
187
+ . notNull ( ) ,
188
+ quantity : integer ( "quantity" ) . notNull ( ) ,
189
+ price : numeric ( "price" , { precision : 10 , scale : 2 } ) . notNull ( ) ,
190
+ } ) ;
191
+
192
+ export const reviews = pgTable ( "reviews" , {
193
+ id : serial ( "id" ) . primaryKey ( ) ,
194
+ userId : integer ( "user_id" )
195
+ . references ( ( ) => users . id )
196
+ . notNull ( ) ,
197
+ productId : integer ( "product_id" )
198
+ . references ( ( ) => products . id )
199
+ . notNull ( ) ,
200
+ rating : integer ( "rating" ) . notNull ( ) ,
201
+ comment : text ( "comment" ) ,
202
+ createdAt : timestamp ( "created_at" ) . defaultNow ( ) ,
203
+ } ) ;
204
+
205
+ export const inventory = pgTable ( "inventory" , {
206
+ id : serial ( "id" ) . primaryKey ( ) ,
207
+ productId : integer ( "product_id" )
208
+ . references ( ( ) => products . id )
209
+ . notNull ( ) ,
210
+ quantity : integer ( "quantity" ) . notNull ( ) ,
211
+ lastUpdated : timestamp ( "last_updated" ) . defaultNow ( ) ,
212
+ } ) ;
213
+
214
+ export const suppliers = pgTable ( "suppliers" , {
215
+ id : serial ( "id" ) . primaryKey ( ) ,
216
+ name : text ( "name" ) . notNull ( ) ,
217
+ contactPerson : text ( "contact_person" ) ,
218
+ email : text ( "email" ) ,
219
+ phone : text ( "phone" ) ,
220
+ } ) ;
221
+
222
+ export const productSuppliers = pgTable ( "product_suppliers" , {
223
+ id : serial ( "id" ) . primaryKey ( ) ,
224
+ productId : integer ( "product_id" )
225
+ . references ( ( ) => products . id )
226
+ . notNull ( ) ,
227
+ supplierId : integer ( "supplier_id" )
228
+ . references ( ( ) => suppliers . id )
229
+ . notNull ( ) ,
230
+ cost : numeric ( "cost" , { precision : 10 , scale : 2 } ) . notNull ( ) ,
231
+ } ) ;
232
+
233
+ export const shippingAddresses = pgTable ( "shipping_addresses" , {
234
+ id : serial ( "id" ) . primaryKey ( ) ,
235
+ userId : integer ( "user_id" )
236
+ . references ( ( ) => users . id )
237
+ . notNull ( ) ,
238
+ address : text ( "address" ) . notNull ( ) ,
239
+ city : text ( "city" ) . notNull ( ) ,
240
+ state : text ( "state" ) . notNull ( ) ,
241
+ country : text ( "country" ) . notNull ( ) ,
242
+ postalCode : text ( "postal_code" ) . notNull ( ) ,
243
+ } ) ;
244
+
245
+ export const promotions = pgTable ( "promotions" , {
246
+ id : serial ( "id" ) . primaryKey ( ) ,
247
+ code : text ( "code" ) . notNull ( ) . unique ( ) ,
248
+ discountPercentage : numeric ( "discount_percentage" , {
249
+ precision : 5 ,
250
+ scale : 2 ,
251
+ } ) . notNull ( ) ,
252
+ startDate : timestamp ( "start_date" ) . notNull ( ) ,
253
+ endDate : timestamp ( "end_date" ) . notNull ( ) ,
254
+ } ) ;
255
+
256
+ export const wishlist = pgTable ( "wishlist" , {
257
+ id : serial ( "id" ) . primaryKey ( ) ,
258
+ userId : integer ( "user_id" )
259
+ . references ( ( ) => users . id )
260
+ . notNull ( ) ,
261
+ productId : integer ( "product_id" )
262
+ . references ( ( ) => products . id )
263
+ . notNull ( ) ,
264
+ addedAt : timestamp ( "added_at" ) . defaultNow ( ) ,
265
+ } ) ;
266
+
267
+ export const productTags = pgTable ( "product_tags" , {
268
+ id : serial ( "id" ) . primaryKey ( ) ,
269
+ productId : integer ( "product_id" )
270
+ . references ( ( ) => products . id )
271
+ . notNull ( ) ,
272
+ tag : text ( "tag" ) . notNull ( ) ,
273
+ } ) ;
274
+
275
+ export const tableWithLongColumnName1 = pgTable (
276
+ "table_with_long_column_name_1" ,
277
+ {
278
+ id : serial ( "id" ) . primaryKey ( ) ,
279
+ thisIsAReallyLongColumnNameThatIsExactlySixtyFourCharactersLong : text (
280
+ "this_is_a_really_long_column_name_that_is_exactly_sixty_four_characters_long" ,
281
+ ) ,
282
+ authorId : integer ( "author_id" )
283
+ . references ( ( ) => users . id )
284
+ . notNull ( ) ,
285
+ } ,
286
+ ) ;
287
+
288
+ export const tableWithLongColumnName2 = pgTable (
289
+ "table_with_long_column_name_2" ,
290
+ {
291
+ id : serial ( "id" ) . primaryKey ( ) ,
292
+ anotherExtremelyLongColumnNameThatIsAlsoSixtyFourCharactersLong : integer (
293
+ "another_extremely_long_column_name_that_is_also_sixty_four_characters_long" ,
294
+ ) ,
295
+ authorId : integer ( "author_id" )
296
+ . references ( ( ) => users . id )
297
+ . notNull ( ) ,
298
+ } ,
299
+ ) ;
0 commit comments