a tool for shared writing and social publishing
at main 484 lines 25 kB view raw
1import { pgTable, pgEnum, text, jsonb, foreignKey, timestamp, boolean, uuid, index, bigint, uniqueIndex, unique, smallint, integer, primaryKey } from "drizzle-orm/pg-core" 2 import { sql } from "drizzle-orm" 3 4export const aal_level = pgEnum("aal_level", ['aal1', 'aal2', 'aal3']) 5export const code_challenge_method = pgEnum("code_challenge_method", ['s256', 'plain']) 6export const factor_status = pgEnum("factor_status", ['unverified', 'verified']) 7export const factor_type = pgEnum("factor_type", ['totp', 'webauthn', 'phone']) 8export const oauth_authorization_status = pgEnum("oauth_authorization_status", ['pending', 'approved', 'denied', 'expired']) 9export const oauth_client_type = pgEnum("oauth_client_type", ['public', 'confidential']) 10export const oauth_registration_type = pgEnum("oauth_registration_type", ['dynamic', 'manual']) 11export const oauth_response_type = pgEnum("oauth_response_type", ['code']) 12export const one_time_token_type = pgEnum("one_time_token_type", ['confirmation_token', 'reauthentication_token', 'recovery_token', 'email_change_token_new', 'email_change_token_current', 'phone_change_token']) 13export const key_status = pgEnum("key_status", ['default', 'valid', 'invalid', 'expired']) 14export const key_type = pgEnum("key_type", ['aead-ietf', 'aead-det', 'hmacsha512', 'hmacsha256', 'auth', 'shorthash', 'generichash', 'kdf', 'secretbox', 'secretstream', 'stream_xchacha20']) 15export const rsvp_status = pgEnum("rsvp_status", ['GOING', 'NOT_GOING', 'MAYBE']) 16export const action = pgEnum("action", ['INSERT', 'UPDATE', 'DELETE', 'TRUNCATE', 'ERROR']) 17export const equality_op = pgEnum("equality_op", ['eq', 'neq', 'lt', 'lte', 'gt', 'gte', 'in']) 18export const buckettype = pgEnum("buckettype", ['STANDARD', 'ANALYTICS', 'VECTOR']) 19 20 21export const oauth_state_store = pgTable("oauth_state_store", { 22 key: text("key").primaryKey().notNull(), 23 state: jsonb("state").notNull(), 24}); 25 26export const notifications = pgTable("notifications", { 27 recipient: text("recipient").notNull().references(() => identities.atp_did, { onDelete: "cascade", onUpdate: "cascade" } ), 28 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 29 read: boolean("read").default(false).notNull(), 30 data: jsonb("data").notNull(), 31 id: uuid("id").primaryKey().notNull(), 32}); 33 34export const publications = pgTable("publications", { 35 uri: text("uri").primaryKey().notNull(), 36 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 37 name: text("name").notNull(), 38 identity_did: text("identity_did").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 39 record: jsonb("record"), 40}, 41(table) => { 42 return { 43 identity_did_idx: index("publications_identity_did_idx").on(table.identity_did), 44 } 45}); 46 47export const comments_on_documents = pgTable("comments_on_documents", { 48 uri: text("uri").primaryKey().notNull(), 49 record: jsonb("record").notNull(), 50 document: text("document").references(() => documents.uri, { onDelete: "cascade", onUpdate: "cascade" } ), 51 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 52 profile: text("profile").references(() => bsky_profiles.did, { onDelete: "set null", onUpdate: "cascade" } ), 53}, 54(table) => { 55 return { 56 document_idx: index("comments_on_documents_document_idx").on(table.document), 57 } 58}); 59 60export const entities = pgTable("entities", { 61 id: uuid("id").primaryKey().notNull(), 62 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 63 set: uuid("set").notNull().references(() => entity_sets.id, { onDelete: "cascade", onUpdate: "cascade" } ), 64}, 65(table) => { 66 return { 67 set_idx: index("entities_set_idx").on(table.set), 68 } 69}); 70 71export const facts = pgTable("facts", { 72 id: uuid("id").primaryKey().notNull(), 73 entity: uuid("entity").notNull().references(() => entities.id, { onDelete: "cascade", onUpdate: "restrict" } ), 74 attribute: text("attribute").notNull(), 75 data: jsonb("data").notNull(), 76 created_at: timestamp("created_at", { mode: 'string' }).defaultNow().notNull(), 77 updated_at: timestamp("updated_at", { mode: 'string' }), 78 // You can use { mode: "bigint" } if numbers are exceeding js number limitations 79 version: bigint("version", { mode: "number" }).default(0).notNull(), 80}, 81(table) => { 82 return { 83 entity_idx: index("facts_entity_idx").on(table.entity), 84 } 85}); 86 87export const replicache_clients = pgTable("replicache_clients", { 88 client_id: text("client_id").primaryKey().notNull(), 89 client_group: text("client_group").notNull(), 90 // You can use { mode: "bigint" } if numbers are exceeding js number limitations 91 last_mutation: bigint("last_mutation", { mode: "number" }).notNull(), 92}, 93(table) => { 94 return { 95 client_group_idx: index("replicache_clients_client_group_idx").on(table.client_group), 96 } 97}); 98 99export const email_auth_tokens = pgTable("email_auth_tokens", { 100 id: uuid("id").defaultRandom().primaryKey().notNull(), 101 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 102 confirmed: boolean("confirmed").default(false).notNull(), 103 email: text("email"), 104 confirmation_code: text("confirmation_code").notNull(), 105 identity: uuid("identity").references(() => identities.id, { onDelete: "cascade", onUpdate: "cascade" } ), 106}); 107 108export const bsky_posts = pgTable("bsky_posts", { 109 uri: text("uri").primaryKey().notNull(), 110 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 111 post_view: jsonb("post_view").notNull(), 112 cid: text("cid").notNull(), 113}); 114 115export const recommends_on_documents = pgTable("recommends_on_documents", { 116 uri: text("uri").primaryKey().notNull(), 117 record: jsonb("record").notNull(), 118 document: text("document").notNull().references(() => documents.uri, { onDelete: "cascade", onUpdate: "cascade" } ), 119 recommender_did: text("recommender_did").notNull().references(() => identities.atp_did, { onDelete: "cascade", onUpdate: "cascade" } ), 120 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 121}, 122(table) => { 123 return { 124 document_idx: index("recommends_on_documents_document_idx").on(table.document), 125 recommender_did_idx: index("recommends_on_documents_recommender_did_idx").on(table.recommender_did), 126 recommender_document_idx: uniqueIndex("recommends_on_documents_recommender_document_idx").on(table.document, table.recommender_did), 127 } 128}); 129 130export const bsky_profiles = pgTable("bsky_profiles", { 131 did: text("did").primaryKey().notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 132 record: jsonb("record").notNull(), 133 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 134 handle: text("handle"), 135}); 136 137export const entity_sets = pgTable("entity_sets", { 138 id: uuid("id").defaultRandom().primaryKey().notNull(), 139 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 140}); 141 142export const poll_votes_on_entity = pgTable("poll_votes_on_entity", { 143 id: uuid("id").defaultRandom().primaryKey().notNull(), 144 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 145 poll_entity: uuid("poll_entity").notNull().references(() => entities.id, { onDelete: "cascade", onUpdate: "cascade" } ), 146 option_entity: uuid("option_entity").notNull().references(() => entities.id, { onDelete: "cascade", onUpdate: "cascade" } ), 147 voter_token: uuid("voter_token").notNull(), 148}); 149 150export const permission_tokens = pgTable("permission_tokens", { 151 id: uuid("id").defaultRandom().primaryKey().notNull(), 152 root_entity: uuid("root_entity").notNull().references(() => entities.id, { onDelete: "cascade", onUpdate: "cascade" } ), 153 blocked_by_admin: boolean("blocked_by_admin"), 154}); 155 156export const user_subscriptions = pgTable("user_subscriptions", { 157 identity_id: uuid("identity_id").primaryKey().notNull().references(() => identities.id, { onDelete: "cascade" } ), 158 stripe_customer_id: text("stripe_customer_id").notNull(), 159 stripe_subscription_id: text("stripe_subscription_id"), 160 plan: text("plan"), 161 status: text("status"), 162 current_period_end: timestamp("current_period_end", { withTimezone: true, mode: 'string' }), 163 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 164 updated_at: timestamp("updated_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 165}, 166(table) => { 167 return { 168 stripe_customer_id_key: uniqueIndex("user_subscriptions_stripe_customer_id_key").on(table.stripe_customer_id), 169 stripe_subscription_id_key: uniqueIndex("user_subscriptions_stripe_subscription_id_key").on(table.stripe_subscription_id), 170 } 171}); 172 173export const identities = pgTable("identities", { 174 id: uuid("id").defaultRandom().primaryKey().notNull(), 175 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 176 home_page: uuid("home_page").default(sql`create_identity_homepage()`).notNull().references(() => permission_tokens.id, { onDelete: "cascade" } ), 177 email: text("email"), 178 atp_did: text("atp_did"), 179 interface_state: jsonb("interface_state"), 180 metadata: jsonb("metadata"), 181}, 182(table) => { 183 return { 184 identities_email_key: unique("identities_email_key").on(table.email), 185 identities_atp_did_key: unique("identities_atp_did_key").on(table.atp_did), 186 } 187}); 188 189export const phone_number_auth_tokens = pgTable("phone_number_auth_tokens", { 190 id: uuid("id").defaultRandom().primaryKey().notNull(), 191 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 192 confirmed: boolean("confirmed").default(false).notNull(), 193 confirmation_code: text("confirmation_code").notNull(), 194 phone_number: text("phone_number").notNull(), 195 country_code: text("country_code").notNull(), 196}); 197 198export const phone_rsvps_to_entity = pgTable("phone_rsvps_to_entity", { 199 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 200 phone_number: text("phone_number").notNull(), 201 country_code: text("country_code").notNull(), 202 status: rsvp_status("status").notNull(), 203 id: uuid("id").defaultRandom().primaryKey().notNull(), 204 entity: uuid("entity").notNull().references(() => entities.id, { onDelete: "cascade", onUpdate: "cascade" } ), 205 name: text("name").default('').notNull(), 206 plus_ones: smallint("plus_ones").default(0).notNull(), 207}, 208(table) => { 209 return { 210 unique_phone_number_entities: uniqueIndex("unique_phone_number_entities").on(table.phone_number, table.entity), 211 } 212}); 213 214export const site_standard_publications = pgTable("site_standard_publications", { 215 uri: text("uri").primaryKey().notNull(), 216 data: jsonb("data").notNull(), 217 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 218 identity_did: text("identity_did").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 219}); 220 221export const custom_domain_routes = pgTable("custom_domain_routes", { 222 id: uuid("id").defaultRandom().primaryKey().notNull(), 223 domain: text("domain").notNull().references(() => custom_domains.domain), 224 route: text("route").notNull(), 225 edit_permission_token: uuid("edit_permission_token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 226 view_permission_token: uuid("view_permission_token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 227 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 228}, 229(table) => { 230 return { 231 edit_permission_token_idx: index("custom_domain_routes_edit_permission_token_idx").on(table.edit_permission_token), 232 custom_domain_routes_domain_route_key: unique("custom_domain_routes_domain_route_key").on(table.domain, table.route), 233 } 234}); 235 236export const site_standard_documents = pgTable("site_standard_documents", { 237 uri: text("uri").primaryKey().notNull(), 238 data: jsonb("data").notNull(), 239 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 240 identity_did: text("identity_did").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 241}); 242 243export const custom_domains = pgTable("custom_domains", { 244 domain: text("domain").primaryKey().notNull(), 245 identity: text("identity").default('').references(() => identities.email, { onDelete: "cascade", onUpdate: "cascade" } ), 246 confirmed: boolean("confirmed").notNull(), 247 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 248 identity_id: uuid("identity_id").references(() => identities.id, { onDelete: "cascade" } ), 249}); 250 251export const email_subscriptions_to_entity = pgTable("email_subscriptions_to_entity", { 252 id: uuid("id").defaultRandom().primaryKey().notNull(), 253 entity: uuid("entity").notNull().references(() => entities.id, { onDelete: "cascade" } ), 254 email: text("email").notNull(), 255 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 256 token: uuid("token").notNull().references(() => permission_tokens.id, { onDelete: "cascade" } ), 257 confirmed: boolean("confirmed").default(false).notNull(), 258 confirmation_code: text("confirmation_code").notNull(), 259}); 260 261export const atp_poll_votes = pgTable("atp_poll_votes", { 262 uri: text("uri").primaryKey().notNull(), 263 record: jsonb("record").notNull(), 264 voter_did: text("voter_did").notNull(), 265 poll_uri: text("poll_uri").notNull().references(() => atp_poll_records.uri, { onDelete: "cascade", onUpdate: "cascade" } ), 266 poll_cid: text("poll_cid").notNull(), 267 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 268}, 269(table) => { 270 return { 271 poll_uri_idx: index("atp_poll_votes_poll_uri_idx").on(table.poll_uri), 272 voter_did_idx: index("atp_poll_votes_voter_did_idx").on(table.voter_did), 273 } 274}); 275 276export const documents = pgTable("documents", { 277 uri: text("uri").primaryKey().notNull(), 278 data: jsonb("data").notNull(), 279 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 280 sort_date: timestamp("sort_date", { withTimezone: true, mode: 'string' }), 281 bsky_like_count: integer("bsky_like_count").default(0).notNull(), 282 recommend_count: integer("recommend_count").default(0).notNull(), 283 indexed: boolean("indexed").default(false).notNull(), 284}, 285(table) => { 286 return { 287 sort_date_idx: index("documents_sort_date_idx").on(table.uri, table.sort_date), 288 indexed_at_idx: index("documents_indexed_at_idx").on(table.indexed_at), 289 idx_documents_ranking: index("idx_documents_ranking").on(table.uri, table.sort_date, table.bsky_like_count, table.recommend_count), 290 } 291}); 292 293export const atp_poll_records = pgTable("atp_poll_records", { 294 uri: text("uri").primaryKey().notNull(), 295 cid: text("cid").notNull(), 296 record: jsonb("record").notNull(), 297 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 298}); 299 300export const oauth_session_store = pgTable("oauth_session_store", { 301 key: text("key").primaryKey().notNull(), 302 session: jsonb("session").notNull(), 303}); 304 305export const bsky_follows = pgTable("bsky_follows", { 306 identity: text("identity").default('').notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 307 follows: text("follows").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 308}, 309(table) => { 310 return { 311 bsky_follows_pkey: primaryKey({ columns: [table.identity, table.follows], name: "bsky_follows_pkey"}), 312 } 313}); 314 315export const subscribers_to_publications = pgTable("subscribers_to_publications", { 316 identity: text("identity").notNull().references(() => identities.email, { onUpdate: "cascade" } ), 317 publication: text("publication").notNull().references(() => publications.uri), 318 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 319}, 320(table) => { 321 return { 322 subscribers_to_publications_pkey: primaryKey({ columns: [table.identity, table.publication], name: "subscribers_to_publications_pkey"}), 323 } 324}); 325 326export const site_standard_documents_in_publications = pgTable("site_standard_documents_in_publications", { 327 publication: text("publication").notNull().references(() => site_standard_publications.uri, { onDelete: "cascade" } ), 328 document: text("document").notNull().references(() => site_standard_documents.uri, { onDelete: "cascade" } ), 329 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 330}, 331(table) => { 332 return { 333 site_standard_documents_in_publications_pkey: primaryKey({ columns: [table.publication, table.document], name: "site_standard_documents_in_publications_pkey"}), 334 } 335}); 336 337export const documents_in_publications = pgTable("documents_in_publications", { 338 publication: text("publication").notNull().references(() => publications.uri, { onDelete: "cascade" } ), 339 document: text("document").notNull().references(() => documents.uri, { onDelete: "cascade" } ), 340 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 341}, 342(table) => { 343 return { 344 publication_idx: index("documents_in_publications_publication_idx").on(table.publication), 345 document_idx: index("documents_in_publications_document_idx").on(table.document), 346 documents_in_publications_pkey: primaryKey({ columns: [table.publication, table.document], name: "documents_in_publications_pkey"}), 347 } 348}); 349 350export const document_mentions_in_bsky = pgTable("document_mentions_in_bsky", { 351 uri: text("uri").notNull().references(() => bsky_posts.uri, { onDelete: "cascade" } ), 352 link: text("link").notNull(), 353 document: text("document").notNull().references(() => documents.uri, { onDelete: "cascade" } ), 354 indexed_at: timestamp("indexed_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 355}, 356(table) => { 357 return { 358 document_idx: index("document_mentions_in_bsky_document_idx").on(table.document), 359 document_mentions_in_bsky_pkey: primaryKey({ columns: [table.uri, table.document], name: "document_mentions_in_bsky_pkey"}), 360 } 361}); 362 363export const permission_token_on_homepage = pgTable("permission_token_on_homepage", { 364 token: uuid("token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 365 identity: uuid("identity").notNull().references(() => identities.id, { onDelete: "cascade" } ), 366 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 367 archived: boolean("archived"), 368}, 369(table) => { 370 return { 371 permission_token_creator_pkey: primaryKey({ columns: [table.token, table.identity], name: "permission_token_creator_pkey"}), 372 } 373}); 374 375export const publication_domains = pgTable("publication_domains", { 376 publication: text("publication").notNull().references(() => publications.uri, { onDelete: "cascade" } ), 377 domain: text("domain").notNull().references(() => custom_domains.domain, { onDelete: "cascade" } ), 378 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 379 identity: text("identity").notNull().references(() => identities.atp_did, { onDelete: "cascade", onUpdate: "cascade" } ), 380}, 381(table) => { 382 return { 383 publication_idx: index("publication_domains_publication_idx").on(table.publication), 384 publication_domains_pkey: primaryKey({ columns: [table.publication, table.domain], name: "publication_domains_pkey"}), 385 } 386}); 387 388export const publication_subscriptions = pgTable("publication_subscriptions", { 389 publication: text("publication").notNull().references(() => publications.uri, { onDelete: "cascade" } ), 390 identity: text("identity").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 391 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 392 record: jsonb("record").notNull(), 393 uri: text("uri").notNull(), 394}, 395(table) => { 396 return { 397 publication_idx: index("publication_subscriptions_publication_idx").on(table.publication), 398 publication_subscriptions_pkey: primaryKey({ columns: [table.publication, table.identity], name: "publication_subscriptions_pkey"}), 399 publication_subscriptions_uri_key: unique("publication_subscriptions_uri_key").on(table.uri), 400 } 401}); 402 403export const site_standard_subscriptions = pgTable("site_standard_subscriptions", { 404 publication: text("publication").notNull().references(() => site_standard_publications.uri, { onDelete: "cascade" } ), 405 identity: text("identity").notNull().references(() => identities.atp_did, { onDelete: "cascade" } ), 406 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 407 record: jsonb("record").notNull(), 408 uri: text("uri").notNull(), 409}, 410(table) => { 411 return { 412 site_standard_subscriptions_pkey: primaryKey({ columns: [table.publication, table.identity], name: "site_standard_subscriptions_pkey"}), 413 site_standard_subscriptions_uri_key: unique("site_standard_subscriptions_uri_key").on(table.uri), 414 } 415}); 416 417export const user_entitlements = pgTable("user_entitlements", { 418 identity_id: uuid("identity_id").notNull().references(() => identities.id, { onDelete: "cascade" } ), 419 entitlement_key: text("entitlement_key").notNull(), 420 granted_at: timestamp("granted_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 421 expires_at: timestamp("expires_at", { withTimezone: true, mode: 'string' }), 422 source: text("source"), 423 metadata: jsonb("metadata"), 424}, 425(table) => { 426 return { 427 identity_id_idx: index("user_entitlements_identity_id_idx").on(table.identity_id), 428 expires_at_idx: index("user_entitlements_expires_at_idx").on(table.expires_at), 429 user_entitlements_pkey: primaryKey({ columns: [table.identity_id, table.entitlement_key], name: "user_entitlements_pkey"}), 430 } 431}); 432 433export const permission_token_rights = pgTable("permission_token_rights", { 434 token: uuid("token").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 435 entity_set: uuid("entity_set").notNull().references(() => entity_sets.id, { onDelete: "cascade", onUpdate: "cascade" } ), 436 read: boolean("read").default(false).notNull(), 437 write: boolean("write").default(false).notNull(), 438 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 439 create_token: boolean("create_token").default(false).notNull(), 440 change_entity_set: boolean("change_entity_set").default(false).notNull(), 441}, 442(table) => { 443 return { 444 token_idx: index("permission_token_rights_token_idx").on(table.token), 445 entity_set_idx: index("permission_token_rights_entity_set_idx").on(table.entity_set), 446 permission_token_rights_pkey: primaryKey({ columns: [table.token, table.entity_set], name: "permission_token_rights_pkey"}), 447 } 448}); 449 450export const leaflets_to_documents = pgTable("leaflets_to_documents", { 451 leaflet: uuid("leaflet").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 452 document: text("document").notNull().references(() => documents.uri, { onDelete: "cascade", onUpdate: "cascade" } ), 453 created_at: timestamp("created_at", { withTimezone: true, mode: 'string' }).defaultNow().notNull(), 454 title: text("title").default('').notNull(), 455 description: text("description").default('').notNull(), 456 tags: text("tags").default('RRAY[').array(), 457 cover_image: text("cover_image"), 458 preferences: jsonb("preferences"), 459}, 460(table) => { 461 return { 462 leaflets_to_documents_pkey: primaryKey({ columns: [table.leaflet, table.document], name: "leaflets_to_documents_pkey"}), 463 } 464}); 465 466export const leaflets_in_publications = pgTable("leaflets_in_publications", { 467 publication: text("publication").notNull().references(() => publications.uri, { onDelete: "cascade" } ), 468 doc: text("doc").default('').references(() => documents.uri, { onDelete: "set null" } ), 469 leaflet: uuid("leaflet").notNull().references(() => permission_tokens.id, { onDelete: "cascade", onUpdate: "cascade" } ), 470 description: text("description").default('').notNull(), 471 title: text("title").default('').notNull(), 472 archived: boolean("archived"), 473 tags: text("tags").default('RRAY[').array(), 474 cover_image: text("cover_image"), 475 preferences: jsonb("preferences"), 476}, 477(table) => { 478 return { 479 leaflet_idx: index("leaflets_in_publications_leaflet_idx").on(table.leaflet), 480 publication_idx: index("leaflets_in_publications_publication_idx").on(table.publication), 481 doc_idx: index("leaflets_in_publications_doc_idx").on(table.doc), 482 leaflets_in_publications_pkey: primaryKey({ columns: [table.publication, table.leaflet], name: "leaflets_in_publications_pkey"}), 483 } 484});