@coursebuilder/adapter-drizzle 0.0.7 → 0.1.1

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.
Files changed (161) hide show
  1. package/dist/{chunk-ICL7XZ2Y.js → chunk-27KREOQW.js} +4 -4
  2. package/dist/{chunk-KVN3JV7C.js → chunk-44VDBYFU.js} +6 -6
  3. package/dist/{chunk-VEFCDI73.js → chunk-75V6F7LZ.js} +12 -12
  4. package/dist/{chunk-SQR6UWVO.js → chunk-7LAAAEVE.js} +165 -11
  5. package/dist/{chunk-TA6VLEV5.js → chunk-AFQGYW7Z.js} +4 -4
  6. package/dist/{chunk-US2EXVMI.js → chunk-CPE4P26C.js} +4 -4
  7. package/dist/{chunk-VZABQCFH.js → chunk-IN6G6MTW.js} +4 -4
  8. package/dist/{chunk-4HDU7QIB.js → chunk-ISURSRBK.js} +345 -324
  9. package/dist/{chunk-AIDEJDKJ.js → chunk-JKRFXYAR.js} +4 -4
  10. package/dist/{chunk-KI47TR7F.js → chunk-L2TQQYG4.js} +4 -4
  11. package/dist/{chunk-UY3DVPP3.js → chunk-LSOPFMDB.js} +4 -4
  12. package/dist/chunk-MCFL2YV4.js +4679 -0
  13. package/dist/{chunk-PFN4YUQZ.js → chunk-MYRB6GLJ.js} +4 -3
  14. package/dist/chunk-NZDLUQWP.js +44 -0
  15. package/dist/{chunk-22KIKVBY.js → chunk-O2KKII62.js} +163 -10
  16. package/dist/{chunk-MBQ3TMHH.js → chunk-OIUOQ3TT.js} +4 -4
  17. package/dist/chunk-QZOBGJSV.js +78 -0
  18. package/dist/chunk-RVYJDDZD.js +75 -0
  19. package/dist/chunk-V6QEDDFG.js +49 -0
  20. package/dist/{chunk-FRNVLW7N.js → chunk-Y34AIPU7.js} +34 -303
  21. package/dist/index.js +21 -17
  22. package/dist/lib/mysql/index.cjs +5896 -1367
  23. package/dist/lib/mysql/index.cjs.map +1 -1
  24. package/dist/lib/mysql/index.d.ts +325 -129
  25. package/dist/lib/mysql/index.js +19 -15
  26. package/dist/lib/mysql/schemas/auth/accounts.cjs +73 -57
  27. package/dist/lib/mysql/schemas/auth/accounts.cjs.map +1 -1
  28. package/dist/lib/mysql/schemas/auth/accounts.js +7 -1
  29. package/dist/lib/mysql/schemas/auth/permissions.cjs +9 -98
  30. package/dist/lib/mysql/schemas/auth/permissions.cjs.map +1 -1
  31. package/dist/lib/mysql/schemas/auth/permissions.d.ts +1 -3
  32. package/dist/lib/mysql/schemas/auth/permissions.js +1 -3
  33. package/dist/lib/mysql/schemas/auth/role-permissions.cjs +64 -43
  34. package/dist/lib/mysql/schemas/auth/role-permissions.cjs.map +1 -1
  35. package/dist/lib/mysql/schemas/auth/role-permissions.js +8 -1
  36. package/dist/lib/mysql/schemas/auth/roles.cjs +63 -46
  37. package/dist/lib/mysql/schemas/auth/roles.cjs.map +1 -1
  38. package/dist/lib/mysql/schemas/auth/roles.js +7 -1
  39. package/dist/lib/mysql/schemas/auth/sessions.cjs +63 -47
  40. package/dist/lib/mysql/schemas/auth/sessions.cjs.map +1 -1
  41. package/dist/lib/mysql/schemas/auth/sessions.js +8 -2
  42. package/dist/lib/mysql/schemas/auth/user-permissions.cjs +97 -82
  43. package/dist/lib/mysql/schemas/auth/user-permissions.cjs.map +1 -1
  44. package/dist/lib/mysql/schemas/auth/user-permissions.js +7 -1
  45. package/dist/lib/mysql/schemas/auth/user-roles.cjs +65 -48
  46. package/dist/lib/mysql/schemas/auth/user-roles.cjs.map +1 -1
  47. package/dist/lib/mysql/schemas/auth/user-roles.js +7 -1
  48. package/dist/lib/mysql/schemas/auth/users.cjs +233 -132
  49. package/dist/lib/mysql/schemas/auth/users.cjs.map +1 -1
  50. package/dist/lib/mysql/schemas/auth/users.d.ts +2 -1
  51. package/dist/lib/mysql/schemas/auth/users.js +7 -1
  52. package/dist/lib/mysql/schemas/commerce/coupon.cjs +4 -4
  53. package/dist/lib/mysql/schemas/commerce/coupon.cjs.map +1 -1
  54. package/dist/lib/mysql/schemas/commerce/coupon.d.ts +6 -6
  55. package/dist/lib/mysql/schemas/commerce/coupon.js +1 -1
  56. package/dist/lib/mysql/schemas/commerce/merchant-account.cjs +2 -2
  57. package/dist/lib/mysql/schemas/commerce/merchant-account.cjs.map +1 -1
  58. package/dist/lib/mysql/schemas/commerce/merchant-account.d.ts +3 -3
  59. package/dist/lib/mysql/schemas/commerce/merchant-account.js +1 -1
  60. package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs +2 -2
  61. package/dist/lib/mysql/schemas/commerce/merchant-charge.cjs.map +1 -1
  62. package/dist/lib/mysql/schemas/commerce/merchant-charge.d.ts +3 -3
  63. package/dist/lib/mysql/schemas/commerce/merchant-charge.js +1 -1
  64. package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs +2 -2
  65. package/dist/lib/mysql/schemas/commerce/merchant-customer.cjs.map +1 -1
  66. package/dist/lib/mysql/schemas/commerce/merchant-customer.d.ts +3 -3
  67. package/dist/lib/mysql/schemas/commerce/merchant-customer.js +1 -1
  68. package/dist/lib/mysql/schemas/commerce/merchant-price.cjs +2 -2
  69. package/dist/lib/mysql/schemas/commerce/merchant-price.cjs.map +1 -1
  70. package/dist/lib/mysql/schemas/commerce/merchant-price.d.ts +3 -3
  71. package/dist/lib/mysql/schemas/commerce/merchant-price.js +1 -1
  72. package/dist/lib/mysql/schemas/commerce/merchant-product.cjs +2 -2
  73. package/dist/lib/mysql/schemas/commerce/merchant-product.cjs.map +1 -1
  74. package/dist/lib/mysql/schemas/commerce/merchant-product.d.ts +3 -3
  75. package/dist/lib/mysql/schemas/commerce/merchant-product.js +1 -1
  76. package/dist/lib/mysql/schemas/commerce/price.cjs +2 -2
  77. package/dist/lib/mysql/schemas/commerce/price.cjs.map +1 -1
  78. package/dist/lib/mysql/schemas/commerce/price.d.ts +3 -3
  79. package/dist/lib/mysql/schemas/commerce/price.js +1 -1
  80. package/dist/lib/mysql/schemas/commerce/product.cjs +2 -2
  81. package/dist/lib/mysql/schemas/commerce/product.cjs.map +1 -1
  82. package/dist/lib/mysql/schemas/commerce/product.d.ts +3 -3
  83. package/dist/lib/mysql/schemas/commerce/product.js +1 -1
  84. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs +10 -10
  85. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.cjs.map +1 -1
  86. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.d.ts +15 -15
  87. package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +1 -1
  88. package/dist/lib/mysql/schemas/commerce/purchase.cjs +320 -21
  89. package/dist/lib/mysql/schemas/commerce/purchase.cjs.map +1 -1
  90. package/dist/lib/mysql/schemas/commerce/purchase.d.ts +12 -4
  91. package/dist/lib/mysql/schemas/commerce/purchase.js +11 -1
  92. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs +130 -0
  93. package/dist/lib/mysql/schemas/commerce/upgradable-products.cjs.map +1 -0
  94. package/dist/lib/mysql/schemas/commerce/upgradable-products.d.ts +101 -0
  95. package/dist/lib/mysql/schemas/commerce/upgradable-products.js +11 -0
  96. package/dist/lib/mysql/schemas/commerce/upgradable-products.js.map +1 -0
  97. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs +90 -72
  98. package/dist/lib/mysql/schemas/communication/communication-preferences.cjs.map +1 -1
  99. package/dist/lib/mysql/schemas/communication/communication-preferences.js +7 -1
  100. package/dist/lib/mysql/schemas/content/content-contributions.cjs +94 -76
  101. package/dist/lib/mysql/schemas/content/content-contributions.cjs.map +1 -1
  102. package/dist/lib/mysql/schemas/content/content-contributions.js +7 -1
  103. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs +68 -53
  104. package/dist/lib/mysql/schemas/content/content-resource-resource.cjs.map +1 -1
  105. package/dist/lib/mysql/schemas/content/content-resource-resource.d.ts +1 -1
  106. package/dist/lib/mysql/schemas/content/content-resource-resource.js +7 -1
  107. package/dist/lib/mysql/schemas/content/content-resource.cjs +81 -103
  108. package/dist/lib/mysql/schemas/content/content-resource.cjs.map +1 -1
  109. package/dist/lib/mysql/schemas/content/content-resource.d.ts +0 -1
  110. package/dist/lib/mysql/schemas/content/content-resource.js +7 -1
  111. package/dist/lib/mysql/schemas/content/contribution-types.cjs +11 -102
  112. package/dist/lib/mysql/schemas/content/contribution-types.cjs.map +1 -1
  113. package/dist/lib/mysql/schemas/content/contribution-types.d.ts +1 -3
  114. package/dist/lib/mysql/schemas/content/contribution-types.js +1 -3
  115. package/dist/lib/mysql/schemas/content/resource-progress.cjs +3 -3
  116. package/dist/lib/mysql/schemas/content/resource-progress.cjs.map +1 -1
  117. package/dist/lib/mysql/schemas/content/resource-progress.d.ts +9 -9
  118. package/dist/lib/mysql/schemas/content/resource-progress.js +1 -1
  119. package/dist/lib/mysql/utils.cjs +51 -0
  120. package/dist/lib/mysql/utils.cjs.map +1 -0
  121. package/dist/lib/mysql/utils.d.ts +12 -0
  122. package/dist/lib/mysql/utils.js +29 -0
  123. package/dist/lib/mysql/utils.js.map +1 -0
  124. package/dist/lib/pg.cjs +4289 -9
  125. package/dist/lib/pg.cjs.map +1 -1
  126. package/dist/lib/pg.d.ts +91 -0
  127. package/dist/lib/pg.js +2 -1
  128. package/dist/lib/sqlite.cjs +4285 -8
  129. package/dist/lib/sqlite.cjs.map +1 -1
  130. package/dist/lib/sqlite.js +2 -1
  131. package/package.json +6 -4
  132. package/src/lib/mysql/index.ts +694 -34
  133. package/src/lib/mysql/schemas/auth/accounts.ts +5 -1
  134. package/src/lib/mysql/schemas/auth/permissions.ts +1 -3
  135. package/src/lib/mysql/schemas/auth/role-permissions.ts +2 -0
  136. package/src/lib/mysql/schemas/auth/roles.ts +1 -1
  137. package/src/lib/mysql/schemas/auth/sessions.ts +5 -1
  138. package/src/lib/mysql/schemas/auth/user-permissions.ts +2 -0
  139. package/src/lib/mysql/schemas/auth/user-roles.ts +2 -0
  140. package/src/lib/mysql/schemas/auth/users.ts +23 -6
  141. package/src/lib/mysql/schemas/commerce/coupon.ts +3 -3
  142. package/src/lib/mysql/schemas/commerce/merchant-account.ts +2 -2
  143. package/src/lib/mysql/schemas/commerce/merchant-charge.ts +2 -2
  144. package/src/lib/mysql/schemas/commerce/merchant-customer.ts +2 -2
  145. package/src/lib/mysql/schemas/commerce/merchant-price.ts +2 -2
  146. package/src/lib/mysql/schemas/commerce/merchant-product.ts +2 -2
  147. package/src/lib/mysql/schemas/commerce/price.ts +2 -2
  148. package/src/lib/mysql/schemas/commerce/product.ts +2 -2
  149. package/src/lib/mysql/schemas/commerce/purchase-user-transfer.ts +6 -6
  150. package/src/lib/mysql/schemas/commerce/purchase.ts +49 -3
  151. package/src/lib/mysql/schemas/commerce/upgradable-products.ts +58 -0
  152. package/src/lib/mysql/schemas/communication/communication-preferences.ts +3 -0
  153. package/src/lib/mysql/schemas/content/content-contributions.ts +3 -0
  154. package/src/lib/mysql/schemas/content/content-resource-resource.ts +1 -1
  155. package/src/lib/mysql/schemas/content/content-resource.ts +1 -2
  156. package/src/lib/mysql/schemas/content/contribution-types.ts +1 -4
  157. package/src/lib/mysql/schemas/content/resource-progress.ts +3 -3
  158. package/src/lib/mysql/utils.ts +23 -0
  159. package/src/lib/pg.ts +298 -16
  160. package/src/lib/sqlite.ts +290 -15
  161. package/dist/chunk-BRGTUNY2.js +0 -78
