@coursebuilder/adapter-drizzle
Version:
Drizzle adapter for Course Builder.
1,572 lines (1,538 loc) • 66.5 kB
JavaScript
import {
getContributionTypesSchema
} from "./chunk-MP4CUWYC.js";
import {
getCommunicationChannelSchema
} from "./chunk-WJWJ6E5Y.js";
import {
getCommunicationPreferenceTypesSchema
} from "./chunk-EHRARBRS.js";
import {
getMerchantSessionSchema
} from "./chunk-BLDW3QUS.js";
import {
getMerchantAccountSchema
} from "./chunk-DKJO4Y3K.js";
import {
getMerchantCouponSchema
} from "./chunk-WPJZAYX7.js";
import {
getMerchantCustomerSchema
} from "./chunk-6MRFUIH5.js";
import {
getMerchantPriceSchema
} from "./chunk-MGZMGDQ5.js";
import {
getMerchantProductSchema
} from "./chunk-KPBVZ44W.js";
import {
getPermissionsSchema
} from "./chunk-LZHZDFNZ.js";
import {
__name
} from "./chunk-H736K5TN.js";
// src/lib/mysql/schemas/auth/user-roles.ts
import { relations as relations27 } from "drizzle-orm";
import { boolean as boolean7, index as index27, primaryKey as primaryKey17, timestamp as timestamp26, varchar as varchar27 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/auth/roles.ts
import { relations } from "drizzle-orm";
import { boolean, index, text, timestamp, uniqueIndex, varchar } from "drizzle-orm/mysql-core";
function getRolesSchema(mysqlTable) {
return mysqlTable("Role", {
id: varchar("id", {
length: 255
}).notNull().primaryKey(),
organizationId: varchar("organizationId", {
length: 191
}),
name: varchar("name", {
length: 255
}).notNull(),
description: text("description"),
active: boolean("active").notNull().default(true),
createdAt: timestamp("createdAt", {
mode: "date",
fsp: 3
}).defaultNow(),
updatedAt: timestamp("updatedAt", {
mode: "date",
fsp: 3
}).defaultNow(),
deletedAt: timestamp("deletedAt", {
mode: "date",
fsp: 3
})
}, (role) => ({
nameIdx: index("name_idx").on(role.name),
organizationIdIdx: index("organizationId_idx").on(role.organizationId),
uniqueNamePerOrg: uniqueIndex("unique_name_per_org").on(role.organizationId, role.name)
}));
}
__name(getRolesSchema, "getRolesSchema");
function getRolesRelationsSchema(mysqlTable) {
const roles = getRolesSchema(mysqlTable);
const userRoles = getUserRolesSchema(mysqlTable);
return relations(roles, ({ many }) => ({
userRoles: many(userRoles, {
relationName: "role"
})
}));
}
__name(getRolesRelationsSchema, "getRolesRelationsSchema");
// src/lib/mysql/schemas/auth/users.ts
import { relations as relations26, sql as sql20 } from "drizzle-orm";
import { index as index26, json as json17, timestamp as timestamp25, varchar as varchar26 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/commerce/purchase.ts
import { relations as relations19, sql as sql16 } from "drizzle-orm";
import { decimal as decimal3, index as index19, json as json13, primaryKey as primaryKey12, timestamp as timestamp19, unique as unique4, varchar as varchar19 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/org/organization-memberships.ts
import { relations as relations17, sql as sql14 } from "drizzle-orm";
import { index as index17, json as json11, timestamp as timestamp17, varchar as varchar17 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/org/organization-membership-roles.ts
import { relations as relations16 } from "drizzle-orm";
import { boolean as boolean3, index as index16, primaryKey as primaryKey10, timestamp as timestamp16, varchar as varchar16 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/org/organizations.ts
import { relations as relations15, sql as sql13 } from "drizzle-orm";
import { index as index15, json as json10, timestamp as timestamp15, varchar as varchar15 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/commerce/subscription.ts
import { relations as relations14, sql as sql12 } from "drizzle-orm";
import { index as index14, json as json9, primaryKey as primaryKey9, timestamp as timestamp14, varchar as varchar14 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/commerce/merchant-subscription.ts
import { relations as relations3, sql as sql2 } from "drizzle-orm";
import { index as index3, int as int2, primaryKey as primaryKey2, timestamp as timestamp3, varchar as varchar3 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/commerce/merchant-charge.ts
import { relations as relations2, sql } from "drizzle-orm";
import { index as index2, int, primaryKey, timestamp as timestamp2, unique, varchar as varchar2 } from "drizzle-orm/mysql-core";
function getMerchantChargeSchema(mysqlTable) {
return mysqlTable("MerchantCharge", {
id: varchar2("id", {
length: 191
}).notNull(),
organizationId: varchar2("organizationId", {
length: 191
}),
status: int("status").default(0).notNull(),
identifier: varchar2("identifier", {
length: 191
}).notNull(),
userId: varchar2("userId", {
length: 191
}).notNull(),
merchantAccountId: varchar2("merchantAccountId", {
length: 191
}).notNull(),
merchantProductId: varchar2("merchantProductId", {
length: 191
}).notNull(),
merchantSubscriptionId: varchar2("merchantSubscriptionId", {
length: 191
}),
createdAt: timestamp2("createdAt", {
mode: "date",
fsp: 3
}).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
merchantCustomerId: varchar2("merchantCustomerId", {
length: 191
}).notNull()
}, (table) => {
return {
merchantChargeId: primaryKey({
columns: [
table.id
],
name: "MerchantCharge_id"
}),
merchantChargeIdentifierKey: unique("MerchantCharge_identifier_key").on(table.identifier),
merchantSubscriptionIdIdx: index2("merchantSubscriptionId_idx").on(table.merchantSubscriptionId),
organizationIdIdx: index2("organizationId_idx").on(table.organizationId)
};
});
}
__name(getMerchantChargeSchema, "getMerchantChargeSchema");
function getMerchantChargeRelationsSchema(mysqlTable) {
const merchantCharge = getMerchantChargeSchema(mysqlTable);
const merchantAccount = getMerchantAccountSchema(mysqlTable);
const merchantProduct = getMerchantProductSchema(mysqlTable);
const merchantCustomer = getMerchantCustomerSchema(mysqlTable);
const merchantSubscription = getMerchantSubscriptionSchema(mysqlTable);
return relations2(merchantCharge, ({ one }) => ({
merchantAccount: one(merchantAccount, {
fields: [
merchantCharge.merchantAccountId
],
references: [
merchantAccount.id
],
relationName: "merchantAccount"
}),
merchantProduct: one(merchantProduct, {
fields: [
merchantCharge.merchantProductId
],
references: [
merchantProduct.id
],
relationName: "merchantProduct"
}),
merchantCustomer: one(merchantCustomer, {
fields: [
merchantCharge.merchantCustomerId
],
references: [
merchantCustomer.id
],
relationName: "merchantCustomer"
}),
merchantSubscription: one(merchantSubscription, {
fields: [
merchantCharge.merchantSubscriptionId
],
references: [
merchantSubscription.id
],
relationName: "merchantSubscription"
})
}));
}
__name(getMerchantChargeRelationsSchema, "getMerchantChargeRelationsSchema");
// src/lib/mysql/schemas/commerce/merchant-subscription.ts
function getMerchantSubscriptionSchema(mysqlTable) {
return mysqlTable("MerchantSubscription", {
id: varchar3("id", {
length: 191
}).notNull(),
organizationId: varchar3("organizationId", {
length: 191
}),
merchantAccountId: varchar3("merchantAccountId", {
length: 191
}).notNull(),
status: int2("status").default(0).notNull(),
createdAt: timestamp3("createdAt", {
mode: "date",
fsp: 3
}).default(sql2`CURRENT_TIMESTAMP(3)`).notNull(),
label: varchar3("label", {
length: 191
}),
identifier: varchar3("identifier", {
length: 191
}),
merchantCustomerId: varchar3("merchantCustomerId", {
length: 191
}).notNull(),
merchantProductId: varchar3("merchantProductId", {
length: 191
}).notNull()
}, (table) => {
return {
merchantSubscriptionId: primaryKey2({
columns: [
table.id
],
name: "MerchantSubscription_id"
}),
organizationIdIdx: index3("organizationId_idx").on(table.organizationId)
};
});
}
__name(getMerchantSubscriptionSchema, "getMerchantSubscriptionSchema");
function getMerchantSubscriptionRelationsSchema(mysqlTable) {
const merchantSubscription = getMerchantSubscriptionSchema(mysqlTable);
const merchantCharge = getMerchantChargeSchema(mysqlTable);
const subscription = getSubscriptionSchema(mysqlTable);
return relations3(merchantSubscription, ({ many, one }) => ({
merchantCharges: many(merchantCharge, {
relationName: "merchantSubscription"
}),
subscription: one(subscription, {
fields: [
merchantSubscription.id
],
references: [
subscription.merchantSubscriptionId
],
relationName: "subscription"
})
}));
}
__name(getMerchantSubscriptionRelationsSchema, "getMerchantSubscriptionRelationsSchema");
// src/lib/mysql/schemas/commerce/product.ts
import { relations as relations13, sql as sql11 } from "drizzle-orm";
import { index as index13, int as int5, json as json8, primaryKey as primaryKey8, timestamp as timestamp13, varchar as varchar13 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/content/content-resource-product.ts
import { relations as relations11, sql as sql9 } from "drizzle-orm";
import { double as double4, index as index11, json as json6, primaryKey as primaryKey6, timestamp as timestamp11, varchar as varchar11 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/content/content-resource.ts
import { relations as relations10, sql as sql8 } from "drizzle-orm";
import { index as index10, json as json5, timestamp as timestamp10, varchar as varchar10 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/content/content-contributions.ts
import { relations as relations4 } from "drizzle-orm";
import { boolean as boolean2, index as index4, timestamp as timestamp4, varchar as varchar4 } from "drizzle-orm/mysql-core";
function getContentContributionsSchema(mysqlTable) {
return mysqlTable("ContentContribution", {
id: varchar4("id", {
length: 255
}).notNull().primaryKey(),
userId: varchar4("userId", {
length: 255
}).notNull(),
organizationId: varchar4("organizationId", {
length: 191
}),
organizationMembershipId: varchar4("organizationMembershipId", {
length: 255
}),
contentId: varchar4("contentId", {
length: 255
}).notNull(),
contributionTypeId: varchar4("contributionTypeId", {
length: 255
}).notNull(),
active: boolean2("active").notNull().default(true),
createdAt: timestamp4("createdAt", {
mode: "date",
fsp: 3
}).defaultNow(),
updatedAt: timestamp4("updatedAt", {
mode: "date",
fsp: 3
}).defaultNow(),
deletedAt: timestamp4("deletedAt", {
mode: "date",
fsp: 3
})
}, (cc) => ({
userIdIdx: index4("userId_idx").on(cc.userId),
contentIdIdx: index4("contentId_idx").on(cc.contentId),
contributionTypeIdIdx: index4("contributionTypeId_idx").on(cc.contributionTypeId),
organizationMembershipIdIdx: index4("organizationMembershipId_idx").on(cc.organizationMembershipId)
}));
}
__name(getContentContributionsSchema, "getContentContributionsSchema");
function getContentContributionRelationsSchema(mysqlTable) {
const contentContributions = getContentContributionsSchema(mysqlTable);
const users = getUsersSchema(mysqlTable);
const contentResource = getContentResourceSchema(mysqlTable);
const contributionTypes = getContributionTypesSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
return relations4(contentContributions, ({ one }) => ({
user: one(users, {
fields: [
contentContributions.userId
],
references: [
users.id
],
relationName: "user"
}),
content: one(contentResource, {
fields: [
contentContributions.contentId
],
references: [
contentResource.id
],
relationName: "contributions"
}),
contributionType: one(contributionTypes, {
fields: [
contentContributions.contributionTypeId
],
references: [
contributionTypes.id
],
relationName: "contributionType"
}),
organizationMembership: one(organizationMemberships, {
fields: [
contentContributions.organizationMembershipId
],
references: [
organizationMemberships.id
],
relationName: "organizationMembership"
})
}));
}
__name(getContentContributionRelationsSchema, "getContentContributionRelationsSchema");
// src/lib/mysql/schemas/content/content-resource-resource.ts
import { relations as relations5, sql as sql3 } from "drizzle-orm";
import { double, index as index5, json, primaryKey as primaryKey3, timestamp as timestamp5, varchar as varchar5 } from "drizzle-orm/mysql-core";
function getContentResourceResourceSchema(mysqlTable) {
return mysqlTable("ContentResourceResource", {
resourceOfId: varchar5("resourceOfId", {
length: 255
}).notNull(),
resourceId: varchar5("resourceId", {
length: 255
}).notNull(),
position: double("position").notNull().default(0),
metadata: json("metadata").$type().default({}),
organizationId: varchar5("organizationId", {
length: 191
}),
createdAt: timestamp5("createdAt", {
mode: "date",
fsp: 3
}).default(sql3`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp5("updatedAt", {
mode: "date",
fsp: 3
}).default(sql3`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp5("deletedAt", {
mode: "date",
fsp: 3
})
}, (crr) => ({
pk: primaryKey3({
columns: [
crr.resourceOfId,
crr.resourceId
]
}),
contentResourceIdIdx: index5("contentResourceId_idx").on(crr.resourceOfId),
resourceIdIdx: index5("resourceId_idx").on(crr.resourceId),
organizationIdIdx: index5("organizationId_idx").on(crr.organizationId)
}));
}
__name(getContentResourceResourceSchema, "getContentResourceResourceSchema");
function getContentResourceResourceRelationsSchema(mysqlTable) {
const contentResource = getContentResourceSchema(mysqlTable);
const contentResourceResource = getContentResourceResourceSchema(mysqlTable);
return relations5(contentResourceResource, ({ one }) => ({
resourceOf: one(contentResource, {
fields: [
contentResourceResource.resourceOfId
],
references: [
contentResource.id
],
relationName: "resourceOf"
}),
resource: one(contentResource, {
fields: [
contentResourceResource.resourceId
],
references: [
contentResource.id
],
relationName: "resource"
})
}));
}
__name(getContentResourceResourceRelationsSchema, "getContentResourceResourceRelationsSchema");
// src/lib/mysql/schemas/content/content-resource-tag.ts
import { relations as relations8, sql as sql6 } from "drizzle-orm";
import { double as double3, index as index8, primaryKey as primaryKey5, timestamp as timestamp8, varchar as varchar8 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/content/tag.ts
import { relations as relations7, sql as sql5 } from "drizzle-orm";
import { index as index7, json as json3, timestamp as timestamp7, varchar as varchar7 } from "drizzle-orm/mysql-core";
// src/lib/mysql/schemas/content/tag-tag.ts
import { relations as relations6, sql as sql4 } from "drizzle-orm";
import { double as double2, index as index6, json as json2, primaryKey as primaryKey4, timestamp as timestamp6, varchar as varchar6 } from "drizzle-orm/mysql-core";
function getTagTagSchema(mysqlTable) {
return mysqlTable("TagTag", {
parentTagId: varchar6("parentTagId", {
length: 255
}).notNull(),
childTagId: varchar6("childTagId", {
length: 255
}).notNull(),
position: double2("position").notNull().default(0),
metadata: json2("metadata").$type().default({}),
organizationId: varchar6("organizationId", {
length: 191
}),
createdAt: timestamp6("createdAt", {
mode: "date",
fsp: 3
}).default(sql4`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp6("updatedAt", {
mode: "date",
fsp: 3
}).default(sql4`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp6("deletedAt", {
mode: "date",
fsp: 3
})
}, (tt) => ({
pk: primaryKey4({
columns: [
tt.parentTagId,
tt.childTagId
]
}),
parentTagIdIdx: index6("parentTagId_idx").on(tt.parentTagId),
childTagIdIdx: index6("childTagId_idx").on(tt.childTagId),
positionIdx: index6("position_idx").on(tt.position),
organizationIdIdx: index6("organizationId_idx").on(tt.organizationId)
}));
}
__name(getTagTagSchema, "getTagTagSchema");
function getTagTagRelationsSchema(mysqlTable) {
const tag = getTagSchema(mysqlTable);
const tagTag = getTagTagSchema(mysqlTable);
return relations6(tagTag, ({ one }) => ({
parentTag: one(tag, {
fields: [
tagTag.parentTagId
],
references: [
tag.id
],
relationName: "parentTag"
}),
childTag: one(tag, {
fields: [
tagTag.childTagId
],
references: [
tag.id
],
relationName: "childTag"
})
}));
}
__name(getTagTagRelationsSchema, "getTagTagRelationsSchema");
// src/lib/mysql/schemas/content/tag.ts
function getTagSchema(mysqlTable) {
return mysqlTable("Tag", {
id: varchar7("id", {
length: 255
}).notNull().primaryKey(),
organizationId: varchar7("organizationId", {
length: 191
}),
type: varchar7("type", {
length: 255
}).notNull(),
fields: json3("fields").$type().default({}),
createdAt: timestamp7("createdAt", {
mode: "date",
fsp: 3
}).default(sql5`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp7("updatedAt", {
mode: "date",
fsp: 3
}).default(sql5`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp7("deletedAt", {
mode: "date",
fsp: 3
})
}, (t) => ({
typeIdx: index7("type_idx").on(t.type),
organizationIdIdx: index7("organizationId_idx").on(t.organizationId)
}));
}
__name(getTagSchema, "getTagSchema");
function getTagRelationsSchema(mysqlTable) {
const tag = getTagSchema(mysqlTable);
const contentResourceTag = getContentResourceTagSchema(mysqlTable);
const tagTag = getTagTagSchema(mysqlTable);
return relations7(tag, ({ many }) => ({
resources: many(contentResourceTag, {
relationName: "contentResource"
}),
parentTags: many(tagTag, {
relationName: "childTag"
}),
childTags: many(tagTag, {
relationName: "parentTag"
})
}));
}
__name(getTagRelationsSchema, "getTagRelationsSchema");
// src/lib/mysql/schemas/content/content-resource-tag.ts
function getContentResourceTagSchema(mysqlTable) {
return mysqlTable("ContentResourceTag", {
contentResourceId: varchar8("contentResourceId", {
length: 255
}).notNull(),
organizationId: varchar8("organizationId", {
length: 191
}),
tagId: varchar8("tagId", {
length: 255
}).notNull(),
position: double3("position").notNull().default(0),
createdAt: timestamp8("createdAt", {
mode: "date",
fsp: 3
}).default(sql6`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp8("updatedAt", {
mode: "date",
fsp: 3
}).default(sql6`CURRENT_TIMESTAMP(3)`)
}, (crt) => ({
pk: primaryKey5({
columns: [
crt.contentResourceId,
crt.tagId
]
}),
contentResourceIdIdx: index8("contentResourceId_idx").on(crt.contentResourceId),
tagIdIdx: index8("tagId_idx").on(crt.tagId),
positionIdx: index8("position_idx").on(crt.position),
organizationIdIdx: index8("organizationId_idx").on(crt.organizationId)
}));
}
__name(getContentResourceTagSchema, "getContentResourceTagSchema");
function getContentResourceTagRelationsSchema(mysqlTable) {
const contentResource = getContentResourceSchema(mysqlTable);
const tag = getTagSchema(mysqlTable);
const contentResourceTag = getContentResourceTagSchema(mysqlTable);
return relations8(contentResourceTag, ({ one }) => ({
contentResource: one(contentResource, {
fields: [
contentResourceTag.contentResourceId
],
references: [
contentResource.id
],
relationName: "contentResource"
}),
tag: one(tag, {
fields: [
contentResourceTag.tagId
],
references: [
tag.id
],
relationName: "tag"
})
}));
}
__name(getContentResourceTagRelationsSchema, "getContentResourceTagRelationsSchema");
// src/lib/mysql/schemas/content/content-resource-version.ts
import { relations as relations9, sql as sql7 } from "drizzle-orm";
import { index as index9, int as int3, json as json4, timestamp as timestamp9, unique as unique2, varchar as varchar9 } from "drizzle-orm/mysql-core";
function getContentResourceVersionSchema(mysqlTable) {
return mysqlTable("ContentResourceVersion", {
id: varchar9("id", {
length: 255
}).notNull().primaryKey(),
organizationId: varchar9("organizationId", {
length: 191
}),
resourceId: varchar9("resourceId", {
length: 255
}).notNull(),
parentVersionId: varchar9("parentVersionId", {
length: 255
}),
versionNumber: int3("versionNumber").notNull(),
fields: json4("fields").$type().default({}),
createdAt: timestamp9("createdAt", {
mode: "date",
fsp: 3
}).default(sql7`CURRENT_TIMESTAMP(3)`),
createdById: varchar9("createdById", {
length: 255
}).notNull()
}, (crv) => ({
resourceIdIdx: index9("resourceId_idx").on(crv.resourceId),
parentVersionIdIdx: index9("parentVersionId_idx").on(crv.parentVersionId),
resourceIdVersionNumberIdx: index9("resourceId_versionNumber_idx").on(crv.resourceId, crv.versionNumber),
uniqueResourceVersion: unique2("uq_resource_version_number").on(crv.resourceId, crv.versionNumber),
organizationIdIdx: index9("organizationId_idx").on(crv.organizationId)
}));
}
__name(getContentResourceVersionSchema, "getContentResourceVersionSchema");
function getContentResourceVersionRelationsSchema(mysqlTable) {
const contentResourceVersion = getContentResourceVersionSchema(mysqlTable);
const contentResource = getContentResourceSchema(mysqlTable);
const users = getUsersSchema(mysqlTable);
return relations9(contentResourceVersion, ({ one }) => ({
resource: one(contentResource, {
fields: [
contentResourceVersion.resourceId
],
references: [
contentResource.id
],
relationName: "versions"
}),
parentVersion: one(contentResourceVersion, {
fields: [
contentResourceVersion.parentVersionId
],
references: [
contentResourceVersion.id
],
relationName: "childVersions"
}),
createdBy: one(users, {
fields: [
contentResourceVersion.createdById
],
references: [
users.id
],
relationName: "createdVersions"
})
}));
}
__name(getContentResourceVersionRelationsSchema, "getContentResourceVersionRelationsSchema");
// src/lib/mysql/schemas/content/content-resource.ts
function getContentResourceSchema(mysqlTable) {
return mysqlTable("ContentResource", {
id: varchar10("id", {
length: 255
}).notNull().primaryKey(),
organizationId: varchar10("organizationId", {
length: 191
}),
createdByOrganizationMembershipId: varchar10("createdByOrganizationMembershipId", {
length: 191
}),
type: varchar10("type", {
length: 255
}).notNull(),
createdById: varchar10("createdById", {
length: 255
}).notNull(),
fields: json5("fields").$type().default({}),
currentVersionId: varchar10("currentVersionId", {
length: 255
}),
createdAt: timestamp10("createdAt", {
mode: "date",
fsp: 3
}).default(sql8`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp10("updatedAt", {
mode: "date",
fsp: 3
}).default(sql8`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp10("deletedAt", {
mode: "date",
fsp: 3
})
}, (cm) => ({
typeIdx: index10("type_idx").on(cm.type),
createdByIdx: index10("createdById_idx").on(cm.createdById),
createdAtIdx: index10("createdAt_idx").on(cm.createdAt),
currentVersionIdIdx: index10("currentVersionId_idx").on(cm.currentVersionId),
createdByOrganizationMembershipIdIdx: index10("createdByOrganizationMembershipId_idx").on(cm.createdByOrganizationMembershipId)
}));
}
__name(getContentResourceSchema, "getContentResourceSchema");
function getContentResourceRelationsSchema(mysqlTable) {
const contentResource = getContentResourceSchema(mysqlTable);
const users = getUsersSchema(mysqlTable);
const contentResourceResource = getContentResourceResourceSchema(mysqlTable);
const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
const contentContributions = getContentContributionsSchema(mysqlTable);
const contentResourceTag = getContentResourceTagSchema(mysqlTable);
const contentResourceVersion = getContentResourceVersionSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
const tag = getTagSchema(mysqlTable);
return relations10(contentResource, ({ one, many }) => ({
createdBy: one(users, {
fields: [
contentResource.createdById
],
references: [
users.id
],
relationName: "creator"
}),
createdByOrganizationMembership: one(organizationMemberships, {
fields: [
contentResource.createdByOrganizationMembershipId
],
references: [
organizationMemberships.id
],
relationName: "createdByOrganizationMembership"
}),
tags: many(contentResourceTag, {
relationName: "contentResource"
}),
resources: many(contentResourceResource, {
relationName: "resourceOf"
}),
resourceOf: many(contentResourceResource, {
relationName: "resource"
}),
resourceProducts: many(contentResourceProduct, {
relationName: "resource"
}),
contributions: many(contentContributions, {
relationName: "contributions"
}),
currentVersion: one(contentResourceVersion, {
fields: [
contentResource.currentVersionId
],
references: [
contentResourceVersion.id
],
relationName: "currentVersionResource"
}),
versions: many(contentResourceVersion, {
relationName: "resource"
})
}));
}
__name(getContentResourceRelationsSchema, "getContentResourceRelationsSchema");
// src/lib/mysql/schemas/content/content-resource-product.ts
function getContentResourceProductSchema(mysqlTable) {
return mysqlTable("ContentResourceProduct", {
productId: varchar11("productId", {
length: 255
}).notNull(),
resourceId: varchar11("resourceId", {
length: 255
}).notNull(),
organizationId: varchar11("organizationId", {
length: 191
}),
position: double4("position").notNull().default(0),
metadata: json6("metadata").$type().default({}),
createdAt: timestamp11("createdAt", {
mode: "date",
fsp: 3
}).default(sql9`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp11("updatedAt", {
mode: "date",
fsp: 3
}).default(sql9`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp11("deletedAt", {
mode: "date",
fsp: 3
})
}, (crr) => ({
pk: primaryKey6({
columns: [
crr.productId,
crr.resourceId
]
}),
contentResourceIdIdx: index11("contentResourceId_idx").on(crr.productId),
resourceIdIdx: index11("resourceId_idx").on(crr.resourceId),
organizationIdIdx: index11("organizationId_idx").on(crr.organizationId)
}));
}
__name(getContentResourceProductSchema, "getContentResourceProductSchema");
function getContentResourceProductRelationsSchema(mysqlTable) {
const contentResource = getContentResourceSchema(mysqlTable);
const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
const product = getProductSchema(mysqlTable);
return relations11(contentResourceProduct, ({ one }) => ({
product: one(product, {
fields: [
contentResourceProduct.productId
],
references: [
product.id
],
relationName: "product"
}),
resource: one(contentResource, {
fields: [
contentResourceProduct.resourceId
],
references: [
contentResource.id
],
relationName: "resource"
})
}));
}
__name(getContentResourceProductRelationsSchema, "getContentResourceProductRelationsSchema");
// src/lib/mysql/schemas/commerce/price.ts
import { relations as relations12, sql as sql10 } from "drizzle-orm";
import { decimal, index as index12, int as int4, json as json7, primaryKey as primaryKey7, timestamp as timestamp12, varchar as varchar12 } from "drizzle-orm/mysql-core";
function getPriceSchema(mysqlTable) {
return mysqlTable("Price", {
id: varchar12("id", {
length: 191
}).notNull(),
productId: varchar12("productId", {
length: 191
}),
organizationId: varchar12("organizationId", {
length: 191
}),
nickname: varchar12("nickname", {
length: 191
}),
status: int4("status").default(0).notNull(),
unitAmount: decimal("unitAmount", {
precision: 10,
scale: 2
}).notNull(),
createdAt: timestamp12("createdAt", {
mode: "date",
fsp: 3
}).default(sql10`CURRENT_TIMESTAMP(3)`).notNull(),
fields: json7("fields").$type().default({})
}, (table) => {
return {
priceId: primaryKey7({
columns: [
table.id
],
name: "Price_id"
}),
organizationIdIdx: index12("organizationId_idx").on(table.organizationId)
};
});
}
__name(getPriceSchema, "getPriceSchema");
function getProductRelationsSchema(mysqlTable) {
const product = getProductSchema(mysqlTable);
const price = getPriceSchema(mysqlTable);
const merchantPrice = getMerchantPriceSchema(mysqlTable);
return relations12(price, ({ one, many }) => ({
product: one(product, {
fields: [
price.productId
],
references: [
product.id
],
relationName: "user"
}),
merchantPrice: one(merchantPrice, {
fields: [
price.id
],
references: [
merchantPrice.priceId
],
relationName: "merchantPrice"
})
}));
}
__name(getProductRelationsSchema, "getProductRelationsSchema");
// src/lib/mysql/schemas/commerce/product.ts
function getProductSchema(mysqlTable) {
return mysqlTable("Product", {
id: varchar13("id", {
length: 191
}).notNull(),
organizationId: varchar13("organizationId", {
length: 191
}),
name: varchar13("name", {
length: 191
}).notNull(),
key: varchar13("key", {
length: 191
}),
type: varchar13("type", {
length: 191
}),
fields: json8("fields").$type().default({}),
createdAt: timestamp13("createdAt", {
mode: "date",
fsp: 3
}).default(sql11`CURRENT_TIMESTAMP(3)`).notNull(),
status: int5("status").default(0).notNull(),
quantityAvailable: int5("quantityAvailable").default(-1).notNull()
}, (table) => {
return {
productId: primaryKey8({
columns: [
table.id
],
name: "Product_id"
}),
organizationIdIdx: index13("organizationId_idx").on(table.organizationId)
};
});
}
__name(getProductSchema, "getProductSchema");
function getProductRelationsSchema2(mysqlTable) {
const product = getProductSchema(mysqlTable);
const price = getPriceSchema(mysqlTable);
const merchantProduct = getMerchantProductSchema(mysqlTable);
const contentResourceProduct = getContentResourceProductSchema(mysqlTable);
return relations13(product, ({ one, many }) => ({
price: one(price, {
fields: [
product.id
],
references: [
price.productId
],
relationName: "price"
}),
resources: many(contentResourceProduct, {
relationName: "product"
}),
merchantProduct: one(merchantProduct, {
fields: [
product.id
],
references: [
merchantProduct.productId
],
relationName: "merchantProduct"
})
}));
}
__name(getProductRelationsSchema2, "getProductRelationsSchema");
// src/lib/mysql/schemas/commerce/subscription.ts
function getSubscriptionSchema(mysqlTable) {
return mysqlTable("Subscription", {
id: varchar14("id", {
length: 191
}).notNull(),
organizationId: varchar14("organizationId", {
length: 191
}),
productId: varchar14("productId", {
length: 191
}).notNull(),
createdAt: timestamp14("createdAt", {
mode: "date",
fsp: 3
}).default(sql12`CURRENT_TIMESTAMP(3)`).notNull(),
merchantSubscriptionId: varchar14("merchantSubscriptionId", {
length: 191
}).notNull(),
status: varchar14("status", {
length: 191
}).default("active").notNull(),
fields: json9("fields").$type().default({})
}, (table) => {
return {
subscriptionId: primaryKey9({
columns: [
table.id
],
name: "Subscription_id"
}),
organizationIdIdx: index14("organizationId_idx").on(table.organizationId)
};
});
}
__name(getSubscriptionSchema, "getSubscriptionSchema");
function getSubscriptionRelationsSchema(mysqlTable) {
const subscriptions = getSubscriptionSchema(mysqlTable);
const products = getProductSchema(mysqlTable);
const organizations = getOrganizationsSchema(mysqlTable);
const merchantSubscriptions = getMerchantSubscriptionSchema(mysqlTable);
return relations14(subscriptions, ({ many, one }) => ({
organization: one(organizations, {
fields: [
subscriptions.organizationId
],
references: [
organizations.id
],
relationName: "organization"
}),
product: one(products, {
fields: [
subscriptions.productId
],
references: [
products.id
],
relationName: "product"
}),
merchantSubscription: one(merchantSubscriptions, {
fields: [
subscriptions.merchantSubscriptionId
],
references: [
merchantSubscriptions.id
],
relationName: "merchantSubscription"
})
}));
}
__name(getSubscriptionRelationsSchema, "getSubscriptionRelationsSchema");
// src/lib/mysql/schemas/org/organizations.ts
function getOrganizationsSchema(mysqlTable) {
return mysqlTable("Organization", {
id: varchar15("id", {
length: 255
}).notNull().primaryKey(),
name: varchar15("name", {
length: 255
}),
fields: json10("fields").$type().default({}),
image: varchar15("image", {
length: 255
}),
createdAt: timestamp15("createdAt", {
mode: "date",
fsp: 3
}).default(sql13`CURRENT_TIMESTAMP(3)`)
}, (organization) => ({
createdAtIdx: index15("created_at_idx").on(organization.createdAt)
}));
}
__name(getOrganizationsSchema, "getOrganizationsSchema");
function getOrganizationsRelationsSchema(mysqlTable) {
const organizations = getOrganizationsSchema(mysqlTable);
const purchases = getPurchaseSchema(mysqlTable);
const subscriptions = getSubscriptionSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
return relations15(organizations, ({ many }) => ({
purchases: many(purchases, {
relationName: "organization"
}),
subscriptions: many(subscriptions, {
relationName: "organization"
}),
members: many(organizationMemberships, {
relationName: "organization"
})
}));
}
__name(getOrganizationsRelationsSchema, "getOrganizationsRelationsSchema");
// src/lib/mysql/schemas/org/organization-membership-roles.ts
function getOrganizationMembershipRolesSchema(mysqlTable) {
return mysqlTable("OrganizationMembershipRole", {
organizationMembershipId: varchar16("organizationMembershipId", {
length: 255
}).notNull(),
roleId: varchar16("roleId", {
length: 255
}).notNull(),
active: boolean3("active").notNull().default(true),
organizationId: varchar16("organizationId", {
length: 191
}),
createdAt: timestamp16("createdAt", {
mode: "date",
fsp: 3
}).defaultNow(),
updatedAt: timestamp16("updatedAt", {
mode: "date",
fsp: 3
}).defaultNow(),
deletedAt: timestamp16("deletedAt", {
mode: "date",
fsp: 3
})
}, (ur) => ({
pk: primaryKey10({
columns: [
ur.organizationMembershipId,
ur.roleId
],
name: "pk"
}),
orgMemberIdIdx: index16("orgMemberId_idx").on(ur.organizationMembershipId),
roleIdIdx: index16("roleId_idx").on(ur.roleId),
organizationIdIdx: index16("organizationId_idx").on(ur.organizationId)
}));
}
__name(getOrganizationMembershipRolesSchema, "getOrganizationMembershipRolesSchema");
function getOrganizationMembershipRolesRelationsSchema(mysqlTable) {
const organizationMembershipRoles = getOrganizationMembershipRolesSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
const roles = getRolesSchema(mysqlTable);
const organizations = getOrganizationsSchema(mysqlTable);
return relations16(organizationMembershipRoles, ({ one }) => ({
organizationMembership: one(organizationMemberships, {
fields: [
organizationMembershipRoles.organizationMembershipId
],
references: [
organizationMemberships.id
],
relationName: "organizationMembership"
}),
role: one(roles, {
fields: [
organizationMembershipRoles.roleId
],
references: [
roles.id
],
relationName: "role"
}),
organization: one(organizations, {
fields: [
organizationMembershipRoles.organizationId
],
references: [
organizations.id
],
relationName: "organization"
})
}));
}
__name(getOrganizationMembershipRolesRelationsSchema, "getOrganizationMembershipRolesRelationsSchema");
// src/lib/mysql/schemas/org/organization-memberships.ts
function getOrganizationMembershipsSchema(mysqlTable) {
return mysqlTable("OrganizationMembership", {
id: varchar17("id", {
length: 255
}).notNull().primaryKey(),
organizationId: varchar17("organizationId", {
length: 191
}),
role: varchar17("role", {
length: 191
}).notNull().default("user"),
invitedById: varchar17("invitedById", {
length: 255
}).notNull(),
userId: varchar17("userId", {
length: 255
}).notNull(),
fields: json11("fields").$type().default({}),
createdAt: timestamp17("createdAt", {
mode: "date",
fsp: 3
}).default(sql14`CURRENT_TIMESTAMP(3)`)
}, (organizationMembership) => ({
roleIdx: index17("role_idx").on(organizationMembership.role),
createdAtIdx: index17("created_at_idx").on(organizationMembership.createdAt),
organizationIdIdx: index17("organizationId_idx").on(organizationMembership.organizationId)
}));
}
__name(getOrganizationMembershipsSchema, "getOrganizationMembershipsSchema");
function getOrganizationMembershipsRelationsSchema(mysqlTable) {
const users = getUsersSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
const purchases = getPurchaseSchema(mysqlTable);
const organizations = getOrganizationsSchema(mysqlTable);
const organizationMembershipRoles = getOrganizationMembershipRolesSchema(mysqlTable);
return relations17(organizationMemberships, ({ one, many }) => ({
user: one(users, {
fields: [
organizationMemberships.userId
],
references: [
users.id
],
relationName: "user"
}),
invitedBy: one(users, {
fields: [
organizationMemberships.invitedById
],
references: [
users.id
],
relationName: "invitedBy"
}),
purchases: many(purchases),
organization: one(organizations, {
fields: [
organizationMemberships.organizationId
],
references: [
organizations.id
],
relationName: "organization"
}),
organizationMembershipRoles: many(organizationMembershipRoles, {
relationName: "organizationMembership"
})
}));
}
__name(getOrganizationMembershipsRelationsSchema, "getOrganizationMembershipsRelationsSchema");
// src/lib/mysql/schemas/commerce/coupon.ts
import { relations as relations18, sql as sql15 } from "drizzle-orm";
import { boolean as boolean4, decimal as decimal2, index as index18, int as int6, json as json12, primaryKey as primaryKey11, timestamp as timestamp18, unique as unique3, varchar as varchar18 } from "drizzle-orm/mysql-core";
function getCouponSchema(mysqlTable) {
return mysqlTable("Coupon", {
id: varchar18("id", {
length: 191
}).notNull(),
organizationId: varchar18("organizationId", {
length: 191
}),
code: varchar18("code", {
length: 191
}),
createdAt: timestamp18("createdAt", {
mode: "date",
fsp: 3
}).default(sql15`CURRENT_TIMESTAMP(3)`).notNull(),
expires: timestamp18("expires", {
mode: "date",
fsp: 3
}),
fields: json12("fields").$type().default({}),
maxUses: int6("maxUses").default(-1).notNull(),
default: boolean4("default").default(false).notNull(),
merchantCouponId: varchar18("merchantCouponId", {
length: 191
}),
status: int6("status").default(0).notNull(),
usedCount: int6("usedCount").default(0).notNull(),
percentageDiscount: decimal2("percentageDiscount", {
precision: 3,
scale: 2
}).notNull(),
restrictedToProductId: varchar18("restrictedToProductId", {
length: 191
})
}, (table) => {
return {
couponIdCodeIndex: index18("Coupon_id_code_index").on(table.id, table.code),
couponId: primaryKey11({
columns: [
table.id
],
name: "Coupon_id"
}),
couponCodeKey: unique3("Coupon_code_key").on(table.code),
organizationIdIdx: index18("organizationId_idx").on(table.organizationId)
};
});
}
__name(getCouponSchema, "getCouponSchema");
function getCouponRelationsSchema(mysqlTable) {
const purchase = getPurchaseSchema(mysqlTable);
const coupon = getCouponSchema(mysqlTable);
const merchantCoupon = getMerchantCouponSchema(mysqlTable);
return relations18(coupon, ({ many, one }) => ({
redeemedBulkCouponPurchases: many(purchase, {
relationName: "redeemedBulkCoupon"
}),
merchantCoupon: one(merchantCoupon, {
fields: [
coupon.merchantCouponId
],
references: [
merchantCoupon.id
],
relationName: "merchantCoupon"
}),
product: one(getProductSchema(mysqlTable), {
fields: [
coupon.restrictedToProductId
],
references: [
getProductSchema(mysqlTable).id
],
relationName: "product"
}),
bulkPurchases: many(purchase, {
relationName: "bulkCoupon"
})
}));
}
__name(getCouponRelationsSchema, "getCouponRelationsSchema");
// src/lib/mysql/schemas/commerce/purchase.ts
function getPurchaseSchema(mysqlTable) {
return mysqlTable("Purchase", {
id: varchar19("id", {
length: 191
}).notNull(),
userId: varchar19("userId", {
length: 191
}),
purchasedByorganizationMembershipId: varchar19("organizationMembershipId", {
length: 191
}),
organizationId: varchar19("organizationId", {
length: 191
}),
createdAt: timestamp19("createdAt", {
mode: "date",
fsp: 3
}).default(sql16`CURRENT_TIMESTAMP(3)`).notNull(),
totalAmount: decimal3("totalAmount", {
precision: 65,
scale: 30
}).notNull(),
ipAddress: varchar19("ip_address", {
length: 191
}),
city: varchar19("city", {
length: 191
}),
state: varchar19("state", {
length: 191
}),
country: varchar19("country", {
length: 191
}),
couponId: varchar19("couponId", {
length: 191
}),
productId: varchar19("productId", {
length: 191
}).notNull(),
merchantChargeId: varchar19("merchantChargeId", {
length: 191
}),
upgradedFromId: varchar19("upgradedFromId", {
length: 191
}),
status: varchar19("status", {
length: 191
}).default("Valid").notNull(),
bulkCouponId: varchar19("bulkCouponId", {
length: 191
}),
merchantSessionId: varchar19("merchantSessionId", {
length: 191
}),
redeemedBulkCouponId: varchar19("redeemedBulkCouponId", {
length: 191
}),
fields: json13("fields").$type().default({})
}, (table) => {
return {
purchaseId: primaryKey12({
columns: [
table.id
],
name: "Purchase_id"
}),
merchantChargeIdIdx: index19("idx_Purchase_on_merchantChargeId").on(table.merchantChargeId),
purchaseUpgradedFromIdKey: unique4("Purchase_upgradedFromId_key").on(table.upgradedFromId),
organizationIdIdx: index19("organizationId_idx").on(table.organizationId),
organizationMembershipIdIdx: index19("organizationMembershipId_idx").on(table.purchasedByorganizationMembershipId)
};
});
}
__name(getPurchaseSchema, "getPurchaseSchema");
function getPurchaseRelationsSchema(mysqlTable) {
const purchases = getPurchaseSchema(mysqlTable);
const users = getUsersSchema(mysqlTable);
const products = getProductSchema(mysqlTable);
const merchantCharges = getMerchantChargeSchema(mysqlTable);
const merchantSessions = getMerchantSessionSchema(mysqlTable);
const coupons = getCouponSchema(mysqlTable);
const organizations = getOrganizationsSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
return relations19(purchases, ({ many, one }) => ({
redeemedBulkCoupon: one(coupons, {
fields: [
purchases.redeemedBulkCouponId
],
references: [
coupons.id
],
relationName: "redeemedBulkCoupon"
}),
user: one(users, {
fields: [
purchases.userId
],
references: [
users.id
],
relationName: "user"
}),
organization: one(organizations, {
fields: [
purchases.organizationId
],
references: [
organizations.id
],
relationName: "organization"
}),
purchasedBy: one(organizationMemberships, {
fields: [
purchases.purchasedByorganizationMembershipId
],
references: [
organizationMemberships.id
],
relationName: "organizationMembership"
}),
product: one(products, {
fields: [
purchases.productId
],
references: [
products.id
],
relationName: "product"
}),
bulkCoupon: one(coupons, {
fields: [
purchases.bulkCouponId
],
references: [
coupons.id
],
relationName: "bulkCoupon"
}),
merchantCharge: one(merchantCharges, {
fields: [
purchases.merchantChargeId
],
references: [
merchantCharges.id
],
relationName: "merchantCharge"
}),
merchantSession: one(merchantSessions, {
fields: [
purchases.merchantSessionId
],
references: [
merchantSessions.id
],
relationName: "merchantSession"
})
}));
}
__name(getPurchaseRelationsSchema, "getPurchaseRelationsSchema");
// src/lib/mysql/schemas/communication/comment.ts
import { relations as relations20, sql as sql17 } from "drizzle-orm";
import { index as index20, json as json14, primaryKey as primaryKey13, text as text2, timestamp as timestamp20, varchar as varchar20 } from "drizzle-orm/mysql-core";
function getCommentsSchema(mysqlTable) {
return mysqlTable("Comment", {
id: varchar20("id", {
length: 191
}).notNull(),
userId: varchar20("userId", {
length: 255
}).notNull(),
organizationMembershipId: varchar20("organizationMembershipId", {
length: 255
}),
context: json14("context").$type().default({}),
text: text2("text").notNull(),
createdAt: timestamp20("createdAt", {
mode: "date",
fsp: 3
}).default(sql17`CURRENT_TIMESTAMP(3)`),
updatedAt: timestamp20("updatedAt", {
mode: "date",
fsp: 3
}).default(sql17`CURRENT_TIMESTAMP(3)`),
deletedAt: timestamp20("deletedAt", {
mode: "date",
fsp: 3
})
}, (crr) => ({
pk: primaryKey13({
columns: [
crr.id
]
}),
crrUserIdIdKey: index20("crr_userIdId_idx").on(crr.userId),
organizationMembershipIdIdx: index20("organizationMembershipId_idx").on(crr.organizationMembershipId)
}));
}
__name(getCommentsSchema, "getCommentsSchema");
function getCommentRelationsSchema(mysqlTable) {
const comment = getCommentsSchema(mysqlTable);
const user = getUsersSchema(mysqlTable);
const organizationMemberships = getOrganizationMembershipsSchema(mysqlTable);
return relations20(comment, ({ one }) => ({
user: one(user, {
fields: [
comment.userId
],
references: [
user.id
],
relationName: "user"
}),
organizationMembership: one(organizationMemberships, {
fields: [
comment.organizationMembershipId
],
references: [