@coursebuilder/adapter-drizzle
Version:
Drizzle adapter for Course Builder.
99 lines (97 loc) • 2.7 kB
JavaScript
import {
getOrganizationMembershipsSchema,
getOrganizationsSchema,
getUsersSchema
} from "./chunk-LPJ2P2KJ.js";
import {
__name
} from "./chunk-H736K5TN.js";
// src/lib/mysql/schemas/entitlements/entitlement.ts
import { relations, sql } from "drizzle-orm";
import { index, json, timestamp, varchar } from "drizzle-orm/mysql-core";
function getEntitlementsSchema(mysqlTable) {
return mysqlTable("Entitlement", {
id: varchar("id", {
length: 191
}).notNull().primaryKey(),
entitlementType: varchar("entitlementType", {
length: 255
}).notNull(),
userId: varchar("userId", {
length: 191
}),
organizationId: varchar("organizationId", {
length: 191
}),
organizationMembershipId: varchar("organizationMembershipId", {
length: 191
}),
sourceType: varchar("sourceType", {
length: 255
}).notNull(),
sourceId: varchar("sourceId", {
length: 191
}).notNull(),
metadata: json("metadata").$type().default({}),
expiresAt: timestamp("expiresAt", {
mode: "date",
fsp: 3
}),
createdAt: timestamp("createdAt", {
mode: "date",
fsp: 3
}).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
updatedAt: timestamp("updatedAt", {
mode: "date",
fsp: 3
}).default(sql`CURRENT_TIMESTAMP(3)`).notNull(),
deletedAt: timestamp("deletedAt", {
mode: "date",
fsp: 3
})
}, (table) => ({
userIdIdx: index("userId_idx").on(table.userId),
orgIdIdx: index("orgId_idx").on(table.organizationId),
sourceIdx: index("source_idx").on(table.sourceType, table.sourceId),
typeIdx: index("type_idx").on(table.entitlementType)
}));
}
__name(getEntitlementsSchema, "getEntitlementsSchema");
function getEntitlementRelationsSchema(mysqlTable) {
const entitlements = getEntitlementsSchema(mysqlTable);
const users = getUsersSchema(mysqlTable);
const orgs = getOrganizationsSchema(mysqlTable);
const memberships = getOrganizationMembershipsSchema(mysqlTable);
return relations(entitlements, ({ one }) => ({
user: one(users, {
fields: [
entitlements.userId
],
references: [
users.id
]
}),
organization: one(orgs, {
fields: [
entitlements.organizationId
],
references: [
orgs.id
]
}),
membership: one(memberships, {
fields: [
entitlements.organizationMembershipId
],
references: [
memberships.id
]
})
}));
}
__name(getEntitlementRelationsSchema, "getEntitlementRelationsSchema");
export {
getEntitlementsSchema,
getEntitlementRelationsSchema
};
//# sourceMappingURL=chunk-253RMSB3.js.map