@@ -47,6 +47,10 @@ export function getAccountsRelationsSchema(mysqlTable: MySqlTableFn) {
47
47
  const accounts = getAccountsSchema(mysqlTable)
48
48
  const users = getUsersSchema(mysqlTable)
49
49
  return relations(accounts, ({ one }) => ({
50
- user: one(users, { fields: [accounts.userId], references: [users.id] }),
50
+ user: one(users, {
51
+ fields: [accounts.userId],
52
+ references: [users.id],
53
+ relationName: 'user',
54
+ }),
51
55
  }))
52
56
  }
@@ -38,7 +38,5 @@ export function getPermissionsSchema(mysqlTable: MySqlTableFn) {
38
38
  }
39
39
 
40
40
  export function getPermissionsRelationsSchema(mysqlTable: MySqlTableFn) {
41
- return relations(getPermissionsSchema(mysqlTable), ({ many }) => ({
42
- rolePermissions: many(getRolePermissionsSchema(mysqlTable)),
43
- }))
41
+ return relations(getPermissionsSchema(mysqlTable), ({ many }) => ({}))
44
42
  }
@@ -47,10 +47,12 @@ export function getRolePermissionsRelationsSchema(mysqlTable: MySqlTableFn) {
47
47
  role: one(roles, {
48
48
  fields: [rolePermissions.roleId],
49
49
  references: [roles.id],
50
+ relationName: 'role',
50
51
  }),
51
52
  permission: one(permissions, {
52
53
  fields: [rolePermissions.permissionId],
53
54
  references: [permissions.id],
55
+ relationName: 'permission',
54
56
  }),
55
57
  }))
