Skip to content

Instantly share code, notes, and snippets.

@ahmedrowaihi
Created December 24, 2025 10:25
Show Gist options
  • Select an option

  • Save ahmedrowaihi/3caf31611da52bb4262556e899859060 to your computer and use it in GitHub Desktop.

Select an option

Save ahmedrowaihi/3caf31611da52bb4262556e899859060 to your computer and use it in GitHub Desktop.
import {
bigint,
boolean,
customType,
date,
doublePrecision,
index,
integer,
jsonb,
numeric,
pgTable,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/pg-core";
const bytea = customType<{ data: Buffer; driverData: Buffer }>({
dataType() {
return "bytea";
},
});
export const ActiveStorageAttachments = pgTable(
"active_storage_attachments",
{
name: varchar("name", { length: 191 }).notNull(),
record_type: varchar("record_type", { length: 191 }).notNull(),
record_id: bigint({ mode: "number" }).notNull(),
blob_id: bigint({ mode: "number" })
.notNull()
.references(() => ActiveStorageBlobs.id),
created_at: timestamp("created_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_active_storage_attachments_on_blob_id").on(table.blob_id),
uniqueIndex("index_active_storage_attachments_uniqueness").on(
table.record_type,
table.record_id,
table.name,
table.blob_id,
),
],
);
export const ActiveStorageBlobs = pgTable(
"active_storage_blobs",
{
key: varchar("key", { length: 191 }).notNull(),
filename: varchar("filename", { length: 191 }).notNull(),
content_type: varchar("content_type", { length: 191 }),
metadata: text("metadata"),
byte_size: bigint({ mode: "number" }).notNull(),
checksum: varchar("checksum", { length: 191 }),
created_at: timestamp("created_at").notNull(),
service_name: varchar("service_name", { length: 255 }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [uniqueIndex("index_active_storage_blobs_on_key").on(table.key)],
);
export const ActiveStorageVariantRecords = pgTable(
"active_storage_variant_records",
{
blob_id: bigint({ mode: "number" })
.notNull()
.references(() => ActiveStorageBlobs.id),
variation_digest: varchar("variation_digest", { length: 255 }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_active_storage_variant_records_uniqueness").on(
table.blob_id,
table.variation_digest,
),
],
);
export const AdminActionCallInfos = pgTable(
"admin_action_call_infos",
{
controller_name: varchar("controller_name", { length: 255 }).notNull(),
action_name: varchar("action_name", { length: 255 }).notNull(),
call_count: integer("call_count").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex(
"index_admin_action_call_infos_on_controller_name_and_action_name",
).on(table.controller_name, table.action_name),
],
);
export const AffiliateCredits = pgTable(
"affiliate_credits",
{
oauth_application_id: integer("oauth_application_id"),
basis_points: integer("basis_points"),
amount_cents: integer("amount_cents"),
affiliate_user_id: integer("affiliate_user_id"),
seller_id: integer("seller_id"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
purchase_id: integer("purchase_id"),
link_id: integer("link_id"),
affiliate_credit_success_balance_id: integer(
"affiliate_credit_success_balance_id",
),
affiliate_credit_chargeback_balance_id: integer(
"affiliate_credit_chargeback_balance_id",
),
affiliate_credit_refund_balance_id: integer(
"affiliate_credit_refund_balance_id",
),
affiliate_id: integer("affiliate_id"),
fee_cents: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("idx_affiliate_credits_on_affiliate_credit_chargeback_balance_id").on(
table.affiliate_credit_chargeback_balance_id,
),
index("index_affiliate_credits_on_affiliate_credit_refund_balance_id").on(
table.affiliate_credit_refund_balance_id,
),
index("index_affiliate_credits_on_affiliate_credit_success_balance_id").on(
table.affiliate_credit_success_balance_id,
),
index("index_affiliate_credits_on_affiliate_id").on(table.affiliate_id),
index("index_affiliate_credits_on_affiliate_user_id").on(
table.affiliate_user_id,
),
index("index_affiliate_credits_on_link_id").on(table.link_id),
index("index_affiliate_credits_on_oauth_application_id").on(
table.oauth_application_id,
),
index("index_affiliate_credits_on_purchase_id").on(table.purchase_id),
index("index_affiliate_credits_on_seller_id").on(table.seller_id),
],
);
export const AffiliatePartialRefunds = pgTable(
"affiliate_partial_refunds",
{
amount_cents: integer("amount_cents").default(0),
purchase_id: integer("purchase_id").notNull(),
total_credit_cents: integer("total_credit_cents").default(0),
affiliate_user_id: integer("affiliate_user_id"),
seller_id: integer("seller_id"),
affiliate_id: integer("affiliate_id"),
balance_id: integer("balance_id"),
affiliate_credit_id: integer("affiliate_credit_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
fee_cents: bigint({ mode: "number" }).default(0),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_affiliate_partial_refunds_on_affiliate_credit_id").on(
table.affiliate_credit_id,
),
index("index_affiliate_partial_refunds_on_affiliate_id").on(
table.affiliate_id,
),
index("index_affiliate_partial_refunds_on_affiliate_user_id").on(
table.affiliate_user_id,
),
index("index_affiliate_partial_refunds_on_balance_id").on(table.balance_id),
index("index_affiliate_partial_refunds_on_purchase_id").on(
table.purchase_id,
),
index("index_affiliate_partial_refunds_on_seller_id").on(table.seller_id),
],
);
export const AffiliateRequests = pgTable(
"affiliate_requests",
{
seller_id: bigint({ mode: "number" }).notNull(),
name: varchar("name", { length: 100 }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
promotion_text: text("promotion_text").notNull(),
locale: varchar("locale", { length: 255 }).default("en").notNull(),
state: varchar("state", { length: 255 }),
state_transitioned_at: timestamp("state_transitioned_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_affiliate_requests_on_seller_id").on(table.seller_id),
],
);
export const Affiliates = pgTable(
"affiliates",
{
seller_id: integer("seller_id"),
affiliate_user_id: integer("affiliate_user_id"),
affiliate_basis_points: integer("affiliate_basis_points"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
deleted_at: timestamp("deleted_at"),
flags: integer("flags").default(0).notNull(),
destination_url: varchar("destination_url", { length: 2083 }),
type: varchar("type", { length: 255 }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_affiliates_on_affiliate_user_id").on(table.affiliate_user_id),
index("index_affiliates_on_seller_id").on(table.seller_id),
],
);
export const AffiliatesLinks = pgTable(
"affiliates_links",
{
affiliate_id: integer("affiliate_id"),
link_id: integer("link_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
affiliate_basis_points: integer("affiliate_basis_points"),
destination_url: varchar("destination_url", { length: 255 }),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_affiliates_links_on_affiliate_id").on(table.affiliate_id),
index("index_affiliates_links_on_link_id").on(table.link_id),
],
);
export const AssetPreviews = pgTable(
"asset_previews",
{
link_id: bigint({ mode: "number" }),
guid: varchar("guid", { length: 255 }),
oembed: text("oembed"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
deleted_at: timestamp("deleted_at"),
position: integer("position"),
unsplash_url: varchar("unsplash_url", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_asset_previews_on_deleted_at").on(table.deleted_at),
index("index_asset_previews_on_link_id").on(table.link_id),
],
);
export const AudienceMembers = pgTable(
"audience_members",
{
seller_id: bigint({ mode: "number" }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
details: jsonb("details"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
customer: boolean("customer").default(false).notNull(),
follower: boolean("follower").default(false).notNull(),
affiliate: boolean("affiliate").default(false).notNull(),
min_paid_cents: integer("min_paid_cents"),
max_paid_cents: integer("max_paid_cents"),
min_created_at: timestamp("min_created_at"),
max_created_at: timestamp("max_created_at"),
min_purchase_created_at: timestamp("min_purchase_created_at"),
max_purchase_created_at: timestamp("max_purchase_created_at"),
follower_created_at: timestamp("follower_created_at"),
min_affiliate_created_at: timestamp("min_affiliate_created_at"),
max_affiliate_created_at: timestamp("max_affiliate_created_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("idx_audience_on_seller_and_types").on(
table.seller_id,
table.customer,
table.follower,
table.affiliate,
),
uniqueIndex("index_audience_members_on_seller_id_and_email").on(
table.seller_id,
table.email,
),
index("idx_audience_on_seller_and_follower_created_at").on(
table.seller_id,
table.follower_created_at,
),
index("idx_audience_on_seller_and_minmax_affiliate_created_at").on(
table.seller_id,
table.min_affiliate_created_at,
table.max_affiliate_created_at,
),
index("idx_audience_on_seller_and_minmax_created_at").on(
table.seller_id,
table.min_created_at,
table.max_created_at,
),
index("idx_audience_on_seller_and_minmax_paid_cents").on(
table.seller_id,
table.min_paid_cents,
table.max_paid_cents,
),
index("idx_audience_on_seller_and_minmax_purchase_created_at").on(
table.seller_id,
table.min_purchase_created_at,
table.max_purchase_created_at,
),
],
);
export const AustraliaBacktaxEmailInfos = pgTable(
"australia_backtax_email_infos",
{
user_id: bigint({ mode: "number" }),
email_name: varchar("email_name", { length: 255 }),
sent_at: timestamp("sent_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_australia_backtax_email_infos_on_user_id").on(table.user_id),
],
);
export const BacktaxAgreements = pgTable(
"backtax_agreements",
{
user_id: bigint({ mode: "number" }).notNull(),
jurisdiction: varchar("jurisdiction", { length: 255 }),
signature: varchar("signature", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_backtax_agreements_on_user_id").on(table.user_id)],
);
export const BacktaxCollections = pgTable(
"backtax_collections",
{
user_id: bigint({ mode: "number" }).notNull(),
backtax_agreement_id: bigint({ mode: "number" }).notNull(),
amount_cents: integer("amount_cents"),
amount_cents_usd: integer("amount_cents_usd"),
currency: varchar("currency", { length: 255 }),
stripe_transfer_id: varchar("stripe_transfer_id", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_backtax_collections_on_backtax_agreement_id").on(
table.backtax_agreement_id,
),
index("index_backtax_collections_on_user_id").on(table.user_id),
],
);
export const BalanceTransactions = pgTable(
"balance_transactions",
{
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
user_id: integer("user_id"),
merchant_account_id: integer("merchant_account_id"),
balance_id: integer("balance_id"),
purchase_id: integer("purchase_id"),
dispute_id: integer("dispute_id"),
refund_id: integer("refund_id"),
credit_id: integer("credit_id"),
occurred_at: timestamp("occurred_at"),
issued_amount_currency: varchar("issued_amount_currency", { length: 255 }),
issued_amount_gross_cents: integer("issued_amount_gross_cents"),
issued_amount_net_cents: integer("issued_amount_net_cents"),
holding_amount_currency: varchar("holding_amount_currency", {
length: 255,
}),
holding_amount_gross_cents: integer("holding_amount_gross_cents"),
holding_amount_net_cents: integer("holding_amount_net_cents"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_balance_transactions_on_balance_id").on(table.balance_id),
index("index_balance_transactions_on_credit_id").on(table.credit_id),
index("index_balance_transactions_on_dispute_id").on(table.dispute_id),
index("index_balance_transactions_on_merchant_account_id").on(
table.merchant_account_id,
),
index("index_balance_transactions_on_purchase_id").on(table.purchase_id),
index("index_balance_transactions_on_refund_id").on(table.refund_id),
index("index_balance_transactions_on_user_id").on(table.user_id),
],
);
export const Balances = pgTable(
"balances",
{
user_id: integer("user_id"),
date: date("date"),
amount_cents: integer("amount_cents").default(0),
state: varchar("state", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
merchant_account_id: integer("merchant_account_id").default(1),
currency: varchar("currency", { length: 255 }).default("usd"),
holding_currency: varchar("holding_currency", { length: 255 }).default(
"usd",
),
holding_amount_cents: integer("holding_amount_cents").default(0),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_on_user_merchant_account_date").on(
table.user_id,
table.merchant_account_id,
table.date,
),
],
);
export const BankAccounts = pgTable(
"bank_accounts",
{
user_id: integer("user_id"),
bank_number: varchar("bank_number", { length: 255 }),
account_number: bytea("account_number"),
state: varchar("state", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
account_number_last_four: varchar("account_number_last_four", {
length: 255,
}),
account_holder_full_name: varchar("account_holder_full_name", {
length: 255,
}),
deleted_at: timestamp("deleted_at"),
type: varchar("type", { length: 255 }).default("AchAccount"),
branch_code: varchar("branch_code", { length: 255 }),
account_type: varchar("account_type", { length: 255 }),
stripe_bank_account_id: varchar("stripe_bank_account_id", { length: 255 }),
stripe_fingerprint: varchar("stripe_fingerprint", { length: 255 }),
stripe_connect_account_id: varchar("stripe_connect_account_id", {
length: 255,
}),
country: varchar("country", { length: 191 }),
credit_card_id: integer("credit_card_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_ach_accounts_on_user_id").on(table.user_id)],
);
export const Banks = pgTable(
"banks",
{
routing_number: varchar("routing_number", { length: 255 }),
name: varchar("name", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_banks_on_routing_number").on(table.routing_number)],
);
export const BaseVariantIntegrations = pgTable(
"base_variant_integrations",
{
base_variant_id: bigint({ mode: "number" }).notNull(),
integration_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_base_variant_integrations_on_base_variant_id").on(
table.base_variant_id,
),
index("index_base_variant_integrations_on_integration_id").on(
table.integration_id,
),
],
);
export const BaseVariants = pgTable(
"base_variants",
{
variant_category_id: integer("variant_category_id"),
price_difference_cents: integer("price_difference_cents"),
name: varchar("name", { length: 255 }),
max_purchase_count: integer("max_purchase_count"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
type: varchar("type", { length: 255 }).default("Variant"),
link_id: integer("link_id"),
custom_sku: varchar("custom_sku", { length: 255 }),
flags: integer("flags").default(0).notNull(),
description: varchar("description", { length: 255 }),
position_in_category: integer("position_in_category"),
customizable_price: boolean("customizable_price"),
subscription_price_change_effective_date: date(
"subscription_price_change_effective_date",
),
subscription_price_change_message: text(
"subscription_price_change_message",
),
duration_in_minutes: integer("duration_in_minutes"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_base_variants_on_link_id").on(table.link_id),
index("index_variants_on_variant_category_id").on(
table.variant_category_id,
),
],
);
export const BaseVariantsProductFiles = pgTable(
"base_variants_product_files",
{
base_variant_id: integer("base_variant_id"),
product_file_id: integer("product_file_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_base_variants_product_files_on_base_variant_id").on(
table.base_variant_id,
),
index("index_base_variants_product_files_on_product_file_id").on(
table.product_file_id,
),
],
);
export const BaseVariantsPurchases = pgTable(
"base_variants_purchases",
{
purchase_id: integer("purchase_id"),
base_variant_id: integer("base_variant_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchases_variants_on_variant_id").on(table.base_variant_id),
index("index_purchases_variants_on_purchase_id").on(table.purchase_id),
],
);
export const BlockedCustomerObjects = pgTable(
"blocked_customer_objects",
{
seller_id: bigint({ mode: "number" }).notNull(),
object_type: varchar("object_type", { length: 255 }).notNull(),
object_value: varchar("object_value", { length: 255 }).notNull(),
buyer_email: varchar("buyer_email", { length: 255 }),
blocked_at: timestamp("blocked_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_blocked_customer_objects_on_buyer_email").on(
table.buyer_email,
),
uniqueIndex(
"idx_blocked_customer_objects_on_seller_and_object_type_and_value",
).on(table.seller_id, table.object_type, table.object_value),
index("index_blocked_customer_objects_on_seller_id").on(table.seller_id),
],
);
export const BundleProductPurchases = pgTable(
"bundle_product_purchases",
{
bundle_purchase_id: bigint({ mode: "number" }).notNull(),
product_purchase_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_bundle_product_purchases_on_bundle_purchase_id").on(
table.bundle_purchase_id,
),
index("index_bundle_product_purchases_on_product_purchase_id").on(
table.product_purchase_id,
),
],
);
export const BundleProducts = pgTable(
"bundle_products",
{
bundle_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
variant_id: bigint({ mode: "number" }),
quantity: integer("quantity").notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
position: integer("position"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_bundle_products_on_bundle_id").on(table.bundle_id),
index("index_bundle_products_on_product_id").on(table.product_id),
index("index_bundle_products_on_variant_id").on(table.variant_id),
],
);
export const CachedSalesRelatedProductsInfos = pgTable(
"cached_sales_related_products_infos",
{
product_id: bigint({ mode: "number" }).notNull(),
counts: jsonb("counts"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_cached_sales_related_products_infos_on_product_id").on(
table.product_id,
),
],
);
export const CallAvailabilities = pgTable(
"call_availabilities",
{
call_id: bigint({ mode: "number" }).notNull(),
start_time: timestamp("start_time"),
end_time: timestamp("end_time"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_call_availabilities_on_call_id").on(table.call_id)],
);
export const CallLimitationInfos = pgTable(
"call_limitation_infos",
{
call_id: bigint({ mode: "number" }).notNull(),
minimum_notice_in_minutes: integer("minimum_notice_in_minutes"),
maximum_calls_per_day: integer("maximum_calls_per_day"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_call_limitation_infos_on_call_id").on(table.call_id),
],
);
export const Calls = pgTable(
"calls",
{
purchase_id: bigint({ mode: "number" }),
call_url: varchar("call_url", { length: 1024 }),
start_time: timestamp("start_time"),
end_time: timestamp("end_time"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
google_calendar_event_id: varchar("google_calendar_event_id", {
length: 255,
}),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_calls_on_purchase_id").on(table.purchase_id)],
);
export const CartProducts = pgTable(
"cart_products",
{
cart_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
option_id: bigint({ mode: "number" }),
affiliate_id: bigint({ mode: "number" }),
accepted_offer_id: bigint({ mode: "number" }),
price: bigint({ mode: "number" }).notNull(),
quantity: integer("quantity").notNull(),
recurrence: varchar("recurrence", { length: 255 }),
recommended_by: varchar("recommended_by", { length: 255 }),
rent: boolean("rent").default(false).notNull(),
url_parameters: jsonb("url_parameters"),
referrer: text("referrer").notNull(),
recommender_model_name: varchar("recommender_model_name", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
call_start_time: timestamp("call_start_time"),
accepted_offer_details: jsonb("accepted_offer_details"),
pay_in_installments: boolean("pay_in_installments")
.default(false)
.notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex(
"index_cart_products_on_cart_id_and_product_id_and_deleted_at",
).on(table.cart_id, table.product_id, table.deleted_at),
index("index_cart_products_on_cart_id").on(table.cart_id),
index("index_cart_products_on_deleted_at_and_cart_id").on(
table.deleted_at,
table.cart_id,
),
index("index_cart_products_on_product_id").on(table.product_id),
],
);
export const Carts = pgTable(
"carts",
{
user_id: bigint({ mode: "number" }),
order_id: bigint({ mode: "number" }),
return_url: text("return_url"),
discount_codes: jsonb("discount_codes"),
reject_ppp_discount: boolean("reject_ppp_discount")
.default(false)
.notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
email: varchar("email", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
ip_address: varchar("ip_address", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_carts_on_browser_guid").on(table.browser_guid),
index("index_carts_on_created_at").on(table.created_at),
index("index_carts_on_deleted_at_and_updated_at").on(
table.deleted_at,
table.updated_at,
),
index("index_carts_on_email").on(table.email),
index("index_carts_on_order_id").on(table.order_id),
index("index_carts_on_updated_at").on(table.updated_at),
index("index_carts_on_user_id").on(table.user_id),
],
);
export const ChargePurchases = pgTable(
"charge_purchases",
{
charge_id: bigint({ mode: "number" }).notNull(),
purchase_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_charge_purchases_on_charge_id").on(table.charge_id),
index("index_charge_purchases_on_purchase_id").on(table.purchase_id),
],
);
export const Charges = pgTable(
"charges",
{
order_id: bigint({ mode: "number" }).notNull(),
seller_id: bigint({ mode: "number" }).notNull(),
processor: varchar("processor", { length: 255 }),
processor_transaction_id: varchar("processor_transaction_id", {
length: 255,
}),
payment_method_fingerprint: varchar("payment_method_fingerprint", {
length: 255,
}),
credit_card_id: bigint({ mode: "number" }),
merchant_account_id: bigint({ mode: "number" }),
amount_cents: bigint({ mode: "number" }),
gumroad_amount_cents: bigint({ mode: "number" }),
processor_fee_cents: bigint({ mode: "number" }),
processor_fee_currency: varchar("processor_fee_currency", { length: 255 }),
paypal_order_id: varchar("paypal_order_id", { length: 255 }),
stripe_payment_intent_id: varchar("stripe_payment_intent_id", {
length: 255,
}),
stripe_setup_intent_id: varchar("stripe_setup_intent_id", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
disputed_at: timestamp("disputed_at"),
dispute_reversed_at: timestamp("dispute_reversed_at"),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_charges_on_credit_card_id").on(table.credit_card_id),
index("index_charges_on_merchant_account_id").on(table.merchant_account_id),
index("index_charges_on_order_id").on(table.order_id),
uniqueIndex("index_charges_on_paypal_order_id").on(table.paypal_order_id),
uniqueIndex("index_charges_on_processor_transaction_id").on(
table.processor_transaction_id,
),
index("index_charges_on_seller_id").on(table.seller_id),
],
);
export const CollaboratorInvitations = pgTable(
"collaborator_invitations",
{
collaborator_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_collaborator_invitations_on_collaborator_id").on(
table.collaborator_id,
),
],
);
export const Comments = pgTable(
"comments",
{
commentable_id: bigint({ mode: "number" }),
commentable_type: varchar("commentable_type", { length: 255 }),
author_id: bigint({ mode: "number" }),
author_name: varchar("author_name", { length: 255 }),
content: text("content"),
comment_type: varchar("comment_type", { length: 255 }),
json_data: text("json_data"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
purchase_id: bigint({ mode: "number" }),
ancestry: varchar("ancestry", { length: 255 }),
ancestry_depth: integer("ancestry_depth").default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_comments_on_ancestry").on(table.ancestry),
index("index_comments_on_commentable_id_and_commentable_type").on(
table.commentable_id,
table.commentable_type,
),
index("index_comments_on_purchase_id").on(table.purchase_id),
],
);
export const CommissionFiles = pgTable(
"commission_files",
{
url: varchar("url", { length: 1024 }),
commission_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_commission_files_on_commission_id").on(table.commission_id),
],
);
export const Commissions = pgTable(
"commissions",
{
status: varchar("status", { length: 255 }),
deposit_purchase_id: bigint({ mode: "number" }),
completion_purchase_id: bigint({ mode: "number" }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_commissions_on_completion_purchase_id").on(
table.completion_purchase_id,
),
index("index_commissions_on_deposit_purchase_id").on(
table.deposit_purchase_id,
),
],
);
export const Communities = pgTable(
"communities",
{
resource_type: varchar("resource_type", { length: 255 }).notNull(),
resource_id: bigint({ mode: "number" }).notNull(),
seller_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_communities_on_deleted_at").on(table.deleted_at),
uniqueIndex(
"idx_on_resource_type_resource_id_seller_id_deleted__23a67b41cb",
).on(
table.resource_type,
table.resource_id,
table.seller_id,
table.deleted_at,
),
index("index_communities_on_resource").on(
table.resource_type,
table.resource_id,
),
index("index_communities_on_seller_id").on(table.seller_id),
],
);
export const CommunityChatMessages = pgTable(
"community_chat_messages",
{
community_id: bigint({ mode: "number" }).notNull(),
user_id: bigint({ mode: "number" }).notNull(),
content: text("content").notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_community_chat_messages_on_community_id").on(
table.community_id,
),
index("index_community_chat_messages_on_deleted_at").on(table.deleted_at),
index("index_community_chat_messages_on_user_id").on(table.user_id),
],
);
export const CommunityChatRecapRuns = pgTable(
"community_chat_recap_runs",
{
recap_frequency: varchar("recap_frequency", { length: 255 }).notNull(),
from_date: timestamp("from_date").notNull(),
to_date: timestamp("to_date").notNull(),
recaps_count: integer("recaps_count").default(0).notNull(),
finished_at: timestamp("finished_at"),
notified_at: timestamp("notified_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("idx_on_recap_frequency_from_date_to_date_2ed29d569d").on(
table.recap_frequency,
table.from_date,
table.to_date,
),
index("index_community_chat_recap_runs_on_recap_frequency").on(
table.recap_frequency,
),
],
);
export const CommunityChatRecaps = pgTable(
"community_chat_recaps",
{
community_chat_recap_run_id: bigint({ mode: "number" }).notNull(),
community_id: bigint({ mode: "number" }),
seller_id: bigint({ mode: "number" }),
summarized_message_count: integer("summarized_message_count")
.default(0)
.notNull(),
summary: text("summary"),
status: varchar("status", { length: 255 }).default("pending").notNull(),
error_message: varchar("error_message", { length: 255 }),
input_token_count: integer("input_token_count").default(0).notNull(),
output_token_count: integer("output_token_count").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_community_chat_recaps_on_community_chat_recap_run_id").on(
table.community_chat_recap_run_id,
),
index("index_community_chat_recaps_on_community_id").on(table.community_id),
index("index_community_chat_recaps_on_seller_id").on(table.seller_id),
index("index_community_chat_recaps_on_status").on(table.status),
],
);
export const CommunityNotificationSettings = pgTable(
"community_notification_settings",
{
user_id: bigint({ mode: "number" }).notNull(),
seller_id: bigint({ mode: "number" }).notNull(),
recap_frequency: varchar("recap_frequency", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_community_notification_settings_on_recap_frequency").on(
table.recap_frequency,
),
index("index_community_notification_settings_on_seller_id").on(
table.seller_id,
),
uniqueIndex(
"index_community_notification_settings_on_user_id_and_seller_id",
).on(table.user_id, table.seller_id),
index("index_community_notification_settings_on_user_id").on(table.user_id),
],
);
export const ComputedSalesAnalyticsDays = pgTable(
"computed_sales_analytics_days",
{
key: varchar("key", { length: 191 }).notNull(),
data: text("data"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_computed_sales_analytics_days_on_key").on(table.key),
],
);
export const ConsumptionEvents = pgTable(
"consumption_events",
{
product_file_id: bigint({ mode: "number" }),
url_redirect_id: bigint({ mode: "number" }),
purchase_id: bigint({ mode: "number" }),
event_type: varchar("event_type", { length: 255 }),
platform: varchar("platform", { length: 255 }),
flags: integer("flags").default(0).notNull(),
json_data: text("json_data"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
link_id: bigint({ mode: "number" }),
consumed_at: timestamp("consumed_at"),
media_location_basis_points: integer("media_location_basis_points"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_consumption_events_on_link_id").on(table.link_id),
index("index_consumption_events_on_product_file_id").on(
table.product_file_id,
),
index("index_consumption_events_on_purchase_id").on(table.purchase_id),
],
);
export const CreditCards = pgTable(
"credit_cards",
{
card_type: varchar("card_type", { length: 255 }),
expiry_month: integer("expiry_month"),
expiry_year: integer("expiry_year"),
stripe_customer_id: varchar("stripe_customer_id", { length: 255 }),
visual: varchar("visual", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
stripe_fingerprint: varchar("stripe_fingerprint", { length: 255 }),
cvc_check_failed: boolean("cvc_check_failed"),
card_country: varchar("card_country", { length: 255 }),
stripe_card_id: varchar("stripe_card_id", { length: 255 }),
card_bin: varchar("card_bin", { length: 255 }),
preorder_id: integer("preorder_id"),
card_data_handling_mode: varchar("card_data_handling_mode", {
length: 255,
}),
charge_processor_id: varchar("charge_processor_id", { length: 255 }),
braintree_customer_id: varchar("braintree_customer_id", { length: 255 }),
funding_type: varchar("funding_type", { length: 191 }),
paypal_billing_agreement_id: varchar("paypal_billing_agreement_id", {
length: 191,
}),
processor_payment_method_id: varchar("processor_payment_method_id", {
length: 255,
}),
json_data: jsonb("json_data"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_credit_cards_on_preorder_id").on(table.preorder_id),
index("index_credit_cards_on_stripe_fingerprint").on(
table.stripe_fingerprint,
),
],
);
export const Credits = pgTable(
"credits",
{
user_id: integer("user_id"),
amount_cents: integer("amount_cents"),
balance_id: integer("balance_id"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
crediting_user_id: integer("crediting_user_id"),
chargebacked_purchase_id: integer("chargebacked_purchase_id"),
merchant_account_id: integer("merchant_account_id").default(1),
dispute_id: integer("dispute_id"),
returned_payment_id: integer("returned_payment_id"),
refund_id: integer("refund_id"),
financing_paydown_purchase_id: integer("financing_paydown_purchase_id"),
fee_retention_refund_id: integer("fee_retention_refund_id"),
backtax_agreement_id: bigint({ mode: "number" }),
json_data: text("json_data"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_credits_on_balance_id").on(table.balance_id),
index("index_credits_on_dispute_id").on(table.dispute_id),
],
);
export const CustomDomains = pgTable(
"custom_domains",
{
user_id: integer("user_id"),
domain: varchar("domain", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
ssl_certificate_issued_at: timestamp("ssl_certificate_issued_at"),
deleted_at: timestamp("deleted_at"),
state: varchar("state", { length: 255 }).default("unverified").notNull(),
failed_verification_attempts_count: integer(
"failed_verification_attempts_count",
)
.default(0)
.notNull(),
product_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_custom_domains_on_domain").on(table.domain),
index("index_custom_domains_on_product_id").on(table.product_id),
index("index_custom_domains_on_ssl_certificate_issued_at").on(
table.ssl_certificate_issued_at,
),
index("index_custom_domains_on_user_id").on(table.user_id),
],
);
export const CustomFields = pgTable(
"custom_fields",
{
field_type: varchar("field_type", { length: 255 }),
name: varchar("name", { length: 255 }),
required: boolean("required").default(false),
global: boolean("global").default(false),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
seller_id: bigint({ mode: "number" }).notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_custom_fields_on_seller_id").on(table.seller_id)],
);
export const CustomFieldsProducts = pgTable(
"custom_fields_products",
{
custom_field_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_custom_fields_products_on_custom_field_id").on(
table.custom_field_id,
),
index("index_custom_fields_products_on_product_id").on(table.product_id),
],
);
export const Devices = pgTable(
"devices",
{
token: varchar("token", { length: 255 }).notNull(),
app_version: varchar("app_version", { length: 255 }),
device_type: varchar("device_type", { length: 255 })
.default("ios")
.notNull(),
user_id: integer("user_id").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
app_type: varchar("app_type", { length: 255 })
.default("consumer")
.notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_devices_on_app_type_and_user_id").on(
table.app_type,
table.user_id,
),
uniqueIndex("index_devices_on_token_and_device_type").on(
table.token,
table.device_type,
),
index("index_devices_on_user_id").on(table.user_id),
],
);
export const DiscoverSearchSuggestions = pgTable(
"discover_search_suggestions",
{
discover_search_id: bigint({ mode: "number" }),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_discover_search_suggestions_on_discover_search_id").on(
table.discover_search_id,
),
],
);
export const DiscoverSearches = pgTable(
"discover_searches",
{
query: varchar("query", { length: 255 }),
taxonomy_id: bigint({ mode: "number" }),
user_id: bigint({ mode: "number" }),
ip_address: varchar("ip_address", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
autocomplete: boolean("autocomplete").default(false).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
clicked_resource_type: varchar("clicked_resource_type", { length: 255 }),
clicked_resource_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_discover_searches_on_browser_guid").on(table.browser_guid),
index("index_discover_searches_on_clicked_resource").on(
table.clicked_resource_type,
table.clicked_resource_id,
),
index("index_discover_searches_on_created_at").on(table.created_at),
index("index_discover_searches_on_ip_address").on(table.ip_address),
index("index_discover_searches_on_query").on(table.query),
index("index_discover_searches_on_user_id").on(table.user_id),
],
);
export const DisputeEvidences = pgTable(
"dispute_evidences",
{
dispute_id: bigint({ mode: "number" }).notNull(),
purchased_at: timestamp("purchased_at"),
customer_purchase_ip: varchar("customer_purchase_ip", { length: 255 }),
customer_email: varchar("customer_email", { length: 255 }),
customer_name: varchar("customer_name", { length: 255 }),
billing_address: varchar("billing_address", { length: 255 }),
shipping_address: varchar("shipping_address", { length: 255 }),
shipped_at: timestamp("shipped_at"),
shipping_carrier: varchar("shipping_carrier", { length: 255 }),
shipping_tracking_number: varchar("shipping_tracking_number", {
length: 255,
}),
uncategorized_text: text("uncategorized_text"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
product_description: text("product_description"),
cancellation_policy_disclosure: text("cancellation_policy_disclosure"),
refund_policy_disclosure: text("refund_policy_disclosure"),
cancellation_rebuttal: text("cancellation_rebuttal"),
refund_refusal_explanation: text("refund_refusal_explanation"),
seller_contacted_at: timestamp("seller_contacted_at"),
seller_submitted_at: timestamp("seller_submitted_at"),
resolved_at: timestamp("resolved_at"),
resolution: varchar("resolution", { length: 255 }).default("unknown"),
error_message: varchar("error_message", { length: 255 }),
access_activity_log: text("access_activity_log"),
reason_for_winning: text("reason_for_winning"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_dispute_evidences_on_dispute_id").on(table.dispute_id),
index("index_dispute_evidences_on_resolved_at").on(table.resolved_at),
],
);
export const Disputes = pgTable(
"disputes",
{
purchase_id: integer("purchase_id"),
charge_processor_id: varchar("charge_processor_id", { length: 255 }),
charge_processor_dispute_id: varchar("charge_processor_dispute_id", {
length: 255,
}),
reason: varchar("reason", { length: 255 }),
state: varchar("state", { length: 255 }),
initiated_at: timestamp("initiated_at"),
closed_at: timestamp("closed_at"),
formalized_at: timestamp("formalized_at"),
won_at: timestamp("won_at"),
lost_at: timestamp("lost_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
service_charge_id: integer("service_charge_id"),
seller_id: bigint({ mode: "number" }),
event_created_at: timestamp("event_created_at"),
charge_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_disputes_on_charge_id").on(table.charge_id),
index("index_disputes_on_purchase_id").on(table.purchase_id),
index("index_disputes_on_seller_id_and_event_created_at").on(
table.seller_id,
table.event_created_at,
),
index("index_disputes_on_seller_id_and_lost_at").on(
table.seller_id,
table.lost_at,
),
index("index_disputes_on_seller_id_and_won_at").on(
table.seller_id,
table.won_at,
),
index("index_disputes_on_service_charge_id").on(table.service_charge_id),
],
);
export const DropboxFiles = pgTable(
"dropbox_files",
{
state: varchar("state", { length: 255 }),
dropbox_url: varchar("dropbox_url", { length: 2000 }),
expires_at: timestamp("expires_at"),
deleted_at: timestamp("deleted_at"),
user_id: integer("user_id"),
product_file_id: integer("product_file_id"),
link_id: integer("link_id"),
json_data: text("json_data"),
s3_url: varchar("s3_url", { length: 2000 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_dropbox_files_on_link_id").on(table.link_id),
index("index_dropbox_files_on_product_file_id").on(table.product_file_id),
index("index_dropbox_files_on_user_id").on(table.user_id),
],
);
export const EmailInfoCharges = pgTable(
"email_info_charges",
{
email_info_id: bigint({ mode: "number" }).notNull(),
charge_id: bigint({ mode: "number" }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_email_info_charges_on_charge_id").on(table.charge_id),
index("index_email_info_charges_on_email_info_id").on(table.email_info_id),
],
);
export const EmailInfos = pgTable(
"email_infos",
{
purchase_id: bigint({ mode: "number" }),
installment_id: bigint({ mode: "number" }),
type: varchar("type", { length: 255 }),
email_name: varchar("email_name", { length: 255 }),
state: varchar("state", { length: 255 }),
sent_at: timestamp("sent_at"),
delivered_at: timestamp("delivered_at"),
opened_at: timestamp("opened_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_email_infos_on_installment_id_and_purchase_id").on(
table.installment_id,
table.purchase_id,
),
index("index_email_infos_on_purchase_id").on(table.purchase_id),
],
);
export const Events = pgTable(
"events",
{
visit_id: integer("visit_id"),
ip_address: varchar("ip_address", { length: 255 }),
event_name: varchar("event_name", { length: 255 }),
user_id: integer("user_id"),
link_id: integer("link_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
referrer: varchar("referrer", { length: 255 }),
parent_referrer: varchar("parent_referrer", { length: 255 }),
language: varchar("language", { length: 255 }),
browser: varchar("browser", { length: 255 }),
is_mobile: boolean("is_mobile").default(false),
email: varchar("email", { length: 255 }),
purchase_id: integer("purchase_id"),
price_cents: integer("price_cents"),
credit_card_id: integer("credit_card_id"),
card_type: varchar("card_type", { length: 255 }),
card_visual: varchar("card_visual", { length: 255 }),
purchase_state: varchar("purchase_state", { length: 255 }),
billing_zip: varchar("billing_zip", { length: 255 }),
chargeback: boolean("chargeback").default(false),
refunded: boolean("refunded").default(false),
view_url: varchar("view_url", { length: 255 }),
fingerprint: varchar("fingerprint", { length: 255 }),
ip_country: varchar("ip_country", { length: 255 }),
ip_longitude: doublePrecision("ip_longitude"),
ip_latitude: doublePrecision("ip_latitude"),
is_modal: boolean("is_modal"),
friend_actions: text("friend_actions"),
browser_fingerprint: varchar("browser_fingerprint", { length: 255 }),
browser_plugins: varchar("browser_plugins", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
referrer_domain: varchar("referrer_domain", { length: 255 }),
ip_state: varchar("ip_state", { length: 255 }),
active_test_path_assignments: varchar("active_test_path_assignments", {
length: 255,
}),
service_charge_id: integer("service_charge_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_events_on_browser_guid").on(table.browser_guid),
index("index_events_on_created_at").on(table.created_at),
index("index_events_on_event_name_and_link_id").on(
table.event_name,
table.link_id,
table.created_at,
),
index("index_events_on_ip_address").on(table.ip_address),
index("index_events_on_link_id").on(table.link_id),
index("index_events_on_purchase_id").on(table.purchase_id),
index("index_events_on_service_charge_id").on(table.service_charge_id),
index("index_events_on_user_id").on(table.user_id),
index("index_events_on_visit_id").on(table.visit_id),
],
);
export const Followers = pgTable(
"followers",
{
followed_id: integer("followed_id").notNull(),
email: varchar("email", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
follower_user_id: integer("follower_user_id"),
source: varchar("source", { length: 255 }),
source_product_id: integer("source_product_id"),
confirmed_at: timestamp("confirmed_at"),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_followers_on_email_and_followed_id").on(
table.email,
table.followed_id,
),
index("index_followers_on_followed_id_and_confirmed_at").on(
table.followed_id,
table.confirmed_at,
),
index("index_followers_on_followed_id_and_email").on(
table.followed_id,
table.email,
),
],
);
export const FriendlyIdSlugs = pgTable(
"friendly_id_slugs",
{
slug: varchar("slug", { length: 191 }).notNull(),
sluggable_id: integer("sluggable_id").notNull(),
sluggable_type: varchar("sluggable_type", { length: 50 }),
scope: varchar("scope", { length: 191 }),
created_at: timestamp("created_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex(
"index_friendly_id_slugs_on_slug_and_sluggable_type_and_scope",
).on(table.slug, table.sluggable_type, table.scope),
index("index_friendly_id_slugs_on_slug_and_sluggable_type").on(
table.slug,
table.sluggable_type,
),
index("index_friendly_id_slugs_on_sluggable_type_and_sluggable_id").on(
table.sluggable_type,
table.sluggable_id,
),
],
);
export const Gifts = pgTable(
"gifts",
{
giftee_purchase_id: bigint({ mode: "number" }),
gifter_purchase_id: bigint({ mode: "number" }),
link_id: bigint({ mode: "number" }),
state: varchar("state", { length: 255 }),
gift_note: text("gift_note"),
giftee_email: varchar("giftee_email", { length: 255 }),
gifter_email: varchar("gifter_email", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_gifts_on_giftee_email").on(table.giftee_email),
index("index_gifts_on_giftee_purchase_id").on(table.giftee_purchase_id),
index("index_gifts_on_gifter_email").on(table.gifter_email),
index("index_gifts_on_gifter_purchase_id").on(table.gifter_purchase_id),
],
);
export const GumroadDailyAnalytics = pgTable(
"gumroad_daily_analytics",
{
period_ended_at: timestamp("period_ended_at").notNull(),
gumroad_price_cents: integer("gumroad_price_cents").notNull(),
gumroad_fee_cents: integer("gumroad_fee_cents").notNull(),
creators_with_sales: integer("creators_with_sales").notNull(),
gumroad_discover_price_cents: integer(
"gumroad_discover_price_cents",
).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_gumroad_daily_analytics_on_period_ended_at").on(
table.period_ended_at,
),
],
);
export const ImportedCustomers = pgTable(
"imported_customers",
{
email: varchar("email", { length: 255 }),
purchase_date: timestamp("purchase_date"),
link_id: integer("link_id"),
importing_user_id: integer("importing_user_id"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_imported_customers_on_email").on(table.email),
index("index_imported_customers_on_importing_user_id").on(
table.importing_user_id,
),
index("index_imported_customers_on_link_id_and_purchase_date").on(
table.link_id,
table.purchase_date,
),
index("index_imported_customers_on_link_id").on(table.link_id),
],
);
export const InstallmentEvents = pgTable(
"installment_events",
{
event_id: integer("event_id"),
installment_id: integer("installment_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_installment_events_on_event_id").on(table.event_id),
uniqueIndex("index_installment_events_on_installment_id_and_event_id").on(
table.installment_id,
table.event_id,
),
],
);
export const InstallmentPlanSnapshots = pgTable(
"installment_plan_snapshots",
{
payment_option_id: integer("payment_option_id").notNull(),
number_of_installments: integer("number_of_installments").notNull(),
recurrence: varchar("recurrence", { length: 255 }).notNull(),
total_price_cents: integer("total_price_cents").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_installment_plan_snapshots_on_payment_option_id").on(
table.payment_option_id,
),
],
);
export const InstallmentRules = pgTable(
"installment_rules",
{
installment_id: integer("installment_id"),
delayed_delivery_time: integer("delayed_delivery_time"),
to_be_published_at: timestamp("to_be_published_at"),
version: integer("version").default(0).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
time_period: varchar("time_period", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_installment_rules_on_installment_id").on(
table.installment_id,
),
],
);
export const Installments = pgTable(
"installments",
{
link_id: integer("link_id"),
message: text("message"),
url: text("url"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
name: varchar("name", { length: 255 }),
published_at: timestamp("published_at"),
deleted_at: timestamp("deleted_at"),
flags: integer("flags").default(0).notNull(),
seller_id: integer("seller_id"),
installment_type: varchar("installment_type", { length: 255 }),
json_data: text("json_data"),
customer_count: integer("customer_count"),
workflow_id: integer("workflow_id"),
call_to_action_text: varchar("call_to_action_text", { length: 2083 }),
call_to_action_url: varchar("call_to_action_url", { length: 2083 }),
cover_image_url: varchar("cover_image_url", { length: 255 }),
base_variant_id: integer("base_variant_id"),
slug: varchar("slug", { length: 255 }),
installment_events_count: integer("installment_events_count").default(0),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_installments_on_base_variant_id").on(table.base_variant_id),
index("index_installments_on_created_at").on(table.created_at),
index("index_installments_on_link_id").on(table.link_id),
index("index_installments_on_seller_id_and_link_id").on(
table.seller_id,
table.link_id,
),
uniqueIndex("index_installments_on_slug").on(table.slug),
index("index_installments_on_workflow_id").on(table.workflow_id),
],
);
export const Integrations = pgTable("integrations", {
api_key: varchar("api_key", { length: 255 }),
json_data: text("json_data"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
type: varchar("type", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
});
export const Invites = pgTable(
"invites",
{
sender_id: integer("sender_id"),
receiver_email: varchar("receiver_email", { length: 255 }),
receiver_id: integer("receiver_id"),
invite_state: varchar("invite_state", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_invites_on_receiver_id").on(table.receiver_id),
index("index_invites_on_sender_id").on(table.sender_id),
],
);
export const LargeSellers = pgTable(
"large_sellers",
{
user_id: integer("user_id").notNull(),
sales_count: integer("sales_count").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_large_sellers_on_updated_at").on(table.updated_at),
uniqueIndex("index_large_sellers_on_user_id").on(table.user_id),
],
);
export const LastReadCommunityChatMessages = pgTable(
"last_read_community_chat_messages",
{
user_id: bigint({ mode: "number" }).notNull(),
community_id: bigint({ mode: "number" }).notNull(),
community_chat_message_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("idx_on_community_chat_message_id_f9e10450e2").on(
table.community_chat_message_id,
),
index("index_last_read_community_chat_messages_on_community_id").on(
table.community_id,
),
uniqueIndex("idx_on_user_id_community_id_45efa2a41c").on(
table.user_id,
table.community_id,
),
index("index_last_read_community_chat_messages_on_user_id").on(
table.user_id,
),
],
);
export const LegacyPermalinks = pgTable(
"legacy_permalinks",
{
permalink: varchar("permalink", { length: 255 }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_legacy_permalinks_on_permalink").on(table.permalink),
index("index_legacy_permalinks_on_product_id").on(table.product_id),
],
);
export const Licenses = pgTable(
"licenses",
{
link_id: integer("link_id"),
purchase_id: integer("purchase_id"),
serial: varchar("serial", { length: 255 }),
trial_expires_at: timestamp("trial_expires_at"),
uses: integer("uses").default(0),
json_data: varchar("json_data", { length: 255 }),
deleted_at: timestamp("deleted_at"),
flags: integer("flags").default(0),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
imported_customer_id: integer("imported_customer_id"),
disabled_at: timestamp("disabled_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_licenses_on_imported_customer_id").on(
table.imported_customer_id,
),
index("index_licenses_on_link_id").on(table.link_id),
index("index_licenses_on_purchase_id").on(table.purchase_id),
uniqueIndex("index_licenses_on_serial").on(table.serial),
],
);
export const Links = pgTable(
"links",
{
user_id: bigint({ mode: "number" }),
name: varchar("name", { length: 255 }).notNull(),
unique_permalink: varchar("unique_permalink", { length: 255 }),
preview_url: text("preview_url"),
description: text("description"),
purchase_type: integer("purchase_type").default(0),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
purchase_disabled_at: timestamp("purchase_disabled_at"),
deleted_at: timestamp("deleted_at"),
price_cents: integer("price_cents"),
price_currency_type: varchar("price_currency_type", {
length: 255,
}).default("usd"),
customizable_price: boolean("customizable_price"),
max_purchase_count: integer("max_purchase_count"),
bad_card_counter: integer("bad_card_counter").default(0),
require_shipping: boolean("require_shipping").default(false),
last_partner_sync: timestamp("last_partner_sync"),
preview_oembed: text("preview_oembed"),
showcaseable: boolean("showcaseable").default(false),
custom_receipt: text("custom_receipt"),
custom_filetype: varchar("custom_filetype", { length: 255 }),
filetype: varchar("filetype", { length: 255 }).default("link"),
filegroup: varchar("filegroup", { length: 255 }).default("url"),
size: bigint({ mode: "number" }),
bitrate: integer("bitrate"),
framerate: integer("framerate"),
pagelength: integer("pagelength"),
duration: integer("duration"),
width: integer("width"),
height: integer("height"),
custom_permalink: varchar("custom_permalink", { length: 255 }),
common_color: varchar("common_color", { length: 255 }),
suggested_price_cents: integer("suggested_price_cents"),
banned_at: timestamp("banned_at"),
risk_score: integer("risk_score"),
risk_score_updated_at: timestamp("risk_score_updated_at"),
draft: boolean("draft").default(false),
flags: bigint({ mode: "number" }).default(0).notNull(),
subscription_duration: integer("subscription_duration"),
json_data: text("json_data"),
external_mapping_id: varchar("external_mapping_id", { length: 255 }),
affiliate_application_id: bigint({ mode: "number" }),
rental_price_cents: integer("rental_price_cents"),
duration_in_months: integer("duration_in_months"),
migrated_to_tiered_pricing_at: timestamp("migrated_to_tiered_pricing_at"),
free_trial_duration_unit: integer("free_trial_duration_unit"),
free_trial_duration_amount: integer("free_trial_duration_amount"),
content_updated_at: timestamp("content_updated_at"),
taxonomy_id: bigint({ mode: "number" }),
native_type: varchar("native_type", { length: 255 })
.default("digital")
.notNull(),
discover_fee_per_thousand: integer("discover_fee_per_thousand")
.default(100)
.notNull(),
support_email: varchar("support_email", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_links_on_banned_at").on(table.banned_at),
index("index_links_on_custom_permalink").on(table.custom_permalink),
index("index_links_on_deleted_at").on(table.deleted_at),
index("index_links_on_showcaseable").on(table.showcaseable),
index("index_links_on_taxonomy_id").on(table.taxonomy_id),
index("index_links_on_unique_permalink").on(table.unique_permalink),
index("index_links_on_user_id_and_updated_at").on(
table.user_id,
table.updated_at,
),
index("index_links_on_user_id").on(table.user_id),
],
);
export const MediaLocations = pgTable(
"media_locations",
{
product_file_id: bigint({ mode: "number" }).notNull(),
url_redirect_id: bigint({ mode: "number" }).notNull(),
purchase_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
consumed_at: timestamp("consumed_at"),
platform: varchar("platform", { length: 255 }),
location: integer("location").notNull(),
content_length: integer("content_length"),
unit: varchar("unit", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_media_locations_on_product_file_id").on(table.product_file_id),
index("index_media_locations_on_product_id_and_updated_at").on(
table.product_id,
table.updated_at,
),
index(
"index_media_locations_on_purchase_id_product_file_id_consumed_at",
).on(table.purchase_id, table.product_file_id, table.consumed_at),
index("index_media_locations_on_purchase_id").on(table.purchase_id),
],
);
export const MerchantAccounts = pgTable(
"merchant_accounts",
{
user_id: bigint({ mode: "number" }),
acquirer_id: varchar("acquirer_id", { length: 255 }),
acquirer_merchant_id: varchar("acquirer_merchant_id", { length: 255 }),
charge_processor_id: varchar("charge_processor_id", { length: 255 }),
charge_processor_merchant_id: varchar("charge_processor_merchant_id", {
length: 255,
}),
json_data: text("json_data"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
deleted_at: timestamp("deleted_at"),
charge_processor_verified_at: timestamp("charge_processor_verified_at"),
country: varchar("country", { length: 255 }).default("US"),
currency: varchar("currency", { length: 255 }).default("usd"),
charge_processor_deleted_at: timestamp("charge_processor_deleted_at"),
charge_processor_alive_at: timestamp("charge_processor_alive_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_merchant_accounts_on_charge_processor_merchant_id").on(
table.charge_processor_merchant_id,
),
index("index_merchant_accounts_on_user_id").on(table.user_id),
],
);
export const OauthAccessGrants = pgTable(
"oauth_access_grants",
{
resource_owner_id: integer("resource_owner_id").notNull(),
application_id: integer("application_id").notNull(),
token: varchar("token", { length: 255 }).notNull(),
expires_in: integer("expires_in").notNull(),
redirect_uri: varchar("redirect_uri", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
revoked_at: timestamp("revoked_at"),
scopes: varchar("scopes", { length: 255 }).default("").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_oauth_access_grants_on_created_at").on(table.created_at),
uniqueIndex("index_oauth_access_grants_on_token").on(table.token),
],
);
export const OauthAccessTokens = pgTable(
"oauth_access_tokens",
{
resource_owner_id: integer("resource_owner_id"),
application_id: integer("application_id").notNull(),
token: varchar("token", { length: 255 }).notNull(),
refresh_token: varchar("refresh_token", { length: 255 }),
expires_in: integer("expires_in"),
revoked_at: timestamp("revoked_at"),
created_at: timestamp("created_at").notNull(),
scopes: varchar("scopes", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_oauth_access_tokens_on_refresh_token").on(
table.refresh_token,
),
index("index_oauth_access_tokens_on_resource_owner_id").on(
table.resource_owner_id,
),
uniqueIndex("index_oauth_access_tokens_on_token").on(table.token),
],
);
export const OauthApplications = pgTable(
"oauth_applications",
{
name: varchar("name", { length: 255 }).notNull(),
uid: varchar("uid", { length: 255 }).notNull(),
secret: varchar("secret", { length: 255 }).notNull(),
redirect_uri: varchar("redirect_uri", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
owner_id: integer("owner_id"),
owner_type: varchar("owner_type", { length: 255 }).default("User"),
affiliate_basis_points: integer("affiliate_basis_points"),
deleted_at: timestamp("deleted_at"),
scopes: varchar("scopes", { length: 255 }).default("").notNull(),
confidential: boolean("confidential").default(false).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_oauth_applications_on_owner_id_and_owner_type").on(
table.owner_id,
table.owner_type,
),
uniqueIndex("index_oauth_applications_on_uid").on(table.uid),
],
);
export const OfferCodes = pgTable(
"offer_codes",
{
link_id: integer("link_id"),
name: varchar("name", { length: 255 }),
amount_cents: integer("amount_cents"),
max_purchase_count: integer("max_purchase_count"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
amount_percentage: integer("amount_percentage"),
user_id: integer("user_id").notNull(),
currency_type: varchar("currency_type", { length: 255 }),
code: varchar("code", { length: 255 }),
universal: boolean("universal").default(false).notNull(),
valid_at: timestamp("valid_at"),
expires_at: timestamp("expires_at"),
minimum_quantity: integer("minimum_quantity"),
duration_in_months: integer("duration_in_months"),
minimum_amount_cents: integer("minimum_amount_cents"),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_offer_codes_on_code_and_link_id").on(
table.code,
table.link_id,
),
index("index_offer_codes_on_link_id").on(table.link_id),
index("index_offer_codes_on_name_and_link_id").on(
table.name,
table.link_id,
),
index("index_offer_codes_on_universal").on(table.universal),
index("index_offer_codes_on_user_id").on(table.user_id),
],
);
export const OfferCodesProducts = pgTable(
"offer_codes_products",
{
offer_code_id: bigint({ mode: "number" }),
product_id: bigint({ mode: "number" }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_offer_codes_products_on_offer_code_id").on(
table.offer_code_id,
),
index("index_offer_codes_products_on_product_id").on(table.product_id),
],
);
export const OrderPurchases = pgTable(
"order_purchases",
{
order_id: bigint({ mode: "number" }).notNull(),
purchase_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_order_purchases_on_order_id").on(table.order_id),
index("index_order_purchases_on_purchase_id").on(table.purchase_id),
],
);
export const Orders = pgTable(
"orders",
{
purchaser_id: bigint({ mode: "number" }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
review_reminder_scheduled_at: timestamp("review_reminder_scheduled_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_orders_on_purchaser_id").on(table.purchaser_id)],
);
export const PaymentOptions = pgTable(
"payment_options",
{
subscription_id: integer("subscription_id"),
price_id: integer("price_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
deleted_at: timestamp("deleted_at"),
flags: integer("flags").default(0).notNull(),
product_installment_plan_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_payment_options_on_price_id").on(table.price_id),
index("index_payment_options_on_product_installment_plan_id").on(
table.product_installment_plan_id,
),
index("index_payment_options_on_subscription_id").on(table.subscription_id),
],
);
export const Payments = pgTable(
"payments",
{
user_id: bigint({ mode: "number" }),
state: varchar("state", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
txn_id: varchar("txn_id", { length: 255 }),
processor_fee_cents: integer("processor_fee_cents"),
correlation_id: varchar("correlation_id", { length: 255 }),
processor: varchar("processor", { length: 255 }),
amount_cents: bigint({ mode: "number" }),
payment_address: varchar("payment_address", { length: 255 }),
payout_period_end_date: date("payout_period_end_date"),
bank_account_id: bigint({ mode: "number" }),
amount_cents_in_local_currency: integer("amount_cents_in_local_currency"),
stripe_connect_account_id: varchar("stripe_connect_account_id", {
length: 255,
}),
stripe_transfer_id: varchar("stripe_transfer_id", { length: 255 }),
stripe_internal_transfer_id: varchar("stripe_internal_transfer_id", {
length: 255,
}),
currency: varchar("currency", { length: 255 }).default("usd"),
flags: integer("flags").default(0).notNull(),
json_data: text("json_data"),
failure_reason: varchar("failure_reason", { length: 191 }),
processor_reversing_payout_id: varchar("processor_reversing_payout_id", {
length: 255,
}),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_payments_on_stripe_transfer_id").on(table.stripe_transfer_id),
index("index_payments_on_user_id").on(table.user_id),
],
);
export const PaymentsBalances = pgTable(
"payments_balances",
{
payment_id: integer("payment_id"),
balance_id: integer("balance_id"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_payments_balances_on_balance_id").on(table.balance_id),
index("index_payments_balances_on_payment_id").on(table.payment_id),
],
);
export const PostEmailBlasts = pgTable(
"post_email_blasts",
{
post_id: bigint({ mode: "number" }).notNull(),
seller_id: bigint({ mode: "number" }).notNull(),
requested_at: timestamp("requested_at"),
started_at: timestamp("started_at"),
first_email_delivered_at: timestamp("first_email_delivered_at"),
last_email_delivered_at: timestamp("last_email_delivered_at"),
delivery_count: integer("delivery_count").default(0),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
completed_at: timestamp("completed_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_post_email_blasts_on_post_id_and_requested_at").on(
table.post_id,
table.requested_at,
),
index("index_post_email_blasts_on_requested_at").on(table.requested_at),
index("index_post_email_blasts_on_seller_id_and_requested_at").on(
table.seller_id,
table.requested_at,
),
],
);
export const PreorderLinks = pgTable(
"preorder_links",
{
link_id: bigint({ mode: "number" }),
state: varchar("state", { length: 255 }),
release_at: timestamp("release_at"),
url: varchar("url", { length: 255 }),
custom_filetype: varchar("custom_filetype", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_preorder_links_on_link_id").on(table.link_id)],
);
export const Preorders = pgTable(
"preorders",
{
preorder_link_id: integer("preorder_link_id").notNull(),
seller_id: integer("seller_id").notNull(),
purchaser_id: integer("purchaser_id"),
state: varchar("state", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_preorders_on_preorder_link_id").on(table.preorder_link_id),
index("index_preorders_on_purchaser_id").on(table.purchaser_id),
index("index_preorders_on_seller_id").on(table.seller_id),
],
);
export const Prices = pgTable(
"prices",
{
link_id: integer("link_id"),
price_cents: integer("price_cents").default(0).notNull(),
currency: varchar("currency", { length: 255 }).default("usd"),
recurrence: varchar("recurrence", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
deleted_at: timestamp("deleted_at"),
flags: integer("flags").default(0).notNull(),
variant_id: integer("variant_id"),
suggested_price_cents: integer("suggested_price_cents"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_prices_on_link_id").on(table.link_id),
index("index_prices_on_variant_id").on(table.variant_id),
],
);
export const ProcessorPaymentIntents = pgTable(
"processor_payment_intents",
{
purchase_id: bigint({ mode: "number" }).notNull(),
intent_id: varchar("intent_id", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_processor_payment_intents_on_intent_id").on(table.intent_id),
uniqueIndex("index_processor_payment_intents_on_purchase_id").on(
table.purchase_id,
),
],
);
export const ProductCachedValues = pgTable(
"product_cached_values",
{
product_id: bigint({ mode: "number" }).notNull(),
expired: boolean("expired").default(false).notNull(),
successful_sales_count: integer("successful_sales_count"),
remaining_for_sale_count: integer("remaining_for_sale_count"),
monthly_recurring_revenue: numeric("monthly_recurring_revenue", {
precision: 10,
scale: 2,
}),
revenue_pending: numeric("revenue_pending", { precision: 10, scale: 2 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
total_usd_cents: bigint({ mode: "number" }).default(0),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_cached_values_on_expired").on(table.expired),
index("index_product_cached_values_on_product_id").on(table.product_id),
],
);
export const ProductFiles = pgTable(
"product_files",
{
link_id: bigint({ mode: "number" }),
url: varchar("url", { length: 1024 }),
filetype: varchar("filetype", { length: 255 }),
filegroup: varchar("filegroup", { length: 255 }),
size: bigint({ mode: "number" }),
bitrate: integer("bitrate"),
framerate: integer("framerate"),
pagelength: integer("pagelength"),
duration: integer("duration"),
width: integer("width"),
height: integer("height"),
flags: bigint({ mode: "number" }).default(0).notNull(),
json_data: text("json_data"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
position: integer("position"),
installment_id: bigint({ mode: "number" }),
display_name: varchar("display_name", { length: 1024 }),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
description: text("description"),
folder_id: bigint({ mode: "number" }),
stampable_pdf: boolean("stampable_pdf"),
isbn: varchar("isbn", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_files_on_deleted_at").on(table.deleted_at),
index("index_product_files_on_deleted_from_cdn_at").on(
table.deleted_from_cdn_at,
),
index("index_product_files_on_installment_id").on(table.installment_id),
index("index_product_files_on_link_id").on(table.link_id),
index("index_product_files_on_url").on(table.url),
],
);
export const ProductFilesArchives = pgTable(
"product_files_archives",
{
deleted_at: timestamp("deleted_at"),
link_id: bigint({ mode: "number" }),
installment_id: bigint({ mode: "number" }),
product_files_archive_state: varchar("product_files_archive_state", {
length: 255,
}),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
url: varchar("url", { length: 1024 }),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
variant_id: bigint({ mode: "number" }),
digest: varchar("digest", { length: 255 }),
folder_id: varchar("folder_id", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_files_archives_on_deleted_at").on(table.deleted_at),
index("index_product_files_archives_on_deleted_from_cdn_at").on(
table.deleted_from_cdn_at,
),
index("index_product_files_archives_on_folder_id").on(table.folder_id),
index("index_product_files_archives_on_installment_id").on(
table.installment_id,
),
index("index_product_files_archives_on_link_id").on(table.link_id),
index("index_product_files_archives_on_variant_id").on(table.variant_id),
],
);
export const ProductFilesFilesArchives = pgTable(
"product_files_files_archives",
{
product_file_id: integer("product_file_id"),
product_files_archive_id: integer("product_files_archive_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_files_files_archives_on_product_files_archive_id").on(
table.product_files_archive_id,
),
],
);
export const ProductFolders = pgTable(
"product_folders",
{
product_id: bigint({ mode: "number" }),
name: varchar("name", { length: 255 }).notNull(),
position: integer("position"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_folders_on_product_id").on(table.product_id),
],
);
export const ProductInstallmentPlans = pgTable(
"product_installment_plans",
{
link_id: bigint({ mode: "number" }).notNull(),
number_of_installments: integer("number_of_installments").notNull(),
recurrence: varchar("recurrence", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_installment_plans_on_deleted_at").on(table.deleted_at),
index("index_product_installment_plans_on_link_id").on(table.link_id),
],
);
export const ProductIntegrations = pgTable(
"product_integrations",
{
product_id: bigint({ mode: "number" }).notNull(),
integration_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_integrations_on_integration_id").on(
table.integration_id,
),
index("index_product_integrations_on_product_id").on(table.product_id),
],
);
export const ProductReviewResponses = pgTable(
"product_review_responses",
{
user_id: bigint({ mode: "number" }).notNull(),
product_review_id: bigint({ mode: "number" }).notNull(),
message: text("message"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_review_responses_on_product_review_id").on(
table.product_review_id,
),
index("index_product_review_responses_on_user_id").on(table.user_id),
],
);
export const ProductReviewStats = pgTable(
"product_review_stats",
{
link_id: integer("link_id"),
reviews_count: integer("reviews_count").default(0).notNull(),
average_rating: doublePrecision("average_rating").default(0.0).notNull(),
ratings_of_one_count: integer("ratings_of_one_count").default(0),
ratings_of_two_count: integer("ratings_of_two_count").default(0),
ratings_of_three_count: integer("ratings_of_three_count").default(0),
ratings_of_four_count: integer("ratings_of_four_count").default(0),
ratings_of_five_count: integer("ratings_of_five_count").default(0),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_product_review_stats_on_link_id").on(table.link_id),
],
);
export const ProductReviewVideos = pgTable(
"product_review_videos",
{
product_review_id: bigint({ mode: "number" }).notNull(),
approval_status: varchar("approval_status", { length: 255 }).default(
"pending_review",
),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_review_videos_on_deleted_at").on(table.deleted_at),
index("index_product_review_videos_on_product_review_id").on(
table.product_review_id,
),
],
);
export const ProductReviews = pgTable(
"product_reviews",
{
purchase_id: bigint({ mode: "number" }),
rating: integer("rating"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
link_id: bigint({ mode: "number" }),
message: text("message"),
has_message: text("has_message").notNull(),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("idx_on_link_id_has_message_created_at_2fcf6c0c64").on(
table.link_id,
table.has_message,
table.created_at,
),
uniqueIndex("index_product_reviews_on_purchase_id").on(table.purchase_id),
],
);
export const ProductTaggings = pgTable(
"product_taggings",
{
tag_id: integer("tag_id"),
product_id: integer("product_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_product_taggings_on_product_id").on(table.product_id),
index("index_product_taggings_on_tag_id").on(table.tag_id),
],
);
export const PublicFiles = pgTable(
"public_files",
{
seller_id: bigint({ mode: "number" }),
resource_type: varchar("resource_type", { length: 255 }).notNull(),
resource_id: bigint({ mode: "number" }).notNull(),
public_id: varchar("public_id", { length: 255 }).notNull(),
display_name: varchar("display_name", { length: 255 }).notNull(),
original_file_name: varchar("original_file_name", {
length: 255,
}).notNull(),
file_type: varchar("file_type", { length: 255 }),
file_group: varchar("file_group", { length: 255 }),
deleted_at: timestamp("deleted_at"),
scheduled_for_deletion_at: timestamp("scheduled_for_deletion_at"),
json_data: text("json_data"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_public_files_on_deleted_at").on(table.deleted_at),
index("index_public_files_on_file_group").on(table.file_group),
index("index_public_files_on_file_type").on(table.file_type),
uniqueIndex("index_public_files_on_public_id").on(table.public_id),
index("index_public_files_on_resource").on(
table.resource_type,
table.resource_id,
),
index("index_public_files_on_scheduled_for_deletion_at").on(
table.scheduled_for_deletion_at,
),
index("index_public_files_on_seller_id").on(table.seller_id),
],
);
export const PurchaseCustomFieldFiles = pgTable(
"purchase_custom_field_files",
{
url: varchar("url", { length: 255 }),
purchase_custom_field_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_custom_field_files_on_purchase_custom_field_id").on(
table.purchase_custom_field_id,
),
],
);
export const PurchaseCustomFields = pgTable(
"purchase_custom_fields",
{
purchase_id: bigint({ mode: "number" }).notNull(),
field_type: varchar("field_type", { length: 255 }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
value: text("value"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
bundle_product_id: bigint({ mode: "number" }),
custom_field_id: bigint({ mode: "number" }),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_custom_fields_on_custom_field_id").on(
table.custom_field_id,
),
index("index_purchase_custom_fields_on_purchase_id").on(table.purchase_id),
],
);
export const PurchaseEarlyFraudWarnings = pgTable(
"purchase_early_fraud_warnings",
{
purchase_id: bigint({ mode: "number" }),
processor_id: varchar("processor_id", { length: 255 }).notNull(),
dispute_id: bigint({ mode: "number" }),
refund_id: bigint({ mode: "number" }),
fraud_type: varchar("fraud_type", { length: 255 }).notNull(),
actionable: boolean("actionable").notNull(),
charge_risk_level: varchar("charge_risk_level", { length: 255 }).notNull(),
processor_created_at: timestamp("processor_created_at").notNull(),
resolution: varchar("resolution", { length: 255 }).default("unknown"),
resolved_at: timestamp("resolved_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
resolution_message: varchar("resolution_message", { length: 255 }),
charge_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_purchase_early_fraud_warnings_on_charge_id").on(
table.charge_id,
),
uniqueIndex("index_purchase_early_fraud_warnings_on_processor_id").on(
table.processor_id,
),
uniqueIndex("index_purchase_early_fraud_warnings_on_purchase_id").on(
table.purchase_id,
),
],
);
export const PurchaseIntegrations = pgTable(
"purchase_integrations",
{
purchase_id: bigint({ mode: "number" }).notNull(),
integration_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
discord_user_id: varchar("discord_user_id", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_integrations_on_integration_id").on(
table.integration_id,
),
index("index_purchase_integrations_on_purchase_id").on(table.purchase_id),
],
);
export const PurchaseOfferCodeDiscounts = pgTable(
"purchase_offer_code_discounts",
{
purchase_id: bigint({ mode: "number" }).notNull(),
offer_code_id: bigint({ mode: "number" }).notNull(),
offer_code_amount: integer("offer_code_amount").notNull(),
offer_code_is_percent: boolean("offer_code_is_percent")
.default(false)
.notNull(),
pre_discount_minimum_price_cents: integer(
"pre_discount_minimum_price_cents",
).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
duration_in_months: integer("duration_in_months"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_offer_code_discounts_on_offer_code_id").on(
table.offer_code_id,
),
uniqueIndex("index_purchase_offer_code_discounts_on_purchase_id").on(
table.purchase_id,
),
],
);
export const PurchaseRefundPolicies = pgTable(
"purchase_refund_policies",
{
purchase_id: bigint({ mode: "number" }).notNull(),
title: varchar("title", { length: 255 }).notNull(),
fine_print: text("fine_print"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
max_refund_period_in_days: integer("max_refund_period_in_days"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_refund_policies_on_purchase_id").on(
table.purchase_id,
),
],
);
export const PurchaseSalesTaxInfos = pgTable(
"purchase_sales_tax_infos",
{
purchase_id: integer("purchase_id"),
elected_country_code: varchar("elected_country_code", { length: 255 }),
card_country_code: varchar("card_country_code", { length: 255 }),
ip_country_code: varchar("ip_country_code", { length: 255 }),
country_code: varchar("country_code", { length: 255 }),
postal_code: varchar("postal_code", { length: 255 }),
ip_address: varchar("ip_address", { length: 255 }),
business_vat_id: varchar("business_vat_id", { length: 191 }),
state_code: varchar("state_code", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_sales_tax_infos_on_purchase_id").on(
table.purchase_id,
),
],
);
export const PurchaseTaxjarInfos = pgTable(
"purchase_taxjar_infos",
{
purchase_id: bigint({ mode: "number" }).notNull(),
combined_tax_rate: numeric("combined_tax_rate", { precision: 8, scale: 7 }),
county_tax_rate: numeric("county_tax_rate", { precision: 8, scale: 7 }),
city_tax_rate: numeric("city_tax_rate", { precision: 8, scale: 7 }),
state_tax_rate: numeric("state_tax_rate", { precision: 8, scale: 7 }),
jurisdiction_state: varchar("jurisdiction_state", { length: 255 }),
jurisdiction_county: varchar("jurisdiction_county", { length: 255 }),
jurisdiction_city: varchar("jurisdiction_city", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
gst_tax_rate: numeric("gst_tax_rate", { precision: 8, scale: 7 }),
pst_tax_rate: numeric("pst_tax_rate", { precision: 8, scale: 7 }),
qst_tax_rate: numeric("qst_tax_rate", { precision: 8, scale: 7 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchase_taxjar_infos_on_purchase_id").on(table.purchase_id),
],
);
export const PurchaseWalletTypes = pgTable(
"purchase_wallet_types",
{
purchase_id: bigint({ mode: "number" }).notNull(),
wallet_type: varchar("wallet_type", { length: 255 }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_purchase_wallet_types_on_purchase_id").on(
table.purchase_id,
),
index("index_purchase_wallet_types_on_wallet_type").on(table.wallet_type),
],
);
export const Purchases = pgTable(
"purchases",
{
seller_id: bigint({ mode: "number" }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
fee_cents: integer("fee_cents"),
link_id: bigint({ mode: "number" }),
email: text("email"),
price_cents: integer("price_cents"),
displayed_price_cents: integer("displayed_price_cents"),
displayed_price_currency_type: varchar("displayed_price_currency_type", {
length: 255,
}).default("usd"),
rate_converted_to_usd: varchar("rate_converted_to_usd", { length: 255 }),
street_address: varchar("street_address", { length: 255 }),
city: varchar("city", { length: 255 }),
state: varchar("state", { length: 255 }),
zip_code: varchar("zip_code", { length: 255 }),
country: varchar("country", { length: 255 }),
full_name: varchar("full_name", { length: 255 }),
credit_card_id: bigint({ mode: "number" }),
purchaser_id: bigint({ mode: "number" }),
purchaser_type: varchar("purchaser_type", { length: 255 }).default("User"),
session_id: varchar("session_id", { length: 255 }),
ip_address: varchar("ip_address", { length: 255 }),
is_mobile: boolean("is_mobile"),
stripe_refunded: boolean("stripe_refunded"),
stripe_transaction_id: varchar("stripe_transaction_id", { length: 255 }),
stripe_fingerprint: varchar("stripe_fingerprint", { length: 255 }),
stripe_card_id: varchar("stripe_card_id", { length: 255 }),
can_contact: boolean("can_contact").default(true),
referrer: varchar("referrer", { length: 255 }),
stripe_status: varchar("stripe_status", { length: 255 }),
variants: text("variants"),
chargeback_date: timestamp("chargeback_date"),
webhook_failed: boolean("webhook_failed").default(false),
failed: boolean("failed").default(false),
card_type: varchar("card_type", { length: 255 }),
card_visual: varchar("card_visual", { length: 255 }),
purchase_state: varchar("purchase_state", { length: 255 }),
processor_fee_cents: integer("processor_fee_cents"),
succeeded_at: timestamp("succeeded_at"),
card_country: varchar("card_country", { length: 255 }),
stripe_error_code: varchar("stripe_error_code", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
error_code: varchar("error_code", { length: 255 }),
card_bin: varchar("card_bin", { length: 255 }),
custom_fields: text("custom_fields"),
ip_country: varchar("ip_country", { length: 255 }),
ip_state: varchar("ip_state", { length: 255 }),
purchase_success_balance_id: bigint({ mode: "number" }),
purchase_chargeback_balance_id: bigint({ mode: "number" }),
purchase_refund_balance_id: bigint({ mode: "number" }),
flags: bigint({ mode: "number" }).default(0).notNull(),
offer_code_id: bigint({ mode: "number" }),
subscription_id: bigint({ mode: "number" }),
preorder_id: bigint({ mode: "number" }),
card_expiry_month: integer("card_expiry_month"),
card_expiry_year: integer("card_expiry_year"),
tax_cents: integer("tax_cents").default(0),
affiliate_credit_cents: integer("affiliate_credit_cents").default(0),
credit_card_zipcode: varchar("credit_card_zipcode", { length: 255 }),
json_data: varchar("json_data", { length: 255 }),
card_data_handling_mode: varchar("card_data_handling_mode", {
length: 255,
}),
charge_processor_id: varchar("charge_processor_id", { length: 255 }),
total_transaction_cents: integer("total_transaction_cents"),
gumroad_tax_cents: integer("gumroad_tax_cents"),
zip_tax_rate_id: bigint({ mode: "number" }),
quantity: integer("quantity").default(1).notNull(),
merchant_account_id: bigint({ mode: "number" }),
shipping_cents: integer("shipping_cents").default(0),
affiliate_id: bigint({ mode: "number" }),
processor_fee_cents_currency: varchar("processor_fee_cents_currency", {
length: 255,
}).default("usd"),
stripe_partially_refunded: boolean("stripe_partially_refunded").default(
false,
),
paypal_order_id: varchar("paypal_order_id", { length: 191 }),
rental_expired: boolean("rental_expired"),
processor_payment_intent_id: varchar("processor_payment_intent_id", {
length: 255,
}),
processor_setup_intent_id: varchar("processor_setup_intent_id", {
length: 255,
}),
price_id: bigint({ mode: "number" }),
recommended_by: varchar("recommended_by", { length: 255 }),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchases_on_affiliate_id_and_created_at").on(
table.affiliate_id,
table.created_at,
),
index("index_purchases_on_browser_guid").on(table.browser_guid),
index("index_purchases_on_card_type_visual_date_fingerprint").on(
table.card_type,
table.card_visual,
table.created_at,
table.stripe_fingerprint,
),
index("index_purchases_on_card_type_visual_fingerprint").on(
table.card_type,
table.card_visual,
table.stripe_fingerprint,
),
index("index_purchases_on_created_at").on(table.created_at),
index("index_purchases_on_email_long").on(table.email),
index("index_purchases_on_full_name").on(table.full_name),
index("index_purchases_on_ip_address").on(table.ip_address),
index("index_purchases_on_link_id_and_purchase_state_and_created_at").on(
table.link_id,
table.purchase_state,
table.created_at,
),
index("index_purchases_on_link_id").on(table.link_id),
index("index_purchases_on_offer_code_id").on(table.offer_code_id),
index("index_purchases_on_paypal_order_id").on(table.paypal_order_id),
index("index_purchases_on_preorder_id").on(table.preorder_id),
index("index_purchase_chargeback_balance_id").on(
table.purchase_chargeback_balance_id,
),
index("index_purchase_refund_balance_id").on(
table.purchase_refund_balance_id,
),
index("index_purchases_on_purchase_state_and_created_at").on(
table.purchase_state,
table.created_at,
),
index("index_purchase_success_balance_id").on(
table.purchase_success_balance_id,
),
index("index_purchases_on_purchaser_id").on(table.purchaser_id),
index("index_purchases_on_rental_expired").on(table.rental_expired),
index("index_purchases_on_seller_id_and_chargeback_date").on(
table.seller_id,
table.chargeback_date,
),
index("index_purchases_on_seller_id_and_purchase_state_and_created_at").on(
table.seller_id,
table.purchase_state,
table.created_at,
),
index("index_purchases_on_seller_id_and_succeeded_at").on(
table.seller_id,
table.succeeded_at,
),
index("index_purchases_on_seller_id").on(table.seller_id),
index("index_purchases_on_stripe_fingerprint").on(table.stripe_fingerprint),
index("index_purchases_on_stripe_transaction_id").on(
table.stripe_transaction_id,
),
index("index_purchases_on_subscription_id").on(table.subscription_id),
],
);
export const PurchasingPowerParityInfos = pgTable(
"purchasing_power_parity_infos",
{
purchase_id: bigint({ mode: "number" }).notNull(),
factor: integer("factor"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_purchasing_power_parity_infos_on_purchase_id").on(
table.purchase_id,
),
],
);
export const RecommendedPurchaseInfos = pgTable(
"recommended_purchase_infos",
{
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
purchase_id: integer("purchase_id"),
recommended_link_id: integer("recommended_link_id"),
recommended_by_link_id: integer("recommended_by_link_id"),
recommendation_type: varchar("recommendation_type", { length: 255 }),
flags: integer("flags").default(0).notNull(),
discover_fee_per_thousand: integer("discover_fee_per_thousand"),
recommender_model_name: varchar("recommender_model_name", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_recommended_purchase_infos_on_purchase_id").on(
table.purchase_id,
),
index("index_recommended_purchase_infos_on_recommended_by_link_id").on(
table.recommended_by_link_id,
),
index("index_recommended_purchase_infos_on_recommended_link_id").on(
table.recommended_link_id,
),
],
);
export const RecurringServices = pgTable(
"recurring_services",
{
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
user_id: integer("user_id"),
type: varchar("type", { length: 191 }),
price_cents: integer("price_cents"),
recurrence: integer("recurrence"),
failed_at: timestamp("failed_at"),
cancelled_at: timestamp("cancelled_at"),
state: varchar("state", { length: 191 }),
json_data: varchar("json_data", { length: 191 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_recurring_services_on_user_id").on(table.user_id)],
);
export const RefundPolicies = pgTable(
"refund_policies",
{
seller_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }),
title: varchar("title", { length: 255 }),
fine_print: text("fine_print"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
max_refund_period_in_days: integer("max_refund_period_in_days"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_refund_policies_on_product_id").on(table.product_id),
index("index_refund_policies_on_seller_id").on(table.seller_id),
],
);
export const Refunds = pgTable(
"refunds",
{
amount_cents: integer("amount_cents").default(0),
purchase_id: bigint({ mode: "number" }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
refunding_user_id: bigint({ mode: "number" }),
creator_tax_cents: integer("creator_tax_cents"),
gumroad_tax_cents: integer("gumroad_tax_cents"),
total_transaction_cents: integer("total_transaction_cents"),
json_data: text("json_data"),
link_id: bigint({ mode: "number" }),
status: varchar("status", { length: 191 }).default("succeeded"),
processor_refund_id: varchar("processor_refund_id", { length: 191 }),
fee_cents: integer("fee_cents"),
flags: bigint({ mode: "number" }).default(0).notNull(),
seller_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_refunds_on_link_id").on(table.link_id),
index("index_refunds_on_processor_refund_id").on(table.processor_refund_id),
index("index_refunds_on_purchase_id").on(table.purchase_id),
index("index_refunds_on_seller_id_and_created_at").on(
table.seller_id,
table.created_at,
),
],
);
export const ResourceSubscriptions = pgTable(
"resource_subscriptions",
{
oauth_application_id: integer("oauth_application_id").notNull(),
user_id: integer("user_id").notNull(),
resource_name: varchar("resource_name", { length: 255 }).notNull(),
post_url: varchar("post_url", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
content_type: varchar("content_type", { length: 255 }).default(
"application/x-www-form-urlencoded",
),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_resource_subscriptions_on_oauth_application_id").on(
table.oauth_application_id,
),
index("index_resource_subscriptions_on_user_id").on(table.user_id),
],
);
export const RichContents = pgTable(
"rich_contents",
{
entity_id: bigint({ mode: "number" }).notNull(),
entity_type: varchar("entity_type", { length: 255 }).notNull(),
description: jsonb("description").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
title: varchar("title", { length: 255 }),
position: integer("position").default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_rich_contents_on_entity_id_and_entity_type").on(
table.entity_id,
table.entity_type,
),
],
);
export const SalesExportChunks = pgTable(
"sales_export_chunks",
{
export_id: bigint({ mode: "number" }).notNull(),
purchase_ids: text("purchase_ids"),
custom_fields: text("custom_fields"),
purchases_data: text("purchases_data"),
processed: boolean("processed").default(false).notNull(),
revision: varchar("revision", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_sales_export_chunks_on_export_id").on(table.export_id),
],
);
export const SalesExports = pgTable(
"sales_exports",
{
recipient_id: bigint({ mode: "number" }).notNull(),
query: text("query"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_sales_exports_on_recipient_id").on(table.recipient_id),
],
);
export const SalesRelatedProductsInfos = pgTable(
"sales_related_products_infos",
{
smaller_product_id: bigint({ mode: "number" }).notNull(),
larger_product_id: bigint({ mode: "number" }).notNull(),
sales_count: integer("sales_count").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_larger_product_id_and_sales_count").on(
table.larger_product_id,
table.sales_count,
),
uniqueIndex("index_smaller_and_larger_product_ids").on(
table.smaller_product_id,
table.larger_product_id,
),
index("index_smaller_product_id_and_sales_count").on(
table.smaller_product_id,
table.sales_count,
),
],
);
export const SelfServiceAffiliateProducts = pgTable(
"self_service_affiliate_products",
{
seller_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
enabled: boolean("enabled").default(false).notNull(),
affiliate_basis_points: integer("affiliate_basis_points").notNull(),
destination_url: varchar("destination_url", { length: 2083 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_self_service_affiliate_products_on_product_id").on(
table.product_id,
),
index("index_self_service_affiliate_products_on_seller_id").on(
table.seller_id,
),
],
);
export const SellerProfileSections = pgTable(
"seller_profile_sections",
{
seller_id: bigint({ mode: "number" }).notNull(),
header: varchar("header", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
json_data: jsonb("json_data"),
type: varchar("type", { length: 255 })
.default("SellerProfileProductsSection")
.notNull(),
product_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_seller_profile_sections_on_product_id").on(table.product_id),
index("index_seller_profile_sections_on_seller_id").on(table.seller_id),
],
);
export const SellerProfiles = pgTable(
"seller_profiles",
{
seller_id: bigint({ mode: "number" }).notNull(),
highlight_color: varchar("highlight_color", { length: 255 }),
background_color: varchar("background_color", { length: 255 }),
font: varchar("font", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
json_data: jsonb("json_data"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_seller_profiles_on_seller_id").on(table.seller_id)],
);
export const SentAbandonedCartEmails = pgTable(
"sent_abandoned_cart_emails",
{
cart_id: bigint({ mode: "number" }).notNull(),
installment_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_sent_abandoned_cart_emails_on_cart_id").on(table.cart_id),
index("index_sent_abandoned_cart_emails_on_installment_id").on(
table.installment_id,
),
],
);
export const SentEmailInfos = pgTable(
"sent_email_infos",
{
key: varchar("key", { length: 40 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_sent_email_infos_on_created_at").on(table.created_at),
uniqueIndex("index_sent_email_infos_on_key").on(table.key),
],
);
export const SentPostEmails = pgTable(
"sent_post_emails",
{
post_id: bigint({ mode: "number" }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_sent_post_emails_on_post_id_and_email").on(
table.post_id,
table.email,
),
],
);
export const ServiceCharges = pgTable(
"service_charges",
{
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
user_id: integer("user_id"),
recurring_service_id: integer("recurring_service_id"),
charge_cents: integer("charge_cents"),
charge_cents_currency: varchar("charge_cents_currency", {
length: 191,
}).default("usd"),
state: varchar("state", { length: 191 }),
succeeded_at: timestamp("succeeded_at"),
credit_card_id: integer("credit_card_id"),
card_expiry_month: integer("card_expiry_month"),
card_expiry_year: integer("card_expiry_year"),
card_data_handling_mode: varchar("card_data_handling_mode", {
length: 191,
}),
card_bin: varchar("card_bin", { length: 191 }),
card_type: varchar("card_type", { length: 191 }),
card_country: varchar("card_country", { length: 191 }),
card_zip_code: varchar("card_zip_code", { length: 191 }),
card_visual: varchar("card_visual", { length: 191 }),
charge_processor_id: varchar("charge_processor_id", { length: 191 }),
charge_processor_fee_cents: integer("charge_processor_fee_cents"),
charge_processor_fee_cents_currency: varchar(
"charge_processor_fee_cents_currency",
{ length: 191 },
).default("usd"),
charge_processor_transaction_id: varchar(
"charge_processor_transaction_id",
{ length: 191 },
),
charge_processor_fingerprint: varchar("charge_processor_fingerprint", {
length: 191,
}),
charge_processor_card_id: varchar("charge_processor_card_id", {
length: 191,
}),
charge_processor_status: varchar("charge_processor_status", {
length: 191,
}),
charge_processor_error_code: varchar("charge_processor_error_code", {
length: 191,
}),
charge_processor_refunded: boolean("charge_processor_refunded")
.default(false)
.notNull(),
chargeback_date: timestamp("chargeback_date"),
json_data: varchar("json_data", { length: 191 }),
error_code: varchar("error_code", { length: 191 }),
merchant_account_id: integer("merchant_account_id"),
browser_guid: varchar("browser_guid", { length: 191 }),
ip_address: varchar("ip_address", { length: 191 }),
ip_country: varchar("ip_country", { length: 191 }),
ip_state: varchar("ip_state", { length: 191 }),
session_id: varchar("session_id", { length: 191 }),
flags: integer("flags").default(0).notNull(),
discount_code: varchar("discount_code", { length: 100 }),
processor_payment_intent_id: varchar("processor_payment_intent_id", {
length: 255,
}),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_service_charges_on_card_type_visual_fingerprint").on(
table.card_type,
table.card_visual,
table.charge_processor_fingerprint,
),
index("index_service_charges_on_card_type_visual_date_fingerprint").on(
table.card_type,
table.card_visual,
table.created_at,
table.charge_processor_fingerprint,
),
index("index_service_charges_on_created_at").on(table.created_at),
index("index_service_charges_on_recurring_service_id").on(
table.recurring_service_id,
),
index("index_service_charges_on_user_id").on(table.user_id),
],
);
export const Shipments = pgTable(
"shipments",
{
purchase_id: integer("purchase_id"),
ship_state: varchar("ship_state", { length: 255 }),
shipped_at: timestamp("shipped_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
tracking_number: varchar("tracking_number", { length: 255 }),
carrier: varchar("carrier", { length: 255 }),
tracking_url: varchar("tracking_url", { length: 2083 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_shipments_on_purchase_id").on(table.purchase_id)],
);
export const ShippingDestinations = pgTable(
"shipping_destinations",
{
link_id: integer("link_id"),
user_id: integer("user_id"),
country_code: varchar("country_code", { length: 255 }).notNull(),
one_item_rate_cents: integer("one_item_rate_cents").notNull(),
multiple_items_rate_cents: integer("multiple_items_rate_cents").notNull(),
flags: integer("flags").default(0).notNull(),
json_data: text("json_data"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_shipping_destinations_on_link_id").on(table.link_id),
index("index_shipping_destinations_on_user_id").on(table.user_id),
],
);
export const SignupEvents = pgTable(
"signup_events",
{
visit_id: integer("visit_id"),
ip_address: varchar("ip_address", { length: 255 }),
user_id: integer("user_id"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
referrer: varchar("referrer", { length: 255 }),
parent_referrer: varchar("parent_referrer", { length: 255 }),
language: varchar("language", { length: 255 }),
browser: varchar("browser", { length: 255 }),
is_mobile: boolean("is_mobile").default(false),
email: varchar("email", { length: 255 }),
view_url: varchar("view_url", { length: 255 }),
fingerprint: varchar("fingerprint", { length: 255 }),
ip_country: varchar("ip_country", { length: 255 }),
ip_longitude: doublePrecision("ip_longitude"),
ip_latitude: doublePrecision("ip_latitude"),
is_modal: boolean("is_modal"),
browser_fingerprint: varchar("browser_fingerprint", { length: 255 }),
browser_plugins: varchar("browser_plugins", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
referrer_domain: varchar("referrer_domain", { length: 255 }),
ip_state: varchar("ip_state", { length: 255 }),
active_test_path_assignments: varchar("active_test_path_assignments", {
length: 255,
}),
event_name: varchar("event_name", { length: 255 }),
link_id: integer("link_id"),
purchase_id: integer("purchase_id"),
price_cents: integer("price_cents"),
credit_card_id: integer("credit_card_id"),
card_type: varchar("card_type", { length: 255 }),
card_visual: varchar("card_visual", { length: 255 }),
purchase_state: boolean("purchase_state").default(false),
billing_zip: varchar("billing_zip", { length: 255 }),
chargeback: boolean("chargeback").default(false),
refunded: boolean("refunded"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_events_on_browser_guid").on(table.browser_guid),
index("index_events_on_created_at").on(table.created_at),
index("index_events_on_ip_address").on(table.ip_address),
index("index_events_on_user_id").on(table.user_id),
index("index_events_on_visit_id").on(table.visit_id),
],
);
export const SkusVariants = pgTable(
"skus_variants",
{
variant_id: integer("variant_id"),
sku_id: integer("sku_id"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_skus_variants_on_sku_id").on(table.sku_id),
index("index_skus_variants_on_variant_id").on(table.variant_id),
],
);
export const StaffPickedProducts = pgTable(
"staff_picked_products",
{
product_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_staff_picked_products_on_product_id").on(
table.product_id,
),
],
);
export const StampedPdfs = pgTable(
"stamped_pdfs",
{
url_redirect_id: bigint({ mode: "number" }),
product_file_id: bigint({ mode: "number" }),
url: varchar("url", { length: 1024 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_stamped_pdfs_on_created_at").on(table.created_at),
index("index_stamped_pdfs_on_deleted_at").on(table.deleted_at),
index("index_stamped_pdfs_on_deleted_from_cdn_at").on(
table.deleted_from_cdn_at,
),
index("index_stamped_pdfs_on_product_file_id").on(table.product_file_id),
index("index_stamped_pdfs_on_url").on(table.url),
index("index_stamped_pdfs_on_url_redirect_id").on(table.url_redirect_id),
],
);
export const StripeApplePayDomains = pgTable(
"stripe_apple_pay_domains",
{
user_id: bigint({ mode: "number" }).notNull(),
domain: varchar("domain", { length: 255 }).notNull(),
stripe_id: varchar("stripe_id", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("index_stripe_apple_pay_domains_on_domain").on(table.domain),
index("index_stripe_apple_pay_domains_on_user_id").on(table.user_id),
],
);
export const SubscriptionEvents = pgTable(
"subscription_events",
{
subscription_id: bigint({ mode: "number" }).notNull(),
event_type: integer("event_type").notNull(),
occurred_at: timestamp("occurred_at").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
seller_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_subscription_events_on_seller_id_and_occurred_at").on(
table.seller_id,
table.occurred_at,
),
index("index_subscription_events_on_subscription_id").on(
table.subscription_id,
),
],
);
export const SubscriptionPlanChanges = pgTable(
"subscription_plan_changes",
{
subscription_id: bigint({ mode: "number" }).notNull(),
base_variant_id: bigint({ mode: "number" }),
recurrence: varchar("recurrence", { length: 191 }).notNull(),
perceived_price_cents: integer("perceived_price_cents").notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
quantity: integer("quantity").default(1).notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
effective_on: date("effective_on"),
notified_subscriber_at: timestamp("notified_subscriber_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_subscription_plan_changes_on_base_variant_id").on(
table.base_variant_id,
),
index("index_subscription_plan_changes_on_subscription_id").on(
table.subscription_id,
),
],
);
export const Subscriptions = pgTable(
"subscriptions",
{
link_id: bigint({ mode: "number" }),
user_id: bigint({ mode: "number" }),
cancelled_at: timestamp("cancelled_at"),
failed_at: timestamp("failed_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
flags: bigint({ mode: "number" }).default(0).notNull(),
user_requested_cancellation_at: timestamp("user_requested_cancellation_at"),
charge_occurrence_count: integer("charge_occurrence_count"),
ended_at: timestamp("ended_at"),
last_payment_option_id: bigint({ mode: "number" }),
credit_card_id: bigint({ mode: "number" }),
deactivated_at: timestamp("deactivated_at"),
free_trial_ends_at: timestamp("free_trial_ends_at"),
seller_id: bigint({ mode: "number" }),
token: varchar("token", { length: 255 }),
token_expires_at: timestamp("token_expires_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_subscriptions_on_cancelled_at").on(table.cancelled_at),
index("index_subscriptions_on_deactivated_at").on(table.deactivated_at),
index("index_subscriptions_on_ended_at").on(table.ended_at),
index("index_subscriptions_on_failed_at").on(table.failed_at),
index("index_subscriptions_on_link_id_and_flags").on(
table.link_id,
table.flags,
),
index("index_subscriptions_on_link_id").on(table.link_id),
index("index_subscriptions_on_seller_id_and_created_at").on(
table.seller_id,
table.created_at,
),
index("index_subscriptions_on_user_id").on(table.user_id),
],
);
export const SubtitleFiles = pgTable(
"subtitle_files",
{
url: varchar("url", { length: 1024 }),
language: varchar("language", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
product_file_id: bigint({ mode: "number" }),
deleted_at: timestamp("deleted_at"),
size: integer("size"),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_subtitle_files_on_deleted_at").on(table.deleted_at),
index("index_subtitle_files_on_product_file_id").on(table.product_file_id),
index("index_subtitle_files_on_url").on(table.url),
],
);
export const Tags = pgTable(
"tags",
{
name: varchar("name", { length: 100 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
humanized_name: varchar("humanized_name", { length: 191 }),
flagged_at: timestamp("flagged_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_tags_on_name").on(table.name)],
);
export const Taxonomies = pgTable(
"taxonomies",
{
parent_id: bigint({ mode: "number" }),
slug: varchar("slug", { length: 255 }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_taxonomies_on_parent_id").on(table.parent_id)],
);
export const TaxonomyHierarchies = pgTable(
"taxonomy_hierarchies",
{
ancestor_id: bigint({ mode: "number" }).notNull(),
descendant_id: bigint({ mode: "number" }).notNull(),
generations: integer("generations").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex("taxonomy_anc_desc_idx").on(
table.ancestor_id,
table.descendant_id,
table.generations,
),
index("taxonomy_desc_idx").on(table.descendant_id),
],
);
export const TaxonomyStats = pgTable(
"taxonomy_stats",
{
taxonomy_id: bigint({ mode: "number" }).notNull(),
creators_count: integer("creators_count").default(0).notNull(),
products_count: integer("products_count").default(0).notNull(),
sales_count: integer("sales_count").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
recent_sales_count: integer("recent_sales_count").default(0),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_taxonomy_stats_on_taxonomy_id").on(table.taxonomy_id),
],
);
export const TeamInvitations = pgTable(
"team_invitations",
{
seller_id: bigint({ mode: "number" }).notNull(),
email: varchar("email", { length: 255 }).notNull(),
role: varchar("role", { length: 255 }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
expires_at: timestamp("expires_at").notNull(),
accepted_at: timestamp("accepted_at"),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_team_invitations_on_seller_id").on(table.seller_id)],
);
export const TeamMemberships = pgTable(
"team_memberships",
{
seller_id: bigint({ mode: "number" }).notNull(),
user_id: bigint({ mode: "number" }).notNull(),
role: varchar("role", { length: 255 }).notNull(),
last_accessed_at: timestamp("last_accessed_at"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_team_memberships_on_seller_id").on(table.seller_id),
index("index_team_memberships_on_user_id").on(table.user_id),
],
);
export const ThirdPartyAnalytics = pgTable(
"third_party_analytics",
{
user_id: integer("user_id"),
link_id: integer("link_id"),
analytics_code: text("analytics_code"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
name: varchar("name", { length: 255 }),
location: varchar("location", { length: 255 }).default("receipt"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_third_party_analytics_on_link_id").on(table.link_id),
index("index_third_party_analytics_on_user_id").on(table.user_id),
],
);
export const Thumbnails = pgTable(
"thumbnails",
{
product_id: integer("product_id"),
deleted_at: timestamp("deleted_at"),
guid: varchar("guid", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
unsplash_url: varchar("unsplash_url", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_thumbnails_on_product_id").on(table.product_id)],
);
export const Tips = pgTable(
"tips",
{
purchase_id: bigint({ mode: "number" }).notNull(),
value_cents: integer("value_cents").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
value_usd_cents: integer("value_usd_cents").default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_tips_on_purchase_id").on(table.purchase_id)],
);
export const TopSellers = pgTable(
"top_sellers",
{
user_id: bigint({ mode: "number" }).notNull(),
sales_usd: bigint({ mode: "number" }).default(0).notNull(),
sales_count: bigint({ mode: "number" }).default(0).notNull(),
rank: integer("rank").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_top_sellers_on_rank").on(table.rank),
uniqueIndex("index_top_sellers_on_user_id").on(table.user_id),
],
);
export const TosAgreements = pgTable(
"tos_agreements",
{
user_id: integer("user_id"),
ip: varchar("ip", { length: 255 }),
created_at: timestamp("created_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_tos_agreements_on_user_id").on(table.user_id)],
);
export const TranscodedVideos = pgTable(
"transcoded_videos",
{
link_id: bigint({ mode: "number" }),
original_video_key: varchar("original_video_key", { length: 1024 }),
transcoded_video_key: varchar("transcoded_video_key", { length: 2048 }),
job_id: varchar("job_id", { length: 255 }),
state: varchar("state", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
product_file_id: bigint({ mode: "number" }),
flags: integer("flags").default(0).notNull(),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
deleted_at: timestamp("deleted_at"),
last_accessed_at: timestamp("last_accessed_at"),
streamable_type: varchar("streamable_type", { length: 255 }),
streamable_id: bigint({ mode: "number" }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_transcoded_videos_on_deleted_at").on(table.deleted_at),
index("index_transcoded_videos_on_deleted_from_cdn_at").on(
table.deleted_from_cdn_at,
),
index("index_transcoded_videos_on_job_id").on(table.job_id),
index("index_transcoded_videos_on_last_accessed_at").on(
table.last_accessed_at,
),
index("index_transcoded_videos_on_link_id").on(table.link_id),
index("index_transcoded_videos_on_original_video_key").on(
table.original_video_key,
),
index("index_transcoded_videos_on_product_file_id").on(
table.product_file_id,
),
index("index_transcoded_videos_on_streamable").on(
table.streamable_type,
table.streamable_id,
),
index("index_transcoded_videos_on_transcoded_video_key").on(
table.transcoded_video_key,
),
],
);
export const UpsellPurchases = pgTable(
"upsell_purchases",
{
upsell_id: bigint({ mode: "number" }).notNull(),
purchase_id: bigint({ mode: "number" }).notNull(),
selected_product_id: bigint({ mode: "number" }),
upsell_variant_id: bigint({ mode: "number" }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_upsell_purchases_on_purchase_id").on(table.purchase_id),
index("index_upsell_purchases_on_selected_product_id").on(
table.selected_product_id,
),
index("index_upsell_purchases_on_upsell_id").on(table.upsell_id),
index("index_upsell_purchases_on_upsell_variant_id").on(
table.upsell_variant_id,
),
],
);
export const UpsellVariants = pgTable(
"upsell_variants",
{
upsell_id: bigint({ mode: "number" }).notNull(),
selected_variant_id: bigint({ mode: "number" }).notNull(),
offered_variant_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_upsell_variants_on_offered_variant_id").on(
table.offered_variant_id,
),
index("index_upsell_variants_on_selected_variant_id").on(
table.selected_variant_id,
),
index("index_upsell_variants_on_upsell_id").on(table.upsell_id),
],
);
export const Upsells = pgTable(
"upsells",
{
seller_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
variant_id: bigint({ mode: "number" }),
offer_code_id: bigint({ mode: "number" }),
name: varchar("name", { length: 255 }),
cross_sell: boolean("cross_sell").notNull(),
text: varchar("text", { length: 255 }),
description: text("description"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
universal: boolean("universal").default(false).notNull(),
flags: integer("flags").default(0).notNull(),
paused: boolean("paused").default(false).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_upsells_on_offer_code_id").on(table.offer_code_id),
index("index_upsells_on_offered_product_id").on(table.product_id),
index("index_upsells_on_seller_id").on(table.seller_id),
index("index_upsells_on_offered_variant_id").on(table.variant_id),
],
);
export const UpsellsSelectedProducts = pgTable(
"upsells_selected_products",
{
upsell_id: bigint({ mode: "number" }).notNull(),
selected_product_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_upsells_selected_products_on_product_id").on(
table.selected_product_id,
),
index("index_upsells_selected_products_on_upsell_id").on(table.upsell_id),
],
);
export const UrlRedirects = pgTable(
"url_redirects",
{
uses: integer("uses").default(0),
expires_at: timestamp("expires_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
purchase_id: bigint({ mode: "number" }),
token: varchar("token", { length: 255 }).notNull(),
link_id: bigint({ mode: "number" }),
flags: integer("flags").default(0).notNull(),
installment_id: bigint({ mode: "number" }),
subscription_id: bigint({ mode: "number" }),
preorder_id: bigint({ mode: "number" }),
imported_customer_id: bigint({ mode: "number" }),
rental_first_viewed_at: timestamp("rental_first_viewed_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_url_redirects_on_imported_customer_id").on(
table.imported_customer_id,
),
index("index_url_redirects_on_installment_id_and_imported_customer_id").on(
table.installment_id,
table.imported_customer_id,
),
index("index_url_redirects_on_installment_id_and_purchase_id").on(
table.installment_id,
table.purchase_id,
),
index("index_url_redirects_on_installment_id_and_subscription_id").on(
table.installment_id,
table.subscription_id,
),
index("index_url_redirects_on_preorder_id").on(table.preorder_id),
index("index_url_redirects_on_purchase_id").on(table.purchase_id),
index("index_url_redirects_on_subscription_id").on(table.subscription_id),
uniqueIndex("index_url_redirects_on_token").on(table.token),
],
);
export const UserComplianceInfo = pgTable(
"user_compliance_info",
{
user_id: integer("user_id"),
full_name: varchar("full_name", { length: 255 }),
street_address: varchar("street_address", { length: 255 }),
city: varchar("city", { length: 255 }),
state: varchar("state", { length: 255 }),
zip_code: varchar("zip_code", { length: 255 }),
country: varchar("country", { length: 255 }),
telephone_number: varchar("telephone_number", { length: 255 }),
vertical: varchar("vertical", { length: 255 }),
is_business: boolean("is_business"),
has_sold_before: boolean("has_sold_before"),
individual_tax_id: bytea("individual_tax_id"),
json_data: text("json_data"),
flags: integer("flags").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
business_name: varchar("business_name", { length: 255 }),
business_street_address: varchar("business_street_address", {
length: 255,
}),
business_city: varchar("business_city", { length: 255 }),
business_state: varchar("business_state", { length: 255 }),
business_zip_code: varchar("business_zip_code", { length: 255 }),
business_country: varchar("business_country", { length: 255 }),
business_type: varchar("business_type", { length: 255 }),
business_tax_id: bytea("business_tax_id"),
birthday: date("birthday"),
deleted_at: timestamp("deleted_at"),
dba: varchar("dba", { length: 255 }),
verticals: text("verticals"),
first_name: varchar("first_name", { length: 255 }),
last_name: varchar("last_name", { length: 255 }),
stripe_identity_document_id: varchar("stripe_identity_document_id", {
length: 255,
}),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_user_compliance_info_on_user_id").on(table.user_id)],
);
export const UserComplianceInfoRequests = pgTable(
"user_compliance_info_requests",
{
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
user_id: integer("user_id"),
field_needed: varchar("field_needed", { length: 255 }),
due_at: timestamp("due_at"),
state: varchar("state", { length: 255 }),
provided_at: timestamp("provided_at"),
json_data: text("json_data"),
flags: integer("flags").default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_user_compliance_info_requests_on_user_id_and_state").on(
table.user_id,
table.state,
),
],
);
export const UserTaxForms = pgTable(
"user_tax_forms",
{
user_id: bigint({ mode: "number" }).notNull(),
tax_year: integer("tax_year").notNull(),
tax_form_type: varchar("tax_form_type", { length: 255 }).notNull(),
json_data: text("json_data"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
uniqueIndex(
"index_user_tax_forms_on_user_id_and_tax_year_and_tax_form_type",
).on(table.user_id, table.tax_year, table.tax_form_type),
index("index_user_tax_forms_on_user_id").on(table.user_id),
],
);
export const Users = pgTable(
"users",
{
email: varchar("email", { length: 255 }).default(""),
encrypted_password: varchar("encrypted_password", { length: 128 })
.default("")
.notNull(),
reset_password_token: varchar("reset_password_token", { length: 255 }),
reset_password_sent_at: timestamp("reset_password_sent_at"),
remember_created_at: timestamp("remember_created_at"),
sign_in_count: integer("sign_in_count").default(0),
current_sign_in_at: timestamp("current_sign_in_at"),
last_sign_in_at: timestamp("last_sign_in_at"),
current_sign_in_ip: varchar("current_sign_in_ip", { length: 255 }),
last_sign_in_ip: varchar("last_sign_in_ip", { length: 255 }),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
name: varchar("name", { length: 255 }),
payment_address: varchar("payment_address", { length: 255 }),
confirmed_at: timestamp("confirmed_at"),
confirmation_token: varchar("confirmation_token", { length: 255 }),
confirmation_sent_at: timestamp("confirmation_sent_at"),
unconfirmed_email: varchar("unconfirmed_email", { length: 255 }),
provider: varchar("provider", { length: 255 }),
twitter_user_id: varchar("twitter_user_id", { length: 255 }),
facebook_uid: varchar("facebook_uid", { length: 255 }),
deleted_at: timestamp("deleted_at"),
payment_notification: boolean("payment_notification").default(true),
currency_type: varchar("currency_type", { length: 255 }).default("usd"),
bio: text("bio"),
twitter_handle: varchar("twitter_handle", { length: 255 }),
username: varchar("username", { length: 255 }),
credit_card_id: bigint({ mode: "number" }),
profile_picture_url: varchar("profile_picture_url", { length: 255 }),
country: varchar("country", { length: 255 }),
state: varchar("state", { length: 255 }),
city: varchar("city", { length: 255 }),
zip_code: varchar("zip_code", { length: 255 }),
street_address: varchar("street_address", { length: 255 }),
facebook_access_token: varchar("facebook_access_token", { length: 1024 }),
verified: boolean("verified"),
manage_pages: boolean("manage_pages").default(false),
banned_at: timestamp("banned_at"),
weekly_notification: boolean("weekly_notification").default(true),
external_id: varchar("external_id", { length: 255 }),
account_created_ip: varchar("account_created_ip", { length: 255 }),
twitter_oauth_token: varchar("twitter_oauth_token", { length: 255 }),
twitter_oauth_secret: varchar("twitter_oauth_secret", { length: 255 }),
notification_endpoint: text("notification_endpoint"),
locale: varchar("locale", { length: 255 }).default("en"),
flags: bigint({ mode: "number" }).default(1).notNull(),
google_analytics_id: varchar("google_analytics_id", { length: 255 }),
timezone: varchar("timezone", { length: 255 })
.default("Pacific Time (US & Canada)")
.notNull(),
user_risk_state: varchar("user_risk_state", { length: 255 }),
tos_violation_reason: varchar("tos_violation_reason", { length: 255 }),
kindle_email: varchar("kindle_email", { length: 255 }),
json_data: text("json_data"),
support_email: varchar("support_email", { length: 255 }),
google_analytics_domains: varchar("google_analytics_domains", {
length: 255,
}),
recommendation_type: varchar("recommendation_type", {
length: 255,
}).notNull(),
facebook_pixel_id: varchar("facebook_pixel_id", { length: 191 }),
split_payment_by_cents: integer("split_payment_by_cents"),
last_active_sessions_invalidated_at: timestamp(
"last_active_sessions_invalidated_at",
),
otp_secret_key: varchar("otp_secret_key", { length: 255 }),
facebook_meta_tag: varchar("facebook_meta_tag", { length: 255 }),
tier_state: integer("tier_state").default(0),
orientation_priority_tag: varchar("orientation_priority_tag", {
length: 255,
}),
notification_content_type: varchar("notification_content_type", {
length: 255,
}).default("application/x-www-form-urlencoded"),
google_uid: varchar("google_uid", { length: 255 }),
purchasing_power_parity_limit: integer("purchasing_power_parity_limit"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_users_on_account_created_ip").on(table.account_created_ip),
index("index_users_on_confirmation_token").on(table.confirmation_token),
index("index_users_on_created_at").on(table.created_at),
index("index_users_on_current_sign_in_ip").on(table.current_sign_in_ip),
index("index_users_on_email").on(table.email),
index("index_users_on_external_id").on(table.external_id),
index("index_users_on_facebook_uid").on(table.facebook_uid),
index("index_users_on_google_uid").on(table.google_uid),
index("index_users_on_last_sign_in_ip").on(table.last_sign_in_ip),
index("index_users_on_name").on(table.name),
index("index_users_on_payment_address_and_user_risk_state").on(
table.payment_address,
table.user_risk_state,
),
index("index_users_on_reset_password_token").on(table.reset_password_token),
index("index_users_on_support_email").on(table.support_email),
index("index_users_on_tos_violation_reason").on(table.tos_violation_reason),
index("index_users_on_twitter_oauth_token").on(table.twitter_oauth_token),
index("index_users_on_twitter_user_id").on(table.twitter_user_id),
index("index_users_on_unconfirmed_email").on(table.unconfirmed_email),
index("index_users_on_user_risk_state").on(table.user_risk_state),
index("index_users_on_username").on(table.username),
],
);
export const UtmLinkDrivenSales = pgTable(
"utm_link_driven_sales",
{
utm_link_id: bigint({ mode: "number" }).notNull(),
utm_link_visit_id: bigint({ mode: "number" }).notNull(),
purchase_id: bigint({ mode: "number" }).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_utm_link_driven_sales_on_purchase_id").on(table.purchase_id),
index("index_utm_link_driven_sales_on_utm_link_id").on(table.utm_link_id),
uniqueIndex("idx_on_utm_link_visit_id_purchase_id_c31951f65f").on(
table.utm_link_visit_id,
table.purchase_id,
),
index("index_utm_link_driven_sales_on_utm_link_visit_id").on(
table.utm_link_visit_id,
),
],
);
export const UtmLinkVisits = pgTable(
"utm_link_visits",
{
utm_link_id: bigint({ mode: "number" }).notNull(),
user_id: bigint({ mode: "number" }),
referrer: varchar("referrer", { length: 255 }),
ip_address: varchar("ip_address", { length: 255 }).notNull(),
user_agent: varchar("user_agent", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }).notNull(),
country_code: varchar("country_code", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_utm_link_visits_on_browser_guid").on(table.browser_guid),
index("index_utm_link_visits_on_created_at").on(table.created_at),
index("index_utm_link_visits_on_user_id").on(table.user_id),
index("index_utm_link_visits_on_utm_link_id").on(table.utm_link_id),
],
);
export const UtmLinks = pgTable(
"utm_links",
{
seller_id: bigint({ mode: "number" }).notNull(),
title: varchar("title", { length: 255 }).notNull(),
target_resource_type: varchar("target_resource_type", {
length: 255,
}).notNull(),
target_resource_id: bigint({ mode: "number" }),
permalink: varchar("permalink", { length: 255 }).notNull(),
utm_campaign: varchar("utm_campaign", { length: 200 }).notNull(),
utm_medium: varchar("utm_medium", { length: 200 }).notNull(),
utm_source: varchar("utm_source", { length: 200 }).notNull(),
utm_term: varchar("utm_term", { length: 200 }),
utm_content: varchar("utm_content", { length: 200 }),
first_click_at: timestamp("first_click_at"),
last_click_at: timestamp("last_click_at"),
total_clicks: integer("total_clicks").default(0).notNull(),
unique_clicks: integer("unique_clicks").default(0).notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
disabled_at: timestamp("disabled_at"),
ip_address: varchar("ip_address", { length: 255 }),
browser_guid: varchar("browser_guid", { length: 255 }),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_utm_links_on_deleted_at").on(table.deleted_at),
uniqueIndex("index_utm_links_on_permalink").on(table.permalink),
uniqueIndex("index_utm_links_on_utm_fields_and_target_resource").on(
table.seller_id,
table.utm_source,
table.utm_medium,
table.utm_campaign,
table.utm_term,
table.utm_content,
table.target_resource_type,
table.target_resource_id,
),
index("index_utm_links_on_seller_id").on(table.seller_id),
index("index_utm_links_on_target_resource_type_and_target_resource_id").on(
table.target_resource_type,
table.target_resource_id,
),
index("index_utm_links_on_utm_campaign").on(table.utm_campaign),
],
);
export const VariantCategories = pgTable(
"variant_categories",
{
link_id: integer("link_id"),
deleted_at: timestamp("deleted_at"),
title: varchar("title", { length: 255 }),
flags: integer("flags").default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [index("index_variant_categories_on_link_id").on(table.link_id)],
);
export const Versions = pgTable(
"versions",
{
item_type: varchar("item_type", { length: 191 }).notNull(),
item_id: bigint({ mode: "number" }).notNull(),
event: varchar("event", { length: 191 }).notNull(),
whodunnit: varchar("whodunnit", { length: 191 }),
object: text("object"),
created_at: timestamp("created_at"),
remote_ip: varchar("remote_ip", { length: 191 }),
request_path: text("request_path"),
request_uuid: varchar("request_uuid", { length: 191 }),
object_changes: text("object_changes"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_versions_on_item_type_and_item_id").on(
table.item_type,
table.item_id,
),
],
);
export const VideoFiles = pgTable(
"video_files",
{
record_type: varchar("record_type", { length: 255 }).notNull(),
record_id: bigint({ mode: "number" }).notNull(),
url: varchar("url", { length: 255 }),
filetype: varchar("filetype", { length: 255 }),
width: integer("width"),
height: integer("height"),
duration: integer("duration"),
bitrate: integer("bitrate"),
framerate: integer("framerate"),
size: integer("size"),
flags: integer("flags").default(0),
deleted_at: timestamp("deleted_at"),
deleted_from_cdn_at: timestamp("deleted_from_cdn_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
user_id: bigint({ mode: "number" }).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_video_files_on_record").on(table.record_type, table.record_id),
index("index_video_files_on_user_id").on(table.user_id),
],
);
export const WishlistFollowers = pgTable(
"wishlist_followers",
{
wishlist_id: bigint({ mode: "number" }).notNull(),
follower_user_id: bigint({ mode: "number" }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_wishlist_followers_on_follower_user_id").on(
table.follower_user_id,
),
index("index_wishlist_followers_on_wishlist_id").on(table.wishlist_id),
],
);
export const WishlistProducts = pgTable(
"wishlist_products",
{
wishlist_id: bigint({ mode: "number" }).notNull(),
product_id: bigint({ mode: "number" }).notNull(),
variant_id: bigint({ mode: "number" }),
recurrence: varchar("recurrence", { length: 255 }),
quantity: integer("quantity").notNull(),
rent: boolean("rent").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
deleted_at: timestamp("deleted_at"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_wishlist_products_on_product_id").on(table.product_id),
index("index_wishlist_products_on_variant_id").on(table.variant_id),
index("index_wishlist_products_on_wishlist_id").on(table.wishlist_id),
],
);
export const Wishlists = pgTable(
"wishlists",
{
user_id: bigint({ mode: "number" }).notNull(),
name: varchar("name", { length: 255 }).notNull(),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
followers_last_contacted_at: timestamp("followers_last_contacted_at"),
description: text("description"),
flags: integer("flags").default(0).notNull(),
recommendable: boolean("recommendable").default(false).notNull(),
follower_count: integer("follower_count").default(0).notNull(),
recent_follower_count: integer("recent_follower_count")
.default(0)
.notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_wishlists_on_recommendable_and_recent_follower_count").on(
table.recommendable,
table.recent_follower_count,
),
index("index_wishlists_on_user_id").on(table.user_id),
],
);
export const Workflows = pgTable(
"workflows",
{
name: varchar("name", { length: 1024 }),
seller_id: integer("seller_id"),
link_id: integer("link_id"),
workflow_type: varchar("workflow_type", { length: 255 }),
published_at: timestamp("published_at"),
deleted_at: timestamp("deleted_at"),
created_at: timestamp("created_at"),
updated_at: timestamp("updated_at"),
base_variant_id: integer("base_variant_id"),
json_data: text("json_data"),
first_published_at: timestamp("first_published_at"),
flags: bigint({ mode: "number" }).default(0).notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_workflows_on_base_variant_id").on(table.base_variant_id),
index("index_workflows_on_link_id").on(table.link_id),
index("index_workflows_on_seller_id").on(table.seller_id),
index("index_workflows_on_workflow_type_and_published_at").on(
table.workflow_type,
table.published_at,
),
],
);
export const YearlyStats = pgTable(
"yearly_stats",
{
user_id: bigint({ mode: "number" }).notNull(),
analytics_data: jsonb("analytics_data").notNull(),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [uniqueIndex("index_yearly_stats_on_user_id").on(table.user_id)],
);
export const ZipTaxRates = pgTable(
"zip_tax_rates",
{
combined_rate: numeric("combined_rate", { precision: 8, scale: 7 }),
county_rate: numeric("county_rate", { precision: 8, scale: 7 }),
city_rate: numeric("city_rate", { precision: 8, scale: 7 }),
state: varchar("state", { length: 255 }),
state_rate: numeric("state_rate", { precision: 8, scale: 7 }),
tax_region_code: varchar("tax_region_code", { length: 255 }),
tax_region_name: varchar("tax_region_name", { length: 255 }),
zip_code: varchar("zip_code", { length: 255 }),
created_at: timestamp("created_at").notNull(),
updated_at: timestamp("updated_at").notNull(),
special_rate: numeric("special_rate", { precision: 8, scale: 7 }),
flags: integer("flags").default(0).notNull(),
country: varchar("country", { length: 255 }).notNull(),
user_id: integer("user_id"),
deleted_at: timestamp("deleted_at"),
json_data: text("json_data"),
id: bigint({ mode: "number" })
.primaryKey()
.generatedAlwaysAsIdentity()
.notNull(),
},
(table) => [
index("index_zip_tax_rates_on_user_id").on(table.user_id),
index("index_zip_tax_rates_on_zip_code").on(table.zip_code),
],
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment