11import { Kysely , sql } from 'kysely'
22
33export async function up ( db : Kysely < any > ) : Promise < void > {
4- // User Table
5- await db . schema
6- . createTable ( 'user' )
7- . addColumn ( 'id' , 'varchar(255)' , ( col ) => col . primaryKey ( ) )
8- . addColumn ( 'name' , 'text' , ( col ) => col . notNull ( ) )
9- . addColumn ( 'email' , 'text' , ( col ) => col . notNull ( ) . unique ( ) )
10- . addColumn ( 'email_verified' , 'boolean' , ( col ) => col . notNull ( ) )
11- . addColumn ( 'image' , 'text' )
12- . addColumn ( 'created_at' , 'timestamp' , ( col ) =>
13- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
14- )
15- . addColumn ( 'updated_at' , 'timestamp' , ( col ) =>
16- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
17- )
18- . execute ( )
19-
20- // Session Table
21- await db . schema
22- . createTable ( 'session' )
23- . addColumn ( 'id' , 'varchar(255)' , ( col ) => col . primaryKey ( ) )
24- . addColumn ( 'expires_at' , 'timestamp' , ( col ) => col . notNull ( ) )
25- . addColumn ( 'token' , 'text' , ( col ) => col . notNull ( ) . unique ( ) )
26- . addColumn ( 'created_at' , 'timestamp' , ( col ) =>
27- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
28- )
29- . addColumn ( 'updated_at' , 'timestamp' , ( col ) =>
30- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
31- )
32- . addColumn ( 'ip_address' , 'text' )
33- . addColumn ( 'user_agent' , 'text' )
34- . addColumn ( 'user_id' , 'varchar(255)' , ( col ) =>
35- col . references ( 'user.id' ) . onDelete ( 'cascade' ) . notNull ( )
36- )
37- . execute ( )
38-
39- // Account Table
40- await db . schema
41- . createTable ( 'account' )
42- . addColumn ( 'id' , 'varchar(255)' , ( col ) => col . primaryKey ( ) )
43- . addColumn ( 'account_id' , 'text' , ( col ) => col . notNull ( ) )
44- . addColumn ( 'provider_id' , 'text' , ( col ) => col . notNull ( ) )
45- . addColumn ( 'user_id' , 'varchar(255)' , ( col ) =>
46- col . references ( 'user.id' ) . onDelete ( 'cascade' ) . notNull ( )
47- )
48- . addColumn ( 'access_token' , 'text' )
49- . addColumn ( 'refresh_token' , 'text' )
50- . addColumn ( 'id_token' , 'text' )
51- . addColumn ( 'access_token_expires_at' , 'timestamp' )
52- . addColumn ( 'refresh_token_expires_at' , 'timestamp' )
53- . addColumn ( 'scope' , 'text' )
54- . addColumn ( 'password' , 'text' )
55- . addColumn ( 'created_at' , 'timestamp' , ( col ) =>
56- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
57- )
58- . addColumn ( 'updated_at' , 'timestamp' , ( col ) =>
59- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP` )
60- )
61- . execute ( )
62-
63- // Verification Table
64- await db . schema
65- . createTable ( 'verification' )
66- . addColumn ( 'id' , 'varchar(255)' , ( col ) => col . primaryKey ( ) )
67- . addColumn ( 'identifier' , 'text' , ( col ) => col . notNull ( ) )
68- . addColumn ( 'value' , 'text' , ( col ) => col . notNull ( ) )
69- . addColumn ( 'expires_at' , 'timestamp' , ( col ) => col . notNull ( ) )
70- . addColumn ( 'created_at' , 'timestamp' )
71- . addColumn ( 'updated_at' , 'timestamp' )
72- . execute ( )
73-
744 // Skill Table
755 await db . schema
766 . createTable ( 'skill' )
77- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
78- . addColumn ( 'name' , 'text ' , ( col ) => col . notNull ( ) . unique ( ) )
7+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
8+ . addColumn ( 'name' , 'varchar(255) ' , ( col ) => col . notNull ( ) . unique ( ) )
799 . addColumn ( 'description' , 'text' )
80- . addColumn ( 'created_at' , 'timestamp ' , ( col ) =>
81- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP ` )
10+ . addColumn ( 'created_at' , 'datetime ' , ( col ) =>
11+ col . notNull ( ) . defaultTo ( sql `GETDATE() ` )
8212 )
83- . addColumn ( 'updated_at' , 'timestamp ' , ( col ) =>
84- col . notNull ( ) . defaultTo ( sql `CURRENT_TIMESTAMP ` )
13+ . addColumn ( 'updated_at' , 'datetime ' , ( col ) =>
14+ col . notNull ( ) . defaultTo ( sql `GETDATE() ` )
8515 )
8616 . execute ( )
8717
8818 // UserSkill Table
8919 await db . schema
9020 . createTable ( 'user_skill' )
91- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
92- . addColumn ( 'user_id' , 'varchar(255 )' , ( col ) =>
21+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
22+ . addColumn ( 'user_id' , 'varchar(36 )' , ( col ) =>
9323 col . references ( 'user.id' ) . onDelete ( 'cascade' ) . notNull ( )
9424 )
9525 . addColumn ( 'skill_id' , 'integer' , ( col ) =>
9626 col . references ( 'skill.id' ) . onDelete ( 'cascade' ) . notNull ( )
9727 )
98- . addColumn ( 'acquired_at' , 'timestamp ' )
28+ . addColumn ( 'acquired_at' , 'datetime ' )
9929 . addColumn ( 'level' , 'integer' )
10030 . execute ( )
10131
10232 // Certification Table
10333 await db . schema
10434 . createTable ( 'certification' )
105- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
35+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
10636 . addColumn ( 'name' , 'text' , ( col ) => col . notNull ( ) )
10737 . addColumn ( 'issuer' , 'text' )
10838 . execute ( )
10939
11040 // UserCertification Table
11141 await db . schema
11242 . createTable ( 'user_certification' )
113- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
114- . addColumn ( 'user_id' , 'varchar(255 )' , ( col ) =>
43+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
44+ . addColumn ( 'user_id' , 'varchar(36 )' , ( col ) =>
11545 col . references ( 'user.id' ) . onDelete ( 'cascade' ) . notNull ( )
11646 )
11747 . addColumn ( 'cert_id' , 'integer' , ( col ) =>
11848 col . references ( 'certification.id' ) . onDelete ( 'cascade' ) . notNull ( )
11949 )
120- . addColumn ( 'issued_at' , 'timestamp ' )
121- . addColumn ( 'expires_at' , 'timestamp ' )
50+ . addColumn ( 'issued_at' , 'datetime ' )
51+ . addColumn ( 'expires_at' , 'datetime ' )
12252 . execute ( )
12353
12454 // Role Table
12555 await db . schema
12656 . createTable ( 'role' )
127- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
57+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
12858 . addColumn ( 'name' , 'text' , ( col ) => col . notNull ( ) )
12959 . addColumn ( 'description' , 'text' )
13060 . execute ( )
13161
13262 // Client Table
13363 await db . schema
13464 . createTable ( 'client' )
135- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
65+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
13666 . addColumn ( 'name' , 'text' , ( col ) => col . notNull ( ) )
13767 . addColumn ( 'description' , 'text' )
13868 . execute ( )
13969
14070 // Project Table
14171 await db . schema
14272 . createTable ( 'project' )
143- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
73+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
14474 . addColumn ( 'name' , 'text' , ( col ) => col . notNull ( ) )
14575 . addColumn ( 'description' , 'text' )
146- . addColumn ( 'started_at' , 'timestamp ' )
147- . addColumn ( 'ended_at' , 'timestamp ' )
76+ . addColumn ( 'started_at' , 'datetime ' )
77+ . addColumn ( 'ended_at' , 'datetime ' )
14878 . execute ( )
14979
15080 // ClientProject Table
15181 await db . schema
15282 . createTable ( 'client_project' )
153- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
83+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
15484 . addColumn ( 'client_id' , 'integer' , ( col ) =>
15585 col . references ( 'client.id' ) . onDelete ( 'cascade' ) . notNull ( )
15686 )
@@ -162,11 +92,11 @@ export async function up(db: Kysely<any>): Promise<void> {
16292 // ProjectUser Table
16393 await db . schema
16494 . createTable ( 'project_user' )
165- . addColumn ( 'id' , 'serial ' , ( col ) => col . primaryKey ( ) )
95+ . addColumn ( 'id' , 'integer ' , ( col ) => col . primaryKey ( ) )
16696 . addColumn ( 'project_id' , 'integer' , ( col ) =>
16797 col . references ( 'project.id' ) . onDelete ( 'cascade' ) . notNull ( )
16898 )
169- . addColumn ( 'user_id' , 'varchar(255 )' , ( col ) =>
99+ . addColumn ( 'user_id' , 'varchar(36 )' , ( col ) =>
170100 col . references ( 'user.id' ) . onDelete ( 'cascade' ) . notNull ( )
171101 )
172102 . addColumn ( 'role_id' , 'integer' , ( col ) =>
0 commit comments