56
58
  }
@@ -41,6 +41,6 @@ export function getRolesRelationsSchema(mysqlTable: MySqlTableFn) {
41
41
  const roles = getRolesSchema(mysqlTable)
42
42
  const userRoles = getUserRolesSchema(mysqlTable)
43
43
  return relations(roles, ({ many }) => ({
44
- userRoles: many(userRoles),
44
+ userRoles: many(userRoles, { relationName: 'role' }),
45
45
  }))
46
46
  }
@@ -23,6 +23,10 @@ export function getSessionRelationsSchema(mysqlTable: MySqlTableFn) {
23
23
  const sessions = getSessionsSchema(mysqlTable)
24
24
  const users = getUsersSchema(mysqlTable)
25
25
  return relations(sessions, ({ one }) => ({
26
- user: one(users, { fields: [sessions.userId], references: [users.id] }),
26
+ user: one(users, {
27
+ fields: [sessions.userId],
28
+ references: [users.id],
29
+ relationName: 'user',
30
+ }),
27
31
  }))
28
32
  }
@@ -47,10 +47,12 @@ export function getUserPermissionsRelationsSchema(mysqlTable: MySqlTableFn) {
47
47
  user: one(users, {
48
48
  fields: [userPermissions.userId],
49
49
  references: [users.id],
50
+ relationName: 'user',
50
51
  }),
51
52
  permission: one(permissions, {
52
53
  fields: [userPermissions.permissionId],
53
54
  references: [permissions.id],
55
+ relationName: 'permission',
54
56
  }),
55
57
  }))
