1- import { relations , sql } from 'drizzle-orm'
1+ import { relations } from 'drizzle-orm'
22import { boolean , pgTable , text , timestamp , uuid , varchar } from 'drizzle-orm/pg-core'
33
44const timestamps = {
@@ -8,9 +8,7 @@ const timestamps = {
88}
99
1010export const users = pgTable ( 'users' , {
11- id : uuid ( 'id' )
12- . primaryKey ( )
13- . default ( sql `gen_random_uuid()` ) ,
11+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
1412 name : text ( 'name' ) . notNull ( ) ,
1513 email : text ( 'email' ) . notNull ( ) . unique ( ) ,
1614 emailVerified : boolean ( 'email_verified' ) . notNull ( ) . default ( false ) ,
@@ -19,7 +17,7 @@ export const users = pgTable('users', {
1917} )
2018
2119export const sessions = pgTable ( 'session' , {
22- id : text ( 'id' ) . primaryKey ( ) ,
20+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
2321 expiresAt : timestamp ( 'expires_at' ) . notNull ( ) ,
2422 token : text ( 'token' ) . notNull ( ) . unique ( ) ,
2523 ipAddress : text ( 'ip_address' ) ,
@@ -31,7 +29,7 @@ export const sessions = pgTable('session', {
3129} )
3230
3331export const accounts = pgTable ( 'account' , {
34- id : text ( 'id' ) . primaryKey ( ) ,
32+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
3533 accountId : text ( 'account_id' ) . notNull ( ) ,
3634 providerId : text ( 'provider_id' ) . notNull ( ) ,
3735 userId : uuid ( 'user_id' )
@@ -48,17 +46,15 @@ export const accounts = pgTable('account', {
4846} )
4947
5048export const verifications = pgTable ( 'verification' , {
51- id : text ( 'id' ) . primaryKey ( ) ,
49+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
5250 identifier : text ( 'identifier' ) . notNull ( ) ,
5351 value : text ( 'value' ) . notNull ( ) ,
5452 expiresAt : timestamp ( 'expires_at' ) . notNull ( ) ,
5553 ...timestamps ,
5654} )
5755
5856export const posts = pgTable ( 'posts' , {
59- id : uuid ( )
60- . primaryKey ( )
61- . default ( sql `gen_random_uuid()` ) ,
57+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
6258 title : varchar ( ) ,
6359 content : text ( ) ,
6460 authorId : uuid ( ) . references ( ( ) => users . id ) ,
@@ -76,9 +72,7 @@ export const postsRelations = relations(posts, ({ one }) => ({
7672} ) )
7773
7874export const categories = pgTable ( 'categories' , {
79- id : uuid ( )
80- . primaryKey ( )
81- . default ( sql `gen_random_uuid()` ) ,
75+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
8276 name : varchar ( ) . notNull ( ) ,
8377 ownerId : uuid ( ) . references ( ( ) => users . id ) ,
8478 ...timestamps ,
@@ -91,9 +85,7 @@ export const categoriesRelations = relations(categories, ({ many, one }) => ({
9185} ) )
9286
9387export const categoryTags = pgTable ( 'categoryTags' , {
94- id : uuid ( )
95- . primaryKey ( )
96- . default ( sql `gen_random_uuid()` ) ,
88+ id : uuid ( 'id' ) . primaryKey ( ) . defaultRandom ( ) ,
9789 name : varchar ( ) . notNull ( ) ,
9890 category : uuid ( ) . references ( ( ) => categories . id ) ,
9991 ...timestamps ,
0 commit comments