{"version":3,"sources":["../../../../../src/lib/mysql/schemas/communication/comment.ts","../../../../../src/lib/mysql/schemas/auth/users.ts","../../../../../src/lib/mysql/schemas/commerce/purchase.ts","../../../../../src/lib/mysql/schemas/org/organization-memberships.ts","../../../../../src/lib/mysql/schemas/org/organization-membership-roles.ts","../../../../../src/lib/mysql/schemas/auth/roles.ts","../../../../../src/lib/mysql/schemas/auth/user-roles.ts","../../../../../src/lib/mysql/schemas/org/organizations.ts","../../../../../src/lib/mysql/schemas/commerce/subscription.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-subscription.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-charge.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-account.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-customer.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-product.ts","../../../../../src/lib/mysql/schemas/commerce/product.ts","../../../../../src/lib/mysql/schemas/content/content-resource-product.ts","../../../../../src/lib/mysql/schemas/content/content-resource.ts","../../../../../src/lib/mysql/schemas/content/content-contributions.ts","../../../../../src/lib/mysql/schemas/content/contribution-types.ts","../../../../../src/lib/mysql/schemas/content/content-resource-resource.ts","../../../../../src/lib/mysql/schemas/content/content-resource-tag.ts","../../../../../src/lib/mysql/schemas/content/tag.ts","../../../../../src/lib/mysql/schemas/content/tag-tag.ts","../../../../../src/lib/mysql/schemas/content/content-resource-version.ts","../../../../../src/lib/mysql/schemas/commerce/price.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-price.ts","../../../../../src/lib/mysql/schemas/commerce/coupon.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-coupon.ts","../../../../../src/lib/mysql/schemas/commerce/merchant-session.ts","../../../../../src/lib/mysql/schemas/communication/communication-preferences.ts","../../../../../src/lib/mysql/schemas/communication/communication-channel.ts","../../../../../src/lib/mysql/schemas/communication/communication-preference-types.ts","../../../../../src/lib/mysql/schemas/auth/accounts.ts","../../../../../src/lib/mysql/schemas/auth/profiles.ts","../../../../../src/lib/mysql/schemas/auth/user-permissions.ts","../../../../../src/lib/mysql/schemas/auth/permissions.ts","../../../../../src/lib/mysql/schemas/auth/user-prefs.ts"],"sourcesContent":["import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\n\nexport function getCommentsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Comment',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\torganizationMembershipId: varchar('organizationMembershipId', {\n\t\t\t\tlength: 255,\n\t\t\t}),\n\t\t\tcontext: json('context').$type<Record<string, any>>().default({}),\n\t\t\ttext: text('text').notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(crr) => ({\n\t\t\tpk: primaryKey({ columns: [crr.id] }),\n\t\t\tcrrUserIdIdKey: index('crr_userIdId_idx').on(crr.userId),\n\t\t\torganizationMembershipIdIdx: index('organizationMembershipId_idx').on(\n\t\t\t\tcrr.organizationMembershipId,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getCommentRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst comment = getCommentsSchema(mysqlTable)\n\tconst user = getUsersSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\treturn relations(comment, ({ one }) => ({\n\t\tuser: one(user, {\n\t\t\tfields: [comment.userId],\n\t\t\treferences: [user.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\torganizationMembership: one(organizationMemberships, {\n\t\t\tfields: [comment.organizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tmysqlEnum,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getPurchaseSchema } from '../commerce/purchase.js'\nimport { getCommentsSchema } from '../communication/comment.js'\nimport { getCommunicationPreferencesSchema } from '../communication/communication-preferences.js'\nimport { getContentContributionsSchema } from '../content/content-contributions.js'\nimport { getContentResourceSchema } from '../content/content-resource.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\nimport { getAccountsSchema } from './accounts.js'\nimport { getProfilesSchema } from './profiles.js'\nimport { getUserPermissionsSchema } from './user-permissions.js'\nimport { getUserPrefsSchema } from './user-prefs.js'\nimport { getUserRolesSchema } from './user-roles.js'\n\nexport function getUsersSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'User',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\tname: varchar('name', { length: 255 }),\n\t\t\trole: varchar('role', { length: 191 }).notNull().default('user'),\n\t\t\temail: varchar('email', { length: 255 }).notNull().unique(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\temailVerified: timestamp('emailVerified', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t\timage: varchar('image', { length: 255 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t},\n\t\t(user) => ({\n\t\t\temailIdx: index('email_idx').on(user.email),\n\t\t\troleIdx: index('role_idx').on(user.role),\n\t\t\tcreatedAtIdx: index('created_at_idx').on(user.createdAt),\n\t\t}),\n\t)\n}\n\nexport function getUsersRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst users = getUsersSchema(mysqlTable)\n\tconst profiles = getProfilesSchema(mysqlTable)\n\tconst accounts = getAccountsSchema(mysqlTable)\n\tconst communicationPreferences = getCommunicationPreferencesSchema(mysqlTable)\n\tconst userRoles = getUserRolesSchema(mysqlTable)\n\tconst userPermissions = getUserPermissionsSchema(mysqlTable)\n\tconst contentContributions = getContentContributionsSchema(mysqlTable)\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst purchases = getPurchaseSchema(mysqlTable)\n\tconst comments = getCommentsSchema(mysqlTable)\n\tconst userPrefs = getUserPrefsSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\treturn relations(users, ({ many, one }) => ({\n\t\tprofiles: many(profiles, {\n\t\t\trelationName: 'profiles',\n\t\t}),\n\t\taccounts: many(accounts, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tpurchases: many(purchases, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tcommunicationPreferences: many(communicationPreferences, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\troles: many(userRoles, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tuserPermissions: many(userPermissions, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tcontributions: many(contentContributions, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tcreatedContent: many(contentResource, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tcomments: many(comments, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tprefs: many(userPrefs, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t\torganizationMemberships: many(organizationMemberships, {\n\t\t\trelationName: 'user',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdecimal,\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\nimport { getOrganizationsSchema } from '../org/organizations.js'\nimport { getCouponSchema } from './coupon.js'\nimport { getMerchantChargeSchema } from './merchant-charge.js'\nimport { getMerchantSessionSchema } from './merchant-session.js'\nimport { getProductSchema } from './product.js'\n\nexport function getPurchaseSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Purchase',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\tuserId: varchar('userId', { length: 191 }),\n\t\t\tpurchasedByorganizationMembershipId: varchar('organizationMembershipId', {\n\t\t\t\tlength: 191,\n\t\t\t}),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\ttotalAmount: decimal('totalAmount', {\n\t\t\t\tprecision: 65,\n\t\t\t\tscale: 30,\n\t\t\t}).notNull(),\n\t\t\tipAddress: varchar('ip_address', { length: 191 }),\n\t\t\tcity: varchar('city', { length: 191 }),\n\t\t\tstate: varchar('state', { length: 191 }),\n\t\t\tcountry: varchar('country', { length: 191 }),\n\t\t\tcouponId: varchar('couponId', { length: 191 }),\n\t\t\tproductId: varchar('productId', { length: 191 }).notNull(),\n\t\t\tmerchantChargeId: varchar('merchantChargeId', { length: 191 }),\n\t\t\tupgradedFromId: varchar('upgradedFromId', { length: 191 }),\n\t\t\tstatus: varchar('status', { length: 191 }).default('Valid').notNull(),\n\t\t\tbulkCouponId: varchar('bulkCouponId', { length: 191 }),\n\t\t\tmerchantSessionId: varchar('merchantSessionId', { length: 191 }),\n\t\t\tredeemedBulkCouponId: varchar('redeemedBulkCouponId', { length: 191 }),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tpurchaseId: primaryKey({ columns: [table.id], name: 'Purchase_id' }),\n\t\t\t\tmerchantChargeIdIdx: index('idx_Purchase_on_merchantChargeId').on(\n\t\t\t\t\ttable.merchantChargeId,\n\t\t\t\t),\n\t\t\t\tpurchaseUpgradedFromIdKey: unique('Purchase_upgradedFromId_key').on(\n\t\t\t\t\ttable.upgradedFromId,\n\t\t\t\t),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t\torganizationMembershipIdIdx: index('organizationMembershipId_idx').on(\n\t\t\t\t\ttable.purchasedByorganizationMembershipId,\n\t\t\t\t),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getPurchaseRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst purchases = getPurchaseSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst products = getProductSchema(mysqlTable)\n\tconst merchantCharges = getMerchantChargeSchema(mysqlTable)\n\tconst merchantSessions = getMerchantSessionSchema(mysqlTable)\n\tconst coupons = getCouponSchema(mysqlTable)\n\tconst organizations = getOrganizationsSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\n\treturn relations(purchases, ({ many, one }) => ({\n\t\tredeemedBulkCoupon: one(coupons, {\n\t\t\tfields: [purchases.redeemedBulkCouponId],\n\t\t\treferences: [coupons.id],\n\t\t\trelationName: 'redeemedBulkCoupon',\n\t\t}),\n\t\tuser: one(users, {\n\t\t\tfields: [purchases.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\torganization: one(organizations, {\n\t\t\tfields: [purchases.organizationId],\n\t\t\treferences: [organizations.id],\n\t\t\trelationName: 'organization',\n\t\t}),\n\t\tpurchasedBy: one(organizationMemberships, {\n\t\t\tfields: [purchases.purchasedByorganizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t\tproduct: one(products, {\n\t\t\tfields: [purchases.productId],\n\t\t\treferences: [products.id],\n\t\t\trelationName: 'product',\n\t\t}),\n\t\tbulkCoupon: one(coupons, {\n\t\t\tfields: [purchases.bulkCouponId],\n\t\t\treferences: [coupons.id],\n\t\t\trelationName: 'bulkCoupon',\n\t\t}),\n\t\tmerchantCharge: one(merchantCharges, {\n\t\t\tfields: [purchases.merchantChargeId],\n\t\t\treferences: [merchantCharges.id],\n\t\t\trelationName: 'merchantCharge',\n\t\t}),\n\t\tmerchantSession: one(merchantSessions, {\n\t\t\tfields: [purchases.merchantSessionId],\n\t\t\treferences: [merchantSessions.id],\n\t\t\trelationName: 'merchantSession',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tmysqlEnum,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getPurchaseSchema } from '../commerce/purchase.js'\nimport { getOrganizationMembershipRolesSchema } from './organization-membership-roles.js'\nimport { getOrganizationsSchema } from './organizations.js'\n\nexport function getOrganizationMembershipsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'OrganizationMembership',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\trole: varchar('role', { length: 191 }).notNull().default('user'),\n\t\t\tinvitedById: varchar('invitedById', { length: 255 }).notNull(),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t},\n\t\t(organizationMembership) => ({\n\t\t\troleIdx: index('role_idx').on(organizationMembership.role),\n\t\t\tcreatedAtIdx: index('created_at_idx').on(\n\t\t\t\torganizationMembership.createdAt,\n\t\t\t),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(\n\t\t\t\torganizationMembership.organizationId,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getOrganizationMembershipsRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst users = getUsersSchema(mysqlTable)\n\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\tconst purchases = getPurchaseSchema(mysqlTable)\n\tconst organizations = getOrganizationsSchema(mysqlTable)\n\tconst organizationMembershipRoles =\n\t\tgetOrganizationMembershipRolesSchema(mysqlTable)\n\n\treturn relations(organizationMemberships, ({ one, many }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [organizationMemberships.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tinvitedBy: one(users, {\n\t\t\tfields: [organizationMemberships.invitedById],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'invitedBy',\n\t\t}),\n\t\tpurchases: many(purchases),\n\t\torganization: one(organizations, {\n\t\t\tfields: [organizationMemberships.organizationId],\n\t\t\treferences: [organizations.id],\n\t\t\trelationName: 'organization',\n\t\t}),\n\t\torganizationMembershipRoles: many(organizationMembershipRoles, {\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getRolesSchema } from '../auth/roles.js'\nimport { getOrganizationMembershipsSchema } from './organization-memberships.js'\nimport { getOrganizationsSchema } from './organizations.js'\n\nexport function getOrganizationMembershipRolesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'OrganizationMembershipRole',\n\t\t{\n\t\t\torganizationMembershipId: varchar('organizationMembershipId', {\n\t\t\t\tlength: 255,\n\t\t\t}).notNull(),\n\t\t\troleId: varchar('roleId', { length: 255 }).notNull(),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(ur) => ({\n\t\t\tpk: primaryKey({\n\t\t\t\tcolumns: [ur.organizationMembershipId, ur.roleId],\n\t\t\t\tname: 'pk',\n\t\t\t}),\n\t\t\torgMemberIdIdx: index('orgMemberId_idx').on(ur.organizationMembershipId),\n\t\t\troleIdIdx: index('roleId_idx').on(ur.roleId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(ur.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getOrganizationMembershipRolesRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst organizationMembershipRoles =\n\t\tgetOrganizationMembershipRolesSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\tconst roles = getRolesSchema(mysqlTable)\n\tconst organizations = getOrganizationsSchema(mysqlTable)\n\treturn relations(organizationMembershipRoles, ({ one }) => ({\n\t\torganizationMembership: one(organizationMemberships, {\n\t\t\tfields: [organizationMembershipRoles.organizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t\trole: one(roles, {\n\t\t\tfields: [organizationMembershipRoles.roleId],\n\t\t\treferences: [roles.id],\n\t\t\trelationName: 'role',\n\t\t}),\n\t\torganization: one(organizations, {\n\t\t\tfields: [organizationMembershipRoles.organizationId],\n\t\t\treferences: [organizations.id],\n\t\t\trelationName: 'organization',\n\t\t}),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\ttext,\n\ttimestamp,\n\tuniqueIndex,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUserRolesSchema } from './user-roles.js'\n\nexport function getRolesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Role',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tname: varchar('name', { length: 255 }).notNull(),\n\t\t\tdescription: text('description'),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(role) => ({\n\t\t\tnameIdx: index('name_idx').on(role.name),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(role.organizationId),\n\t\t\tuniqueNamePerOrg: uniqueIndex('unique_name_per_org').on(\n\t\t\t\trole.organizationId,\n\t\t\t\trole.name,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getRolesRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst roles = getRolesSchema(mysqlTable)\n\tconst userRoles = getUserRolesSchema(mysqlTable)\n\n\treturn relations(roles, ({ many }) => ({\n\t\tuserRoles: many(userRoles, { relationName: 'role' }),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getRolesSchema } from './roles.js'\nimport { getUsersSchema } from './users.js'\n\nexport function getUserRolesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'UserRole',\n\t\t{\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\troleId: varchar('roleId', { length: 255 }).notNull(),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(ur) => ({\n\t\t\tpk: primaryKey({ columns: [ur.userId, ur.roleId] }),\n\t\t\tuserIdIdx: index('userId_idx').on(ur.userId),\n\t\t\troleIdIdx: index('roleId_idx').on(ur.roleId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(ur.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getUserRolesRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst userRoles = getUserRolesSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst roles = getRolesSchema(mysqlTable)\n\treturn relations(userRoles, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [userRoles.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\trole: one(roles, {\n\t\t\tfields: [userRoles.roleId],\n\t\t\treferences: [roles.id],\n\t\t\trelationName: 'role',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tmysqlEnum,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getPurchaseSchema } from '../commerce/purchase.js'\nimport { getSubscriptionSchema } from '../commerce/subscription.js'\nimport { getOrganizationMembershipsSchema } from './organization-memberships.js'\n\nexport function getOrganizationsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Organization',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\tname: varchar('name', { length: 255 }),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\timage: varchar('image', { length: 255 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t},\n\t\t(organization) => ({\n\t\t\tcreatedAtIdx: index('created_at_idx').on(organization.createdAt),\n\t\t}),\n\t)\n}\n\nexport function getOrganizationsRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst organizations = getOrganizationsSchema(mysqlTable)\n\tconst purchases = getPurchaseSchema(mysqlTable)\n\tconst subscriptions = getSubscriptionSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\treturn relations(organizations, ({ many }) => ({\n\t\tpurchases: many(purchases, {\n\t\t\trelationName: 'organization',\n\t\t}),\n\t\tsubscriptions: many(subscriptions, {\n\t\t\trelationName: 'organization',\n\t\t}),\n\t\tmembers: many(organizationMemberships, {\n\t\t\trelationName: 'organization',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getOrganizationsSchema } from '../org/organizations.js'\nimport { getMerchantSubscriptionSchema } from './merchant-subscription.js'\nimport { getProductSchema } from './product.js'\n\n// TODO: do we add a renewal date here? probably just add that stuff to fields\n// \teven status feels out of place at the top level maybe\nexport function getSubscriptionSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Subscription',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tproductId: varchar('productId', { length: 191 }).notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tmerchantSubscriptionId: varchar('merchantSubscriptionId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tstatus: varchar('status', { length: 191 }).default('active').notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tsubscriptionId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'Subscription_id',\n\t\t\t\t}),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getSubscriptionRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst subscriptions = getSubscriptionSchema(mysqlTable)\n\tconst products = getProductSchema(mysqlTable)\n\n\tconst organizations = getOrganizationsSchema(mysqlTable)\n\tconst merchantSubscriptions = getMerchantSubscriptionSchema(mysqlTable)\n\n\treturn relations(subscriptions, ({ many, one }) => ({\n\t\torganization: one(organizations, {\n\t\t\tfields: [subscriptions.organizationId],\n\t\t\treferences: [organizations.id],\n\t\t\trelationName: 'organization',\n\t\t}),\n\t\tproduct: one(products, {\n\t\t\tfields: [subscriptions.productId],\n\t\t\treferences: [products.id],\n\t\t\trelationName: 'product',\n\t\t}),\n\t\tmerchantSubscription: one(merchantSubscriptions, {\n\t\t\tfields: [subscriptions.merchantSubscriptionId],\n\t\t\treferences: [merchantSubscriptions.id],\n\t\t\trelationName: 'merchantSubscription',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getMerchantChargeSchema } from './merchant-charge.js'\nimport { getSubscriptionSchema } from './subscription.js'\n\nexport function getMerchantSubscriptionSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantSubscription',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tlabel: varchar('label', { length: 191 }),\n\t\t\tidentifier: varchar('identifier', { length: 191 }),\n\t\t\tmerchantCustomerId: varchar('merchantCustomerId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tmerchantProductId: varchar('merchantProductId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantSubscriptionId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantSubscription_id',\n\t\t\t\t}),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getMerchantSubscriptionRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst merchantSubscription = getMerchantSubscriptionSchema(mysqlTable)\n\tconst merchantCharge = getMerchantChargeSchema(mysqlTable)\n\tconst subscription = getSubscriptionSchema(mysqlTable)\n\treturn relations(merchantSubscription, ({ many, one }) => ({\n\t\tmerchantCharges: many(merchantCharge, {\n\t\t\trelationName: 'merchantSubscription',\n\t\t}),\n\t\tsubscription: one(subscription, {\n\t\t\tfields: [merchantSubscription.id],\n\t\t\treferences: [subscription.merchantSubscriptionId],\n\t\t\trelationName: 'subscription',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getMerchantAccountSchema } from './merchant-account.js'\nimport { getMerchantCustomerSchema } from './merchant-customer.js'\nimport { getMerchantProductSchema } from './merchant-product.js'\nimport { getMerchantSubscriptionSchema } from './merchant-subscription.js'\n\nexport function getMerchantChargeSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantCharge',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tidentifier: varchar('identifier', { length: 191 }).notNull(),\n\t\t\tuserId: varchar('userId', { length: 191 }).notNull(),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tmerchantProductId: varchar('merchantProductId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tmerchantSubscriptionId: varchar('merchantSubscriptionId', {\n\t\t\t\tlength: 191,\n\t\t\t}),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tmerchantCustomerId: varchar('merchantCustomerId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantChargeId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantCharge_id',\n\t\t\t\t}),\n\t\t\t\tmerchantChargeIdentifierKey: unique('MerchantCharge_identifier_key').on(\n\t\t\t\t\ttable.identifier,\n\t\t\t\t),\n\t\t\t\tmerchantSubscriptionIdIdx: index('merchantSubscriptionId_idx').on(\n\t\t\t\t\ttable.merchantSubscriptionId,\n\t\t\t\t),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getMerchantChargeRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst merchantCharge = getMerchantChargeSchema(mysqlTable)\n\tconst merchantAccount = getMerchantAccountSchema(mysqlTable)\n\tconst merchantProduct = getMerchantProductSchema(mysqlTable)\n\tconst merchantCustomer = getMerchantCustomerSchema(mysqlTable)\n\tconst merchantSubscription = getMerchantSubscriptionSchema(mysqlTable)\n\treturn relations(merchantCharge, ({ one }) => ({\n\t\tmerchantAccount: one(merchantAccount, {\n\t\t\tfields: [merchantCharge.merchantAccountId],\n\t\t\treferences: [merchantAccount.id],\n\t\t\trelationName: 'merchantAccount',\n\t\t}),\n\t\tmerchantProduct: one(merchantProduct, {\n\t\t\tfields: [merchantCharge.merchantProductId],\n\t\t\treferences: [merchantProduct.id],\n\t\t\trelationName: 'merchantProduct',\n\t\t}),\n\t\tmerchantCustomer: one(merchantCustomer, {\n\t\t\tfields: [merchantCharge.merchantCustomerId],\n\t\t\treferences: [merchantCustomer.id],\n\t\t\trelationName: 'merchantCustomer',\n\t\t}),\n\t\tmerchantSubscription: one(merchantSubscription, {\n\t\t\tfields: [merchantCharge.merchantSubscriptionId],\n\t\t\treferences: [merchantSubscription.id],\n\t\t\trelationName: 'merchantSubscription',\n\t\t}),\n\t}))\n}\n","import { sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantAccountSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantAccount',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tlabel: varchar('label', { length: 191 }),\n\t\t\tidentifier: varchar('identifier', { length: 191 }),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantAccountId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantAccount_id',\n\t\t\t\t}),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import { sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantCustomerSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantCustomer',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tuserId: varchar('userId', { length: 191 }).notNull(),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tidentifier: varchar('identifier', { length: 191 }).notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tstatus: int('status').default(0),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantCustomerId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantCustomer_id',\n\t\t\t\t}),\n\t\t\t\tmerchantCustomerIdentifierKey: unique(\n\t\t\t\t\t'MerchantCustomer_identifier_key',\n\t\t\t\t).on(table.identifier),\n\t\t\t\tuserIdIdx: index('idx_MerchantCustomer_on_userId').on(table.userId),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import { sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantProductSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantProduct',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tproductId: varchar('productId', { length: 191 }).notNull(),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tidentifier: varchar('identifier', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantProductId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantProduct_id',\n\t\t\t\t}),\n\t\t\t\tmerchantProductIdentifierKey: unique(\n\t\t\t\t\t'MerchantProduct_identifier_key',\n\t\t\t\t).on(table.identifier),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getContentResourceProductSchema } from '../content/content-resource-product.js'\nimport { getMerchantProductSchema } from './merchant-product.js'\nimport { getPriceSchema } from './price.js'\n\nexport function getProductSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Product',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tname: varchar('name', { length: 191 }).notNull(),\n\t\t\tkey: varchar('key', { length: 191 }),\n\t\t\ttype: varchar('type', { length: 191 }),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tquantityAvailable: int('quantityAvailable').default(-1).notNull(),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tproductId: primaryKey({ columns: [table.id], name: 'Product_id' }),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getProductRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst product = getProductSchema(mysqlTable)\n\tconst price = getPriceSchema(mysqlTable)\n\tconst merchantProduct = getMerchantProductSchema(mysqlTable)\n\tconst contentResourceProduct = getContentResourceProductSchema(mysqlTable)\n\treturn relations(product, ({ one, many }) => ({\n\t\tprice: one(price, {\n\t\t\tfields: [product.id],\n\t\t\treferences: [price.productId],\n\t\t\trelationName: 'price',\n\t\t}),\n\t\tresources: many(contentResourceProduct, { relationName: 'product' }),\n\t\tmerchantProduct: one(merchantProduct, {\n\t\t\tfields: [product.id],\n\t\t\treferences: [merchantProduct.productId],\n\t\t\trelationName: 'merchantProduct',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdouble,\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getProductSchema } from '../commerce/product.js'\nimport { getContentResourceSchema } from './content-resource.js'\n\nexport function getContentResourceProductSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentResourceProduct',\n\t\t{\n\t\t\tproductId: varchar('productId', { length: 255 }).notNull(),\n\t\t\tresourceId: varchar('resourceId', { length: 255 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tposition: double('position').notNull().default(0),\n\t\t\tmetadata: json('metadata').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(crr) => ({\n\t\t\tpk: primaryKey({ columns: [crr.productId, crr.resourceId] }),\n\t\t\tcontentResourceIdIdx: index('contentResourceId_idx').on(crr.productId),\n\t\t\tresourceIdIdx: index('resourceId_idx').on(crr.resourceId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(crr.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getContentResourceProductRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst contentResourceProduct = getContentResourceProductSchema(mysqlTable)\n\tconst product = getProductSchema(mysqlTable)\n\treturn relations(contentResourceProduct, ({ one }) => ({\n\t\tproduct: one(product, {\n\t\t\tfields: [contentResourceProduct.productId],\n\t\t\treferences: [product.id],\n\t\t\trelationName: 'product',\n\t\t}),\n\t\tresource: one(contentResource, {\n\t\t\tfields: [contentResourceProduct.resourceId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'resource',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\nimport { getContentContributionsSchema } from './content-contributions.js'\nimport { getContentResourceProductSchema } from './content-resource-product.js'\nimport { getContentResourceResourceSchema } from './content-resource-resource.js'\nimport { getContentResourceTagSchema } from './content-resource-tag.js'\nimport { getContentResourceVersionSchema } from './content-resource-version.js'\nimport { getTagSchema } from './tag.js'\n\nexport function getContentResourceSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentResource',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedByOrganizationMembershipId: varchar(\n\t\t\t\t'createdByOrganizationMembershipId',\n\t\t\t\t{\n\t\t\t\t\tlength: 191,\n\t\t\t\t},\n\t\t\t),\n\t\t\ttype: varchar('type', { length: 255 }).notNull(),\n\t\t\tcreatedById: varchar('createdById', { length: 255 }).notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcurrentVersionId: varchar('currentVersionId', { length: 255 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(cm) => ({\n\t\t\ttypeIdx: index('type_idx').on(cm.type),\n\t\t\tcreatedByIdx: index('createdById_idx').on(cm.createdById),\n\t\t\tcreatedAtIdx: index('createdAt_idx').on(cm.createdAt),\n\t\t\tcurrentVersionIdIdx: index('currentVersionId_idx').on(\n\t\t\t\tcm.currentVersionId,\n\t\t\t),\n\t\t\tcreatedByOrganizationMembershipIdIdx: index(\n\t\t\t\t'createdByOrganizationMembershipId_idx',\n\t\t\t).on(cm.createdByOrganizationMembershipId),\n\t\t}),\n\t)\n}\n\nexport function getContentResourceRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst contentResourceResource = getContentResourceResourceSchema(mysqlTable)\n\tconst contentResourceProduct = getContentResourceProductSchema(mysqlTable)\n\tconst contentContributions = getContentContributionsSchema(mysqlTable)\n\tconst contentResourceTag = getContentResourceTagSchema(mysqlTable)\n\tconst contentResourceVersion = getContentResourceVersionSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\tconst tag = getTagSchema(mysqlTable)\n\treturn relations(contentResource, ({ one, many }) => ({\n\t\tcreatedBy: one(users, {\n\t\t\tfields: [contentResource.createdById],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'creator',\n\t\t}),\n\t\tcreatedByOrganizationMembership: one(organizationMemberships, {\n\t\t\tfields: [contentResource.createdByOrganizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'createdByOrganizationMembership',\n\t\t}),\n\t\ttags: many(contentResourceTag, { relationName: 'contentResource' }),\n\t\tresources: many(contentResourceResource, { relationName: 'resourceOf' }),\n\t\tresourceOf: many(contentResourceResource, { relationName: 'resource' }),\n\t\tresourceProducts: many(contentResourceProduct, {\n\t\t\trelationName: 'resource',\n\t\t}),\n\t\tcontributions: many(contentContributions, {\n\t\t\trelationName: 'contributions',\n\t\t}),\n\t\tcurrentVersion: one(contentResourceVersion, {\n\t\t\tfields: [contentResource.currentVersionId],\n\t\t\treferences: [contentResourceVersion.id],\n\t\t\trelationName: 'currentVersionResource',\n\t\t}),\n\t\tversions: many(contentResourceVersion, { relationName: 'resource' }),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\nimport { getContentResourceSchema } from './content-resource.js'\nimport { getContributionTypesSchema } from './contribution-types.js'\n\nexport function getContentContributionsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentContribution',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\torganizationMembershipId: varchar('organizationMembershipId', {\n\t\t\t\tlength: 255,\n\t\t\t}),\n\t\t\tcontentId: varchar('contentId', { length: 255 }).notNull(),\n\t\t\tcontributionTypeId: varchar('contributionTypeId', {\n\t\t\t\tlength: 255,\n\t\t\t}).notNull(),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(cc) => ({\n\t\t\tuserIdIdx: index('userId_idx').on(cc.userId),\n\t\t\tcontentIdIdx: index('contentId_idx').on(cc.contentId),\n\t\t\tcontributionTypeIdIdx: index('contributionTypeId_idx').on(\n\t\t\t\tcc.contributionTypeId,\n\t\t\t),\n\t\t\torganizationMembershipIdIdx: index('organizationMembershipId_idx').on(\n\t\t\t\tcc.organizationMembershipId,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getContentContributionRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst contentContributions = getContentContributionsSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst contributionTypes = getContributionTypesSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\n\treturn relations(contentContributions, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [contentContributions.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tcontent: one(contentResource, {\n\t\t\tfields: [contentContributions.contentId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'contributions',\n\t\t}),\n\t\tcontributionType: one(contributionTypes, {\n\t\t\tfields: [contentContributions.contributionTypeId],\n\t\t\treferences: [contributionTypes.id],\n\t\t\trelationName: 'contributionType',\n\t\t}),\n\t\torganizationMembership: one(organizationMemberships, {\n\t\t\tfields: [contentContributions.organizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getContentContributionsSchema } from './content-contributions.js'\n\nexport function getContributionTypesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContributionType',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tslug: varchar('slug', { length: 255 }).notNull().unique(),\n\t\t\tname: varchar('name', { length: 255 }).notNull(),\n\t\t\tdescription: text('description'),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(ct) => ({\n\t\t\tnameIdx: index('name_idx').on(ct.name),\n\t\t\tslugIdx: index('slug_idx').on(ct.slug),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(ct.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getContributionTypesRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst contributionTypes = getContributionTypesSchema(mysqlTable)\n\n\treturn relations(contributionTypes, ({ many }) => ({}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdouble,\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getContentResourceSchema } from './content-resource.js'\n\nexport function getContentResourceResourceSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentResourceResource',\n\t\t{\n\t\t\tresourceOfId: varchar('resourceOfId', { length: 255 }).notNull(),\n\t\t\tresourceId: varchar('resourceId', { length: 255 }).notNull(),\n\t\t\tposition: double('position').notNull().default(0),\n\t\t\tmetadata: json('metadata').$type<Record<string, any>>().default({}),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(crr) => ({\n\t\t\tpk: primaryKey({ columns: [crr.resourceOfId, crr.resourceId] }),\n\t\t\tcontentResourceIdIdx: index('contentResourceId_idx').on(crr.resourceOfId),\n\t\t\tresourceIdIdx: index('resourceId_idx').on(crr.resourceId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(crr.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getContentResourceResourceRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst contentResourceResource = getContentResourceResourceSchema(mysqlTable)\n\treturn relations(contentResourceResource, ({ one }) => ({\n\t\tresourceOf: one(contentResource, {\n\t\t\tfields: [contentResourceResource.resourceOfId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'resourceOf',\n\t\t}),\n\t\tresource: one(contentResource, {\n\t\t\tfields: [contentResourceResource.resourceId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'resource',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdouble,\n\tindex,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getContentResourceSchema } from './content-resource.js'\nimport { getTagSchema } from './tag.js'\n\nexport function getContentResourceTagSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentResourceTag',\n\t\t{\n\t\t\tcontentResourceId: varchar('contentResourceId', {\n\t\t\t\tlength: 255,\n\t\t\t}).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\ttagId: varchar('tagId', { length: 255 }).notNull(),\n\t\t\tposition: double('position').notNull().default(0),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t},\n\t\t(crt) => ({\n\t\t\tpk: primaryKey({ columns: [crt.contentResourceId, crt.tagId] }),\n\t\t\tcontentResourceIdIdx: index('contentResourceId_idx').on(\n\t\t\t\tcrt.contentResourceId,\n\t\t\t),\n\t\t\ttagIdIdx: index('tagId_idx').on(crt.tagId),\n\t\t\tpositionIdx: index('position_idx').on(crt.position),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(crt.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getContentResourceTagRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst tag = getTagSchema(mysqlTable)\n\tconst contentResourceTag = getContentResourceTagSchema(mysqlTable)\n\treturn relations(contentResourceTag, ({ one }) => ({\n\t\tcontentResource: one(contentResource, {\n\t\t\tfields: [contentResourceTag.contentResourceId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'contentResource',\n\t\t}),\n\t\ttag: one(tag, {\n\t\t\tfields: [contentResourceTag.tagId],\n\t\t\treferences: [tag.id],\n\t\t\trelationName: 'tag',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getContentResourceTagSchema } from './content-resource-tag.js'\nimport { getTagTagSchema } from './tag-tag.js'\n\nexport function getTagSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Tag',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\ttype: varchar('type', { length: 255 }).notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(t) => ({\n\t\t\ttypeIdx: index('type_idx').on(t.type),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(t.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getTagRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst tag = getTagSchema(mysqlTable)\n\tconst contentResourceTag = getContentResourceTagSchema(mysqlTable)\n\tconst tagTag = getTagTagSchema(mysqlTable)\n\treturn relations(tag, ({ many }) => ({\n\t\tresources: many(contentResourceTag, { relationName: 'contentResource' }),\n\t\tparentTags: many(tagTag, { relationName: 'childTag' }),\n\t\tchildTags: many(tagTag, { relationName: 'parentTag' }),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdouble,\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getTagSchema } from './tag.js'\n\nexport function getTagTagSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'TagTag',\n\t\t{\n\t\t\tparentTagId: varchar('parentTagId', { length: 255 }).notNull(),\n\t\t\tchildTagId: varchar('childTagId', { length: 255 }).notNull(),\n\t\t\tposition: double('position').notNull().default(0),\n\t\t\tmetadata: json('metadata').$type<Record<string, any>>().default({}),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(tt) => ({\n\t\t\tpk: primaryKey({ columns: [tt.parentTagId, tt.childTagId] }),\n\t\t\tparentTagIdIdx: index('parentTagId_idx').on(tt.parentTagId),\n\t\t\tchildTagIdIdx: index('childTagId_idx').on(tt.childTagId),\n\t\t\tpositionIdx: index('position_idx').on(tt.position),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(tt.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getTagTagRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst tag = getTagSchema(mysqlTable)\n\tconst tagTag = getTagTagSchema(mysqlTable)\n\treturn relations(tagTag, ({ one }) => ({\n\t\tparentTag: one(tag, {\n\t\t\tfields: [tagTag.parentTagId],\n\t\t\treferences: [tag.id],\n\t\t\trelationName: 'parentTag',\n\t\t}),\n\t\tchildTag: one(tag, {\n\t\t\tfields: [tagTag.childTagId],\n\t\t\treferences: [tag.id],\n\t\t\trelationName: 'childTag',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tjson,\n\tMySqlTableFn,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getContentResourceSchema } from './content-resource.js'\n\nexport function getContentResourceVersionSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'ContentResourceVersion',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tresourceId: varchar('resourceId', { length: 255 }).notNull(),\n\t\t\tparentVersionId: varchar('parentVersionId', { length: 255 }),\n\t\t\tversionNumber: int('versionNumber').notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tcreatedById: varchar('createdById', { length: 255 }).notNull(),\n\t\t},\n\t\t(crv) => ({\n\t\t\tresourceIdIdx: index('resourceId_idx').on(crv.resourceId),\n\t\t\tparentVersionIdIdx: index('parentVersionId_idx').on(crv.parentVersionId),\n\t\t\tresourceIdVersionNumberIdx: index('resourceId_versionNumber_idx').on(\n\t\t\t\tcrv.resourceId,\n\t\t\t\tcrv.versionNumber,\n\t\t\t),\n\t\t\tuniqueResourceVersion: unique('uq_resource_version_number').on(\n\t\t\t\tcrv.resourceId,\n\t\t\t\tcrv.versionNumber,\n\t\t\t),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(crv.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getContentResourceVersionRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst contentResourceVersion = getContentResourceVersionSchema(mysqlTable)\n\tconst contentResource = getContentResourceSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\n\treturn relations(contentResourceVersion, ({ one }) => ({\n\t\tresource: one(contentResource, {\n\t\t\tfields: [contentResourceVersion.resourceId],\n\t\t\treferences: [contentResource.id],\n\t\t\trelationName: 'versions',\n\t\t}),\n\t\tparentVersion: one(contentResourceVersion, {\n\t\t\tfields: [contentResourceVersion.parentVersionId],\n\t\t\treferences: [contentResourceVersion.id],\n\t\t\trelationName: 'childVersions',\n\t\t}),\n\t\tcreatedBy: one(users, {\n\t\t\tfields: [contentResourceVersion.createdById],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'createdVersions',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tdecimal,\n\tindex,\n\tint,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getMerchantPriceSchema } from './merchant-price.js'\nimport { getProductSchema } from './product.js'\n\nexport function getPriceSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Price',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\tproductId: varchar('productId', { length: 191 }),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tnickname: varchar('nickname', { length: 191 }),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tunitAmount: decimal('unitAmount', { precision: 10, scale: 2 }).notNull(),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tpriceId: primaryKey({ columns: [table.id], name: 'Price_id' }),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getProductRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst product = getProductSchema(mysqlTable)\n\tconst price = getPriceSchema(mysqlTable)\n\tconst merchantPrice = getMerchantPriceSchema(mysqlTable)\n\treturn relations(price, ({ one, many }) => ({\n\t\tproduct: one(product, {\n\t\t\tfields: [price.productId],\n\t\t\treferences: [product.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tmerchantPrice: one(merchantPrice, {\n\t\t\tfields: [price.id],\n\t\t\treferences: [merchantPrice.priceId],\n\t\t\trelationName: 'merchantPrice',\n\t\t}),\n\t}))\n}\n","import { sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantPriceSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantPrice',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tmerchantProductId: varchar('merchantProductId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tstatus: int('status').default(0),\n\t\t\tidentifier: varchar('identifier', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\tpriceId: varchar('priceId', { length: 191 }),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantPriceId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantPrice_id',\n\t\t\t\t}),\n\t\t\t\tmerchantPriceIdentifierKey: unique('MerchantPrice_identifier_key').on(\n\t\t\t\t\ttable.identifier,\n\t\t\t\t),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tboolean,\n\tdecimal,\n\tindex,\n\tint,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getMerchantCouponSchema } from './merchant-coupon.js'\nimport { getProductSchema } from './product.js'\nimport { getPurchaseSchema } from './purchase.js'\n\nexport function getCouponSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Coupon',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tcode: varchar('code', { length: 191 }),\n\t\t\tcreatedAt: timestamp('createdAt', { mode: 'date', fsp: 3 })\n\t\t\t\t.default(sql`CURRENT_TIMESTAMP(3)`)\n\t\t\t\t.notNull(),\n\t\t\texpires: timestamp('expires', { mode: 'date', fsp: 3 }),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tmaxUses: int('maxUses').default(-1).notNull(),\n\t\t\tdefault: boolean('default').default(false).notNull(),\n\t\t\tmerchantCouponId: varchar('merchantCouponId', { length: 191 }),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tusedCount: int('usedCount').default(0).notNull(),\n\t\t\tpercentageDiscount: decimal('percentageDiscount', {\n\t\t\t\tprecision: 3,\n\t\t\t\tscale: 2,\n\t\t\t}).notNull(),\n\t\t\trestrictedToProductId: varchar('restrictedToProductId', { length: 191 }),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tcouponIdCodeIndex: index('Coupon_id_code_index').on(\n\t\t\t\t\ttable.id,\n\t\t\t\t\ttable.code,\n\t\t\t\t),\n\t\t\t\tcouponId: primaryKey({ columns: [table.id], name: 'Coupon_id' }),\n\t\t\t\tcouponCodeKey: unique('Coupon_code_key').on(table.code),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n\nexport function getCouponRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst purchase = getPurchaseSchema(mysqlTable)\n\tconst coupon = getCouponSchema(mysqlTable)\n\tconst merchantCoupon = getMerchantCouponSchema(mysqlTable)\n\treturn relations(coupon, ({ many, one }) => ({\n\t\tredeemedBulkCouponPurchases: many(purchase, {\n\t\t\trelationName: 'redeemedBulkCoupon',\n\t\t}),\n\t\tmerchantCoupon: one(merchantCoupon, {\n\t\t\tfields: [coupon.merchantCouponId],\n\t\t\treferences: [merchantCoupon.id],\n\t\t\trelationName: 'merchantCoupon',\n\t\t}),\n\t\tproduct: one(getProductSchema(mysqlTable), {\n\t\t\tfields: [coupon.restrictedToProductId],\n\t\t\treferences: [getProductSchema(mysqlTable).id],\n\t\t\trelationName: 'product',\n\t\t}),\n\t\tbulkPurchases: many(purchase, {\n\t\t\trelationName: 'bulkCoupon',\n\t\t}),\n\t}))\n}\n","import {\n\tdecimal,\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\tunique,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantCouponSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantCoupon',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\tidentifier: varchar('identifier', { length: 191 }),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tstatus: int('status').default(0).notNull(),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t\tpercentageDiscount: decimal('percentageDiscount', {\n\t\t\t\tprecision: 3,\n\t\t\t\tscale: 2,\n\t\t\t}).notNull(),\n\t\t\ttype: varchar('type', { length: 191 }),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantCouponId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantCoupon_id',\n\t\t\t\t}),\n\t\t\t\tmerchantCouponIdentifierKey: unique('MerchantCoupon_identifier_key').on(\n\t\t\t\t\ttable.identifier,\n\t\t\t\t),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import {\n\tindex,\n\tMySqlTableFn,\n\tprimaryKey,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getMerchantSessionSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'MerchantSession',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tidentifier: varchar('identifier', { length: 191 }).notNull(),\n\t\t\tmerchantAccountId: varchar('merchantAccountId', {\n\t\t\t\tlength: 191,\n\t\t\t}).notNull(),\n\t\t},\n\t\t(table) => {\n\t\t\treturn {\n\t\t\t\tmerchantSessionId: primaryKey({\n\t\t\t\t\tcolumns: [table.id],\n\t\t\t\t\tname: 'MerchantSession_id',\n\t\t\t\t}),\n\t\t\t\torganizationIdIdx: index('organizationId_idx').on(table.organizationId),\n\t\t\t}\n\t\t},\n\t)\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tmysqlEnum,\n\tMySqlTableFn,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\nimport { getOrganizationMembershipsSchema } from '../org/organization-memberships.js'\nimport { getCommunicationChannelSchema } from './communication-channel.js'\nimport { getCommunicationPreferenceTypesSchema } from './communication-preference-types.js'\n\nexport function getCommunicationPreferencesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'CommunicationPreference',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\torganizationMembershipId: varchar('organizationMembershipId', {\n\t\t\t\tlength: 255,\n\t\t\t}),\n\t\t\tchannelId: varchar('channelId', { length: 255 }).notNull(),\n\t\t\tpreferenceLevel: mysqlEnum('preferenceLevel', ['low', 'medium', 'high'])\n\t\t\t\t.notNull()\n\t\t\t\t.default('medium'),\n\t\t\tpreferenceTypeId: varchar('preferenceTypeId', { length: 255 }).notNull(),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\toptInAt: timestamp('optInAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t\toptOutAt: timestamp('optOutAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(cp) => ({\n\t\t\tuserIdIdx: index('userId_idx').on(cp.userId),\n\t\t\tpreferenceTypeIdx: index('preferenceTypeId_idx').on(cp.preferenceTypeId),\n\t\t\tchannelIdIdx: index('channelId_idx').on(cp.channelId),\n\t\t\torganizationMembershipIdIdx: index('organizationMembershipId_idx').on(\n\t\t\t\tcp.organizationMembershipId,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getCommunicationPreferencesRelationsSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\tconst communicationPreferences = getCommunicationPreferencesSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst communicationChannel = getCommunicationChannelSchema(mysqlTable)\n\tconst communicationPreferenceTypes =\n\t\tgetCommunicationPreferenceTypesSchema(mysqlTable)\n\tconst organizationMemberships = getOrganizationMembershipsSchema(mysqlTable)\n\treturn relations(communicationPreferences, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [communicationPreferences.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\torganizationMembership: one(organizationMemberships, {\n\t\t\tfields: [communicationPreferences.organizationMembershipId],\n\t\t\treferences: [organizationMemberships.id],\n\t\t\trelationName: 'organizationMembership',\n\t\t}),\n\t\tchannel: one(communicationChannel, {\n\t\t\tfields: [communicationPreferences.channelId],\n\t\t\treferences: [communicationChannel.id],\n\t\t\trelationName: 'channel',\n\t\t}),\n\t\tpreferenceType: one(communicationPreferenceTypes, {\n\t\t\tfields: [communicationPreferences.preferenceTypeId],\n\t\t\treferences: [communicationPreferenceTypes.id],\n\t\t\trelationName: 'preferenceType',\n\t\t}),\n\t}))\n}\n","import {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getCommunicationChannelSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'CommunicationChannel',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tname: varchar('name', { length: 255 }).notNull(),\n\t\t\tdescription: text('description'),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(cc) => ({\n\t\t\tnameIdx: index('name_idx').on(cc.name),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(cc.organizationId),\n\t\t}),\n\t)\n}\n","import {\n\tboolean,\n\tMySqlTableFn,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nexport function getCommunicationPreferenceTypesSchema(\n\tmysqlTable: MySqlTableFn,\n) {\n\treturn mysqlTable('CommunicationPreferenceType', {\n\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\tname: varchar('name', { length: 255 }).notNull(),\n\t\tdescription: text('description'),\n\t\tactive: boolean('active').notNull().default(true),\n\t\tcreatedAt: timestamp('createdAt', {\n\t\t\tmode: 'date',\n\t\t\tfsp: 3,\n\t\t}).defaultNow(),\n\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\tmode: 'date',\n\t\t\tfsp: 3,\n\t\t}),\n\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\tmode: 'date',\n\t\t\tfsp: 3,\n\t\t}),\n\t})\n}\n","import { AdapterAccount } from '@auth/core/adapters'\nimport { relations } from 'drizzle-orm'\nimport {\n\tindex,\n\tint,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttext,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from './users.js'\n\nexport function getAccountsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Account',\n\t\t{\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\ttype: varchar('type', { length: 255 })\n\t\t\t\t.$type<AdapterAccount['type']>()\n\t\t\t\t.notNull(),\n\t\t\tprovider: varchar('provider', { length: 255 }).notNull(),\n\t\t\tproviderAccountId: varchar('providerAccountId', {\n\t\t\t\tlength: 255,\n\t\t\t}).notNull(),\n\t\t\trefresh_token: text('refresh_token'),\n\t\t\taccess_token: text('access_token'),\n\t\t\toauth_token: text('oauth_token'),\n\t\t\toauth_token_secret: text('oauth_token_secret'),\n\t\t\texpires_at: int('expires_at'),\n\t\t\ttoken_type: varchar('token_type', { length: 255 }),\n\t\t\tscope: varchar('scope', { length: 255 }),\n\t\t\tid_token: text('id_token'),\n\t\t\tsession_state: varchar('session_state', { length: 255 }),\n\t\t\trefresh_token_expires_in: int('refresh_token_expires_in'),\n\t\t},\n\t\t(account) => ({\n\t\t\tpk: primaryKey({\n\t\t\t\tcolumns: [account.provider, account.providerAccountId],\n\t\t\t}),\n\t\t\tuserIdIdx: index('userId_idx').on(account.userId),\n\t\t}),\n\t)\n}\n\nexport function getAccountsRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst accounts = getAccountsSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\treturn relations(accounts, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [accounts.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\ttimestamp,\n\tuniqueIndex,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from './users.js'\n\nexport function getProfilesSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Profile',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\ttype: varchar('type', { length: 255 }).notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t},\n\t\t(profile) => ({\n\t\t\tuserIdIdx: index('userId_idx').on(profile.userId),\n\t\t\tuniqueUserType: uniqueIndex('unique_user_type_idx').on(\n\t\t\t\tprofile.userId,\n\t\t\t\tprofile.type,\n\t\t\t),\n\t\t}),\n\t)\n}\n\nexport function getProfilesRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst profiles = getProfilesSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\treturn relations(profiles, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [profiles.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'profiles',\n\t\t}),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getPermissionsSchema } from './permissions.js'\nimport { getUsersSchema } from './users.js'\n\nexport function getUserPermissionsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'UserPermission',\n\t\t{\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\tpermissionId: varchar('permissionId', { length: 255 }).notNull(),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(up) => ({\n\t\t\tpk: primaryKey({ columns: [up.userId, up.permissionId] }),\n\t\t\tuserIdIdx: index('userId_idx').on(up.userId),\n\t\t\tpermissionIdIdx: index('permissionId_idx').on(up.permissionId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(up.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getUserPermissionsRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst userPermissions = getUserPermissionsSchema(mysqlTable)\n\tconst users = getUsersSchema(mysqlTable)\n\tconst permissions = getPermissionsSchema(mysqlTable)\n\treturn relations(userPermissions, ({ one }) => ({\n\t\tuser: one(users, {\n\t\t\tfields: [userPermissions.userId],\n\t\t\treferences: [users.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t\tpermission: one(permissions, {\n\t\t\tfields: [userPermissions.permissionId],\n\t\t\treferences: [permissions.id],\n\t\t\trelationName: 'permission',\n\t\t}),\n\t}))\n}\n","import { relations } from 'drizzle-orm'\nimport {\n\tboolean,\n\tindex,\n\tMySqlTableFn,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getRolePermissionsSchema } from './role-permissions.js'\n\nexport function getPermissionsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'Permission',\n\t\t{\n\t\t\tid: varchar('id', { length: 255 }).notNull().primaryKey(),\n\t\t\tname: varchar('name', { length: 255 }).notNull().unique(),\n\t\t\tdescription: text('description'),\n\t\t\tactive: boolean('active').notNull().default(true),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).defaultNow(),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(permission) => ({\n\t\t\tnameIdx: index('name_idx').on(permission.name),\n\t\t}),\n\t)\n}\n\nexport function getPermissionsRelationsSchema(mysqlTable: MySqlTableFn) {\n\treturn relations(getPermissionsSchema(mysqlTable), ({ many }) => ({}))\n}\n","import { relations, sql } from 'drizzle-orm'\nimport {\n\tindex,\n\tjson,\n\tMySqlTableFn,\n\tprimaryKey,\n\ttext,\n\ttimestamp,\n\tvarchar,\n} from 'drizzle-orm/mysql-core'\n\nimport { getUsersSchema } from '../auth/users.js'\n\nexport function getUserPrefsSchema(mysqlTable: MySqlTableFn) {\n\treturn mysqlTable(\n\t\t'UserPrefs',\n\t\t{\n\t\t\tid: varchar('id', { length: 191 }).notNull(),\n\t\t\torganizationId: varchar('organizationId', { length: 191 }),\n\t\t\ttype: varchar('type', { length: 191 }).default('Global').notNull(),\n\t\t\tuserId: varchar('userId', { length: 255 }).notNull(),\n\t\t\tfields: json('fields').$type<Record<string, any>>().default({}),\n\t\t\tcreatedAt: timestamp('createdAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tupdatedAt: timestamp('updatedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}).default(sql`CURRENT_TIMESTAMP(3)`),\n\t\t\tdeletedAt: timestamp('deletedAt', {\n\t\t\t\tmode: 'date',\n\t\t\t\tfsp: 3,\n\t\t\t}),\n\t\t},\n\t\t(crr) => ({\n\t\t\tpk: primaryKey({ columns: [crr.id] }),\n\t\t\tcrrUserIdIdKey: index('crr_userIdId_idx').on(crr.userId),\n\t\t\torganizationIdIdx: index('organizationId_idx').on(crr.organizationId),\n\t\t}),\n\t)\n}\n\nexport function getUserPrefsRelationsSchema(mysqlTable: MySqlTableFn) {\n\tconst userPrefs = getUserPrefsSchema(mysqlTable)\n\tconst user = getUsersSchema(mysqlTable)\n\treturn relations(userPrefs, ({ one }) => ({\n\t\tuser: one(user, {\n\t\t\tfields: [userPrefs.userId],\n\t\t\treferences: [user.id],\n\t\t\trelationName: 'user',\n\t\t}),\n\t}))\n}\n"],"mappings":"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","names":["import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","getOrganizationMembershipsSchema","mysqlTable","id","varchar","length","notNull","primaryKey","organizationId","role","default","invitedById","userId","fields","json","$type","createdAt","timestamp","mode","fsp","sql","organizationMembership","roleIdx","index","on","createdAtIdx","organizationIdIdx","import_drizzle_orm","import_mysql_core","import_mysql_core","import_mysql_core","import_drizzle_orm","import_mysql_core","import_mysql_core","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","import_drizzle_orm","import_mysql_core","getUsersSchema","mysqlTable","id","varchar","length","notNull","primaryKey","name","role","default","email","unique","fields","json","$type","emailVerified","timestamp","mode","fsp","image","createdAt","sql","user","emailIdx","index","on","roleIdx","createdAtIdx","getCommentsSchema","mysqlTable","id","varchar","length","notNull","userId","organizationMembershipId","context","json","$type","default","text","createdAt","timestamp","mode","fsp","sql","updatedAt","deletedAt","crr","pk","primaryKey","columns","crrUserIdIdKey","index","on","organizationMembershipIdIdx","getCommentRelationsSchema","comment","user","getUsersSchema","organizationMemberships","getOrganizationMembershipsSchema","relations","one","fields","references","relationName","organizationMembership"]}