56
58
  }
@@ -47,10 +47,12 @@ export function getUserRolesRelationsSchema(mysqlTable: MySqlTableFn) {
47
47
  user: one(users, {
48
48
  fields: [userRoles.userId],
49
49
  references: [users.id],
50
+ relationName: 'role',
50
51
  }),
51
52
  role: one(roles, {
52
53
  fields: [userRoles.roleId],
53
54
  references: [roles.id],
55
+ relationName: 'user',
54
56
  }),
55
57
  }))
56
58
  }
@@ -7,6 +7,7 @@ import {
7
7
  varchar,
8
8
  } from 'drizzle-orm/mysql-core'
9
9
 
10
+ import { getPurchaseSchema } from '../commerce/purchase.js'
10
11
  import { getCommunicationPreferencesSchema } from '../communication/communication-preferences.js'
11
12
  import { getContentContributionsSchema } from '../content/content-contributions.js'
12
13
  import { getContentResourceSchema } from '../content/content-resource.js'
@@ -48,12 +49,28 @@ export function getUsersRelationsSchema(mysqlTable: MySqlTableFn) {
48
49
  const userPermissions = getUserPermissionsSchema(mysqlTable)
49
50
  const contentContributions = getContentContributionsSchema(mysqlTable)
50
51
  const contentResource = getContentResourceSchema(mysqlTable)
52
+ const purchases = getPurchaseSchema(mysqlTable)
51
53
  return relations(users, ({ many }) => ({
52
- accounts: many(accounts),
53
- communicationPreferences: many(communicationPreferences),
54
- userRoles: many(userRoles),
55
- userPermissions: many(userPermissions),
56
- contributions: many(contentContributions),
57
- createdContent: many(contentResource),
54
+ accounts: many(accounts, {
55
+ relationName: 'user',
56
+ }),
57
+ purchases: many(purchases, {
58
+ relationName: 'user',
59
+ }),
60
+ communicationPreferences: many(communicationPreferences, {
61
+ relationName: 'user',
62
+ }),
63
+ roles: many(userRoles, {
64
+ relationName: 'user',
65
+ }),
66
+ userPermissions: many(userPermissions, {
67
+ relationName: 'user',
68
+ }),
69
+ contributions: many(contentContributions, {
70
+ relationName: 'user',
71
+ }),
72
+ createdContent: many(contentResource, {
73
+ relationName: 'user',
74
+ }),
58
75
  }))
59
76
  }
@@ -1,11 +1,11 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  decimal,
5
4
  int,
6
5
  json,
7
6
  MySqlTableFn,
8
7
  primaryKey,
8
+ timestamp,
9
9
  tinyint,
10
10
  unique,
11
11
  varchar,
@@ -17,10 +17,10 @@ export function getCouponSchema(mysqlTable: MySqlTableFn) {
17
17
  {
18
18
  id: varchar('id', { length: 191 }).notNull(),
19
19
  code: varchar('code', { length: 191 }),
20
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
20
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
21
21
  .default(sql`CURRENT_TIMESTAMP(3)`)
22
22
  .notNull(),
23
- expires: datetime('expires', { mode: 'string', fsp: 3 }),
23
+ expires: timestamp('expires', { mode: 'date', fsp: 3 }),
24
24
  metadata: json('fields').$type<Record<string, any>>().default({}),
25
25
  maxUses: int('maxUses').default(-1).notNull(),
26
26
  default: tinyint('default').default(0).notNull(),
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  varchar,
8
8
  } from 'drizzle-orm/mysql-core'
9
9
 
@@ -13,7 +13,7 @@ export function getMerchantAccountSchema(mysqlTable: MySqlTableFn) {
13
13
  {
14
14
  id: varchar('id', { length: 191 }).notNull(),
15
15
  status: int('status').default(0).notNull(),
16
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
16
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
17
17
  .default(sql`CURRENT_TIMESTAMP(3)`)
18
18
  .notNull(),
19
19
  label: varchar('label', { length: 191 }),
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  unique,
8
8
  varchar,
9
9
  } from 'drizzle-orm/mysql-core'
@@ -22,7 +22,7 @@ export function getMerchantChargeSchema(mysqlTable: MySqlTableFn) {
22
22
  merchantProductId: varchar('merchantProductId', {
23
23
  length: 191,
24
24
  }).notNull(),
25
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
25
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
26
26
  .default(sql`CURRENT_TIMESTAMP(3)`)
27
27
  .notNull(),
28
28
  merchantCustomerId: varchar('merchantCustomerId', {
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  unique,
8
8
  varchar,
9
9
  } from 'drizzle-orm/mysql-core'
@@ -18,7 +18,7 @@ export function getMerchantCustomerSchema(mysqlTable: MySqlTableFn) {
18
18
  length: 191,
19
19
  }).notNull(),
20
20
  identifier: varchar('identifier', { length: 191 }).notNull(),
21
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
21
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
22
22
  .default(sql`CURRENT_TIMESTAMP(3)`)
23
23
  .notNull(),
24
24
  status: int('status').default(0),
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  unique,
8
8
  varchar,
9
9
  } from 'drizzle-orm/mysql-core'
@@ -21,7 +21,7 @@ export function getMerchantPriceSchema(mysqlTable: MySqlTableFn) {
21
21
  }).notNull(),
22
22
  status: int('status').default(0),
23
23
  identifier: varchar('identifier', { length: 191 }),
24
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
24
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
25
25
  .default(sql`CURRENT_TIMESTAMP(3)`)
26
26
  .notNull(),
27
27
  priceId: varchar('priceId', { length: 191 }),
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  unique,
8
8
  varchar,
9
9
  } from 'drizzle-orm/mysql-core'
@@ -19,7 +19,7 @@ export function getMerchantProductSchema(mysqlTable: MySqlTableFn) {
19
19
  productId: varchar('productId', { length: 191 }).notNull(),
20
20
  status: int('status').default(0).notNull(),
21
21
  identifier: varchar('identifier', { length: 191 }),
22
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
22
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
23
23
  .default(sql`CURRENT_TIMESTAMP(3)`)
24
24
  .notNull(),
25
25
  },
@@ -1,11 +1,11 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  decimal,
5
4
  int,
6
5
  json,
7
6
  MySqlTableFn,
8
7
  primaryKey,
8
+ timestamp,
9
9
  varchar,
10
10
  } from 'drizzle-orm/mysql-core'
11
11
 
@@ -18,7 +18,7 @@ export function getPriceSchema(mysqlTable: MySqlTableFn) {
18
18
  nickname: varchar('nickname', { length: 191 }),
19
19
  status: int('status').default(0).notNull(),
20
20
  unitAmount: decimal('unitAmount', { precision: 10, scale: 2 }).notNull(),
21
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
21
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
22
22
  .default(sql`CURRENT_TIMESTAMP(3)`)
23
23
  .notNull(),
24
24
  metadata: json('fields').$type<Record<string, any>>().default({}),
@@ -1,10 +1,10 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  int,
5
4
  json,
6
5
  MySqlTableFn,
7
6
  primaryKey,
7
+ timestamp,
8
8
  varchar,
9
9
  } from 'drizzle-orm/mysql-core'
10
10
 
@@ -16,7 +16,7 @@ export function getProductSchema(mysqlTable: MySqlTableFn) {
16
16
  name: varchar('name', { length: 191 }).notNull(),
17
17
  key: varchar('key', { length: 191 }),
18
18
  metadata: json('fields').$type<Record<string, any>>().default({}),
19
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
19
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
20
20
  .default(sql`CURRENT_TIMESTAMP(3)`)
21
21
  .notNull(),
22
22
  status: int('status').default(0).notNull(),
@@ -1,9 +1,9 @@
1
1
  import { sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  mysqlEnum,
5
4
  MySqlTableFn,
6
5
  primaryKey,
6
+ timestamp,
7
7
  varchar,
8
8
  } from 'drizzle-orm/mysql-core'
9
9
 
@@ -26,13 +26,13 @@ export function getPurchaseUserTransferSchema(mysqlTable: MySqlTableFn) {
26
26
  purchaseId: varchar('purchaseId', { length: 191 }).notNull(),
27
27
  sourceUserId: varchar('sourceUserId', { length: 191 }).notNull(),
28
28
  targetUserId: varchar('targetUserId', { length: 191 }),
29
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
29
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
30
30
  .default(sql`CURRENT_TIMESTAMP(3)`)
31
31
  .notNull(),
32
- expiresAt: datetime('expiresAt', { mode: 'string', fsp: 3 }),
33
- canceledAt: datetime('canceledAt', { mode: 'string', fsp: 3 }),
34
- confirmedAt: datetime('confirmedAt', { mode: 'string', fsp: 3 }),
35
- completedAt: datetime('completedAt', { mode: 'string', fsp: 3 }),
32
+ expiresAt: timestamp('expiresAt', { mode: 'date', fsp: 3 }),
33
+ canceledAt: timestamp('canceledAt', { mode: 'date', fsp: 3 }),
34
+ confirmedAt: timestamp('confirmedAt', { mode: 'date', fsp: 3 }),
35
+ completedAt: timestamp('completedAt', { mode: 'date', fsp: 3 }),
36
36
  },
37
37
  (table) => {
38
38
  return {
@@ -1,21 +1,30 @@
1
- import { sql } from 'drizzle-orm'
1
+ import { relations, sql } from 'drizzle-orm'
2
2
  import {
3
- datetime,
4
3
  decimal,
5
4
  json,
6
5
  MySqlTableFn,
7
6
  primaryKey,
7
+ timestamp,
8
8
  unique,
9
9
  varchar,
10
10
  } from 'drizzle-orm/mysql-core'
11
11
 
12
+ import { getUsersSchema } from '../auth/users.js'
13
+ import { getCouponSchema } from './coupon.js'
14
+ import { getMerchantChargeSchema } from './merchant-charge.js'
15
+ import { getMerchantCouponSchema } from './merchant-coupon.js'
16
+ import { getMerchantCustomerSchema } from './merchant-customer.js'
17
+ import { getMerchantProductSchema } from './merchant-product.js'
18
+ import { getMerchantSessionSchema } from './merchant-session.js'
19
+ import { getProductSchema } from './product.js'
20
+
12
21
  export function getPurchaseSchema(mysqlTable: MySqlTableFn) {
13
22
  return mysqlTable(
14
23
  'purchases',
15
24
  {
16
25
  id: varchar('id', { length: 191 }).notNull(),
17
26
  userId: varchar('userId', { length: 191 }),
18
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
27
+ createdAt: timestamp('createdAt', { mode: 'date', fsp: 3 })
19
28
  .default(sql`CURRENT_TIMESTAMP(3)`)
20
29
  .notNull(),
21
30
  totalAmount: decimal('totalAmount', {
@@ -46,3 +55,40 @@ export function getPurchaseSchema(mysqlTable: MySqlTableFn) {
46
55
  },
47
56
  )
48
57
  }
58
+
59
+ export function getPurchaseRelationsSchema(mysqlTable: MySqlTableFn) {
60
+ const purchases = getPurchaseSchema(mysqlTable)
61
+ const users = getUsersSchema(mysqlTable)
62
+ const products = getProductSchema(mysqlTable)
63
+ const merchantCharges = getMerchantChargeSchema(mysqlTable)
64
+ const merchantSessions = getMerchantSessionSchema(mysqlTable)
65
+ const coupons = getCouponSchema(mysqlTable)
66
+
67
+ return relations(purchases, ({ many, one }) => ({
68
+ user: one(users, {
69
+ fields: [purchases.userId],
70
+ references: [users.id],
71
+ relationName: 'user',
72
+ }),
73
+ product: one(products, {
74
+ fields: [purchases.productId],
75
+ references: [products.id],
76
+ relationName: 'product',
77
+ }),
78
+ bulkCoupon: one(coupons, {
79
+ fields: [purchases.bulkCouponId],
80
+ references: [coupons.id],
81
+ relationName: 'bulkCoupon',
82
+ }),
83
+ merchantCharge: one(merchantCharges, {
84
+ fields: [purchases.merchantChargeId],
85
+ references: [merchantCharges.id],
86
+ relationName: 'merchantCharge',
87
+ }),
88
+ merchantSession: one(merchantSessions, {
89
+ fields: [purchases.merchantSessionId],
90
+ references: [merchantSessions.id],
91
+ relationName: 'merchantSession',
92
+ }),
93
+ }))
94
+ }
@@ -0,0 +1,58 @@
1
+ import { relations, sql } from 'drizzle-orm'
2
+ import {
3
+ double,
4
+ index,
5
+ json,
6
+ MySqlTableFn,
7
+ primaryKey,
8
+ timestamp,
9
+ varchar,
10
+ } from 'drizzle-orm/mysql-core'
11
+
12
+ import { getProductSchema } from './product.js'
13
+
14
+ export function getUpgradableProductsSchema(mysqlTable: MySqlTableFn) {
15
+ return mysqlTable(
16
+ 'upgradableProducts',
17
+ {
18
+ upgradableToId: varchar('upgradableToId', { length: 255 }).notNull(),
19
+ upgradableFromId: varchar('upgradableFrom', { length: 255 }).notNull(),
20
+ position: double('position').notNull().default(0),
21
+ metadata: json('metadata').$type<Record<string, any>>().default({}),
22
+ createdAt: timestamp('createdAt', {
23
+ mode: 'date',
24
+ fsp: 3,
25
+ }).default(sql`CURRENT_TIMESTAMP(3)`),
26
+ updatedAt: timestamp('updatedAt', {
27
+ mode: 'date',
28
+ fsp: 3,
29
+ }).default(sql`CURRENT_TIMESTAMP(3)`),
30
+ deletedAt: timestamp('deletedAt', {
31
+ mode: 'date',
32
+ fsp: 3,
33
+ }),
34
+ },
35
+ (crr) => ({
36
+ pk: primaryKey({ columns: [crr.upgradableToId, crr.upgradableFromId] }),
37
+ upgradableToIdIdx: index('upgradableFromId_idx').on(crr.upgradableToId),
38
+ upgradableFromIdIdx: index('upgradableToId_idx').on(crr.upgradableFromId),
39
+ }),
40
+ )
41
+ }
42
+
43
+ export function getUpgradableProductsRelationsSchema(mysqlTable: MySqlTableFn) {
44
+ const product = getProductSchema(mysqlTable)
45
+ const upgradableProduct = getUpgradableProductsSchema(mysqlTable)
46
+ return relations(upgradableProduct, ({ one }) => ({
47
+ upgradableTo: one(product, {
48
+ fields: [upgradableProduct.upgradableToId],
49
+ references: [product.id],
50
+ relationName: 'upgradableTo',
51
+ }),
52
+ upgradableFrom: one(product, {
53
+ fields: [upgradableProduct.upgradableFromId],
54
+ references: [product.id],
55
+ relationName: 'upgradableFrom',
56
+ }),
57
+ }))
58
+ }
@@ -65,14 +65,17 @@ export function getCommunicationPreferencesRelationsSchema(
65
65
  user: one(users, {
66
66
  fields: [communicationPreferences.userId],
67
67
  references: [users.id],
68
+ relationName: 'user',
68
69
  }),
69
70
  channel: one(communicationChannel, {
70
71
  fields: [communicationPreferences.channelId],
71
72
  references: [communicationChannel.id],
73
+ relationName: 'channel',
72
74
  }),
73
75
  preferenceType: one(communicationPreferenceTypes, {
74
76
  fields: [communicationPreferences.preferenceTypeId],
75
77
  references: [communicationPreferenceTypes.id],
78
+ relationName: 'preferenceType',
76
79
  }),
77
80
  }))
78
81
  }
@@ -57,14 +57,17 @@ export function getContentContributionRelationsSchema(
57
57
  user: one(users, {
58
58
  fields: [contentContributions.userId],
59
59
  references: [users.id],
60
+ relationName: 'user',
60
61
  }),
61
62
  content: one(contentResource, {
62
63
  fields: [contentContributions.contentId],
63
64
  references: [contentResource.id],
65
+ relationName: 'contributions',
64
66
  }),
65
67
  contributionType: one(contributionTypes, {
66
68
  fields: [contentContributions.contributionTypeId],
67
69
  references: [contributionTypes.id],
70
+ relationName: 'contributionType',
68
71
  }),
69
72
  }))
70
73
  }
@@ -18,7 +18,7 @@ export function getContentResourceResourceSchema(mysqlTable: MySqlTableFn) {
18
18
  resourceOfId: varchar('resourceOfId', { length: 255 }).notNull(),
19
19
  resourceId: varchar('resourceId', { length: 255 }).notNull(),
20
20
  position: double('position').notNull().default(0),
21
- metadata: json('fields').$type<Record<string, any>>().default({}),
21
+ metadata: json('metadata').$type<Record<string, any>>().default({}),
22
22
  createdAt: timestamp('createdAt', {
23
23
  mode: 'date',
24
24
  fsp: 3,
@@ -43,14 +43,13 @@ export function getContentResourceSchema(mysqlTable: MySqlTableFn) {
43
43
  export function getContentResourceRelationsSchema(mysqlTable: MySqlTableFn) {
44
44
  const contentResource = getContentResourceSchema(mysqlTable)
45
45
  const users = getUsersSchema(mysqlTable)
46
- const contentContributions = getContentContributionsSchema(mysqlTable)
47
46
  const contentResourceResource = getContentResourceResourceSchema(mysqlTable)
48
47
  return relations(contentResource, ({ one, many }) => ({
49
48
  createdBy: one(users, {
50
49
  fields: [contentResource.createdById],
51
50
  references: [users.id],
51
+ relationName: 'user',
52
52
  }),
53
- contributions: many(contentContributions),
54
53
  resources: many(contentResourceResource, { relationName: 'resourceOf' }),
55
54
  resourceOf: many(contentResourceResource, { relationName: 'resource' }),
56
55
  }))
@@ -41,9 +41,6 @@ export function getContributionTypesSchema(mysqlTable: MySqlTableFn) {
41
41
 
42
42
  export function getContributionTypesRelationsSchema(mysqlTable: MySqlTableFn) {
43
43
  const contributionTypes = getContributionTypesSchema(mysqlTable)
44
- const contentContributions = getContentContributionsSchema(mysqlTable)
45
44
 
46
- return relations(contributionTypes, ({ many }) => ({
47
- contributions: many(contentContributions),
48
- }))
45
+ return relations(contributionTypes, ({ many }) => ({}))
49
46
  }
@@ -15,9 +15,9 @@ export function getResourceProgressSchema(mysqlTable: MySqlTableFn) {
15
15
  userId: varchar('userId', { length: 191 }).notNull(),
16
16
  contentResourceId: varchar('contentResourceId', { length: 191 }),
17
17
  metadata: json('fields').$type<Record<string, any>>().default({}),
18
- completedAt: datetime('completedAt', { mode: 'string', fsp: 3 }),
19
- updatedAt: datetime('updatedAt', { mode: 'string', fsp: 3 }),
20
- createdAt: datetime('createdAt', { mode: 'string', fsp: 3 })
18
+ completedAt: datetime('completedAt', { mode: 'date', fsp: 3 }),
19
+ updatedAt: datetime('updatedAt', { mode: 'date', fsp: 3 }),
20
+ createdAt: datetime('createdAt', { mode: 'date', fsp: 3 })
21
21
  .default(sql`CURRENT_TIMESTAMP(3)`)
22
22
  .notNull(),
23
23
  },
@@ -0,0 +1,23 @@
1
+ import { customType } from 'drizzle-orm/mysql-core'
2
+
3
+ export const datetimeUtc = (name: string, precision: number) =>
4
+ customType<{ data: Date; driverData: string }>({
5
+ dataType() {
6
+ return `datetime(${precision})`
7
+ },
8
+ toDriver(value: Date): string {
9
+ return mysqlDatetimeUtc(value)
10
+ },
11
+ fromDriver(value: string): Date {
12
+ return mysqlDatetimeUtcToDate(value)
13
+ },
14
+ })(name)
15
+
16
+ function mysqlDatetimeUtc(date: Date = new Date()) {
17
+ return date.toISOString().slice(0, 19).replace('T', ' ')
18
+ }
19
+ // Use this function instead of new Date() when converting a MySQL datetime to a
20
+ // Date object so that the date is interpreted as UTC instead of local time (default behavior)
21
+ function mysqlDatetimeUtcToDate(mysqlDatetimeUtc: string) {
22
+ return new Date(mysqlDatetimeUtc.replace(' ', 'T') + 'Z')
23
+ }