Skip to content

Instantly share code, notes, and snippets.

@tomfa
Created October 3, 2023 11:33
Show Gist options
  • Save tomfa/7827442ba58e8e239a6bb7cb4b5d0321 to your computer and use it in GitHub Desktop.
Save tomfa/7827442ba58e8e239a6bb7cb4b5d0321 to your computer and use it in GitHub Desktop.
Lago invoicing modelling
// autogenerated from Lago database model (https://github.com/getlago/lago)
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model active_storage_attachments {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.VarChar
record_type String @db.VarChar
blob_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
record_id String? @db.Uuid
active_storage_blobs active_storage_blobs @relation(fields: [blob_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_c3b3935057")
@@index([blob_id], map: "index_active_storage_attachments_on_blob_id")
}
model active_storage_blobs {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
key String @unique(map: "index_active_storage_blobs_on_key") @db.VarChar
filename String @db.VarChar
content_type String? @db.VarChar
metadata String?
service_name String @db.VarChar
byte_size BigInt
checksum String? @db.VarChar
created_at DateTime @db.Timestamp(6)
active_storage_attachments active_storage_attachments[]
active_storage_variant_records active_storage_variant_records[]
}
model active_storage_variant_records {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
blob_id String @db.Uuid
variation_digest String @db.VarChar
active_storage_blobs active_storage_blobs @relation(fields: [blob_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_993965df05")
@@unique([blob_id, variation_digest], map: "index_active_storage_variant_records_uniqueness")
}
model add_ons {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
name String @db.VarChar
code String @db.VarChar
description String? @db.VarChar
amount_cents BigInt
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
deleted_at DateTime? @db.Timestamp(6)
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_81e3b6abba")
add_ons_taxes add_ons_taxes[]
applied_add_ons applied_add_ons[]
fees fees[]
@@index([deleted_at], map: "index_add_ons_on_deleted_at")
@@index([organization_id], map: "index_add_ons_on_organization_id")
}
model add_ons_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
add_on_id String @db.Uuid
tax_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
add_ons add_ons @relation(fields: [add_on_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_08dfe87131")
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_89e1020aca")
@@unique([add_on_id, tax_id], map: "index_add_ons_taxes_on_add_on_id_and_tax_id")
@@index([add_on_id], map: "index_add_ons_taxes_on_add_on_id")
@@index([tax_id], map: "index_add_ons_taxes_on_tax_id")
}
model applied_add_ons {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
add_on_id String @db.Uuid
customer_id String @db.Uuid
amount_cents BigInt
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_7995206484")
add_ons add_ons @relation(fields: [add_on_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_9c8e276cc0")
fees fees[]
@@index([add_on_id], map: "index_applied_add_ons_on_add_on_id")
@@index([add_on_id, customer_id], map: "index_applied_add_ons_on_add_on_id_and_customer_id")
@@index([customer_id], map: "index_applied_add_ons_on_customer_id")
}
model applied_coupons {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
coupon_id String @db.Uuid
customer_id String @db.Uuid
status Int @default(0)
amount_cents BigInt?
amount_currency String? @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
terminated_at DateTime? @db.Timestamp(6)
percentage_rate Decimal? @db.Decimal(10, 5)
frequency Int @default(0)
frequency_duration Int?
frequency_duration_remaining Int?
credits credits[]
@@index([coupon_id], map: "index_applied_coupons_on_coupon_id")
@@index([customer_id], map: "index_applied_coupons_on_customer_id")
}
model ar_internal_metadata {
key String @id @db.VarChar
value String? @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
}
model billable_metrics {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
name String @db.VarChar
code String @db.VarChar
description String? @db.VarChar
properties Json? @default("{}")
aggregation_type Int
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
field_name String? @db.VarChar
deleted_at DateTime? @db.Timestamp(6)
recurring Boolean @default(false)
weighted_interval billable_metric_weighted_interval?
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_7e8a2f26e5")
charges charges[]
coupon_targets coupon_targets[]
groups groups[]
@@index([deleted_at], map: "index_billable_metrics_on_deleted_at")
@@index([organization_id], map: "index_billable_metrics_on_organization_id")
}
model charges {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
billable_metric_id String? @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
plan_id String? @db.Uuid
amount_currency String? @db.VarChar
charge_model Int @default(0)
properties Json @default("\"{}\"")
deleted_at DateTime? @db.Timestamp(6)
pay_in_advance Boolean @default(false)
min_amount_cents BigInt @default(0)
invoiceable Boolean @default(true)
prorated Boolean @default(false)
plans plans? @relation(fields: [plan_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_7eb0484711")
billable_metrics billable_metrics? @relation(fields: [billable_metric_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_a710519346")
charges_taxes charges_taxes[]
fees fees[]
group_properties group_properties[]
@@index([billable_metric_id], map: "index_charges_on_billable_metric_id")
@@index([deleted_at], map: "index_charges_on_deleted_at")
@@index([plan_id], map: "index_charges_on_plan_id")
}
model charges_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
charge_id String @db.Uuid
tax_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_3ff27d7624")
charges charges @relation(fields: [charge_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_ac146c9541")
@@unique([charge_id, tax_id], map: "index_charges_taxes_on_charge_id_and_tax_id")
@@index([charge_id], map: "index_charges_taxes_on_charge_id")
@@index([tax_id], map: "index_charges_taxes_on_tax_id")
}
model coupon_targets {
id String @id(map: "coupon_plans_pkey") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
coupon_id String @db.Uuid
plan_id String? @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
deleted_at DateTime? @db.Timestamp(6)
billable_metric_id String? @db.Uuid
coupons coupons @relation(fields: [coupon_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_0bb6dcc01f")
billable_metrics billable_metrics? @relation(fields: [billable_metric_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_1454058c96")
plans plans? @relation(fields: [plan_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_de6b3c3138")
@@index([billable_metric_id], map: "index_coupon_targets_on_billable_metric_id")
@@index([coupon_id], map: "index_coupon_targets_on_coupon_id")
@@index([deleted_at], map: "index_coupon_targets_on_deleted_at")
@@index([plan_id], map: "index_coupon_targets_on_plan_id")
}
model coupons {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
name String @db.VarChar
code String? @db.VarChar
status Int @default(0)
terminated_at DateTime? @db.Timestamp(6)
amount_cents BigInt?
amount_currency String? @db.VarChar
expiration Int
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
coupon_type Int @default(0)
percentage_rate Decimal? @db.Decimal(10, 5)
frequency Int @default(0)
frequency_duration Int?
expiration_at DateTime? @db.Timestamp(6)
reusable Boolean @default(true)
limited_plans Boolean @default(false)
deleted_at DateTime? @db.Timestamp(6)
limited_billable_metrics Boolean @default(false)
description String?
coupon_targets coupon_targets[]
@@index([deleted_at], map: "index_coupons_on_deleted_at")
@@index([organization_id], map: "index_coupons_on_organization_id")
}
model credit_note_items {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
credit_note_id String @db.Uuid
fee_id String? @db.Uuid
amount_cents BigInt @default(0)
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
precise_amount_cents Decimal @db.Decimal(30, 5)
credit_notes credit_notes @relation(fields: [credit_note_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_9f22076477")
fees fees? @relation(fields: [fee_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_dea748e529")
@@index([credit_note_id], map: "index_credit_note_items_on_credit_note_id")
@@index([fee_id], map: "index_credit_note_items_on_fee_id")
}
model credit_notes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
invoice_id String @db.Uuid
sequential_id Int
number String @db.VarChar
credit_amount_cents BigInt @default(0)
credit_amount_currency String @db.VarChar
credit_status Int?
balance_amount_cents BigInt @default(0)
balance_amount_currency String @default("0") @db.VarChar
reason Int
file String? @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
total_amount_cents BigInt @default(0)
total_amount_currency String @db.VarChar
refund_amount_cents BigInt @default(0)
refund_amount_currency String? @db.VarChar
refund_status Int?
voided_at DateTime? @db.Timestamp(6)
description String?
taxes_amount_cents BigInt @default(0)
refunded_at DateTime? @db.Timestamp(6)
issuing_date DateTime @db.Date
status Int @default(1)
coupons_adjustment_amount_cents BigInt @default(0)
precise_coupons_adjustment_amount_cents Decimal @default(0.0) @db.Decimal(30, 5)
precise_taxes_amount_cents Decimal @default(0.0) @db.Decimal(30, 5)
taxes_rate Float @default(0.0)
credit_note_items credit_note_items[]
invoices invoices @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_4117574b51")
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_5cb67dee79")
credit_notes_taxes credit_notes_taxes[]
credits credits[]
refunds refunds[]
@@index([customer_id], map: "index_credit_notes_on_customer_id")
@@index([invoice_id], map: "index_credit_notes_on_invoice_id")
}
model credit_notes_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
credit_note_id String @db.Uuid
tax_id String @db.Uuid
tax_description String? @db.VarChar
tax_code String @db.VarChar
tax_name String @db.VarChar
tax_rate Float @default(0.0)
amount_cents BigInt @default(0)
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
base_amount_cents BigInt @default(0)
credit_notes credit_notes @relation(fields: [credit_note_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_25232a0ec3")
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_626209b8d2")
@@unique([credit_note_id, tax_id], map: "index_credit_notes_taxes_on_credit_note_id_and_tax_id")
@@index([credit_note_id], map: "index_credit_notes_taxes_on_credit_note_id")
@@index([tax_id], map: "index_credit_notes_taxes_on_tax_id")
}
model credits {
invoice_id String? @db.Uuid
applied_coupon_id String? @db.Uuid
amount_cents BigInt
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
credit_note_id String? @db.Uuid
before_taxes Boolean @default(false)
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
applied_coupons applied_coupons? @relation(fields: [applied_coupon_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_1db0057d9b")
credit_notes credit_notes? @relation(fields: [credit_note_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_310fcb3585")
invoices invoices? @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_521b5240ed")
@@index([applied_coupon_id], map: "index_credits_on_applied_coupon_id")
@@index([credit_note_id], map: "index_credits_on_credit_note_id")
@@index([invoice_id], map: "index_credits_on_invoice_id")
}
model customer_metadata {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
key String @db.VarChar
value String @db.VarChar
display_in_invoice Boolean @default(false)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_195153290d")
@@unique([customer_id, key], map: "index_customer_metadata_on_customer_id_and_key")
@@index([customer_id], map: "index_customer_metadata_on_customer_id")
}
/// This table contains check constraints and requires additional setup for migrations. Visit https://pris.ly/d/check-constraints for more info.
model customers {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
external_id String @db.VarChar
name String? @db.VarChar
organization_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
country String? @db.VarChar
address_line1 String? @db.VarChar
address_line2 String? @db.VarChar
state String? @db.VarChar
zipcode String? @db.VarChar
email String? @db.VarChar
city String? @db.VarChar
url String? @db.VarChar
phone String? @db.VarChar
logo_url String? @db.VarChar
legal_name String? @db.VarChar
legal_number String? @db.VarChar
vat_rate Float?
payment_provider String? @db.VarChar
slug String? @db.VarChar
sequential_id BigInt?
currency String? @db.VarChar
invoice_grace_period Int?
timezone String? @db.VarChar
deleted_at DateTime? @db.Timestamp(6)
document_locale String? @db.VarChar
tax_identification_number String? @db.VarChar
net_payment_term Int?
external_salesforce_id String? @db.VarChar
applied_add_ons applied_add_ons[]
credit_notes credit_notes[]
customer_metadata customer_metadata[]
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_58234c715e")
customers_taxes customers_taxes[]
events events[]
invoices invoices[]
payment_provider_customers payment_provider_customers[]
quantified_events quantified_events[]
subscriptions subscriptions[]
wallets wallets[]
@@index([deleted_at], map: "index_customers_on_deleted_at")
@@index([organization_id], map: "index_customers_on_organization_id")
}
model customers_taxes {
id String @id(map: "customers_tax_rates_pkey") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
tax_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_0d2be3d72c")
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_e86903e081")
@@unique([customer_id, tax_id], map: "index_customers_taxes_on_customer_id_and_tax_id")
@@index([customer_id], map: "index_customers_taxes_on_customer_id")
@@index([tax_id], map: "index_customers_taxes_on_tax_id")
}
model events {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
customer_id String @db.Uuid
transaction_id String @db.VarChar
code String @db.VarChar
properties Json @default("{}")
timestamp DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
metadata Json @default("{}")
subscription_id String? @db.Uuid
deleted_at DateTime? @db.Timestamp(6)
quantified_event_id String? @db.Uuid
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_163b5130b5")
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_64995045bd")
subscriptions subscriptions? @relation(fields: [subscription_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_aae99c2073")
@@unique([subscription_id, transaction_id], map: "index_events_on_subscription_id_and_transaction_id")
@@index([customer_id], map: "index_events_on_customer_id")
@@index([deleted_at], map: "index_events_on_deleted_at")
@@index([organization_id], map: "index_events_on_organization_id")
@@index([organization_id, code], map: "index_events_on_organization_id_and_code")
@@index([properties(ops: JsonbPathOps)], map: "index_events_on_properties", type: Gin)
@@index([quantified_event_id], map: "index_events_on_quantified_event_id")
@@index([subscription_id], map: "index_events_on_subscription_id")
}
model fees {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
invoice_id String? @db.Uuid
charge_id String? @db.Uuid
subscription_id String? @db.Uuid
amount_cents BigInt
amount_currency String @db.VarChar
taxes_amount_cents BigInt
taxes_rate Float @default(0.0)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
units Decimal @default(0.0) @db.Decimal
applied_add_on_id String? @db.Uuid
properties Json @default("{}")
fee_type Int?
invoiceable_type String? @db.VarChar
invoiceable_id String? @db.Uuid
events_count Int?
group_id String? @db.Uuid
pay_in_advance_event_id String? @db.Uuid
payment_status Int @default(0)
succeeded_at DateTime? @db.Timestamp(6)
failed_at DateTime? @db.Timestamp(6)
refunded_at DateTime? @db.Timestamp(6)
true_up_parent_fee_id String? @db.Uuid
add_on_id String? @db.Uuid
description String? @db.VarChar
unit_amount_cents BigInt @default(0)
pay_in_advance Boolean @default(false)
precise_coupons_amount_cents Decimal @default(0.0) @db.Decimal(30, 5)
total_aggregated_units Decimal? @db.Decimal
credit_note_items credit_note_items[]
charges charges? @relation(fields: [charge_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_085d1cc97b")
fees fees? @relation("feesTofees", fields: [true_up_parent_fee_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_257af22645")
other_fees fees[] @relation("feesTofees")
subscriptions subscriptions? @relation(fields: [subscription_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_2ea4db3a4c")
applied_add_ons applied_add_ons? @relation(fields: [applied_add_on_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_34ab152115")
add_ons add_ons? @relation(fields: [add_on_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_6023b3f2dd")
groups groups? @relation(fields: [group_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_b50dc82c1e")
invoices invoices? @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_eaca9421be")
fees_taxes fees_taxes[]
@@index([add_on_id], map: "index_fees_on_add_on_id")
@@index([applied_add_on_id], map: "index_fees_on_applied_add_on_id")
@@index([charge_id], map: "index_fees_on_charge_id")
@@index([group_id], map: "index_fees_on_group_id")
@@index([invoice_id], map: "index_fees_on_invoice_id")
@@index([invoiceable_type, invoiceable_id], map: "index_fees_on_invoiceable")
@@index([subscription_id], map: "index_fees_on_subscription_id")
@@index([true_up_parent_fee_id], map: "index_fees_on_true_up_parent_fee_id")
}
model fees_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
fee_id String @db.Uuid
tax_id String @db.Uuid
tax_description String? @db.VarChar
tax_code String @db.VarChar
tax_name String @db.VarChar
tax_rate Float @default(0.0)
amount_cents BigInt @default(0)
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
fees fees @relation(fields: [fee_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_745b4ca7dd")
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_f98413d404")
@@index([fee_id], map: "index_fees_taxes_on_fee_id")
@@index([tax_id], map: "index_fees_taxes_on_tax_id")
}
model group_properties {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
charge_id String @db.Uuid
group_id String @db.Uuid
values Json @default("{}")
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
deleted_at DateTime? @db.Timestamp(6)
charges charges @relation(fields: [charge_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fk_rails_3acf9e789c")
groups groups @relation(fields: [group_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fk_rails_a2d2cb3819")
@@unique([charge_id, group_id], map: "index_group_properties_on_charge_id_and_group_id")
@@index([charge_id], map: "index_group_properties_on_charge_id")
@@index([deleted_at], map: "index_group_properties_on_deleted_at")
@@index([group_id], map: "index_group_properties_on_group_id")
}
model groups {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
billable_metric_id String @db.Uuid
parent_group_id String? @db.Uuid
key String @db.VarChar
value String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
deleted_at DateTime? @db.Timestamp(6)
fees fees[]
group_properties group_properties[]
billable_metrics billable_metrics @relation(fields: [billable_metric_id], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fk_rails_34b5ee1894")
groups groups? @relation("groupsTogroups", fields: [parent_group_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_7886e1bc34")
other_groups groups[] @relation("groupsTogroups")
quantified_events quantified_events[]
@@index([billable_metric_id], map: "index_groups_on_billable_metric_id")
@@index([deleted_at], map: "index_groups_on_deleted_at")
@@index([parent_group_id], map: "index_groups_on_parent_group_id")
}
model invites {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
membership_id String? @db.Uuid
email String @db.VarChar
token String @unique(map: "index_invites_on_token") @db.VarChar
status Int @default(0)
accepted_at DateTime? @db.Timestamp(6)
revoked_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
memberships memberships? @relation(fields: [membership_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_c71f4b2026")
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_dd342449a6")
@@index([membership_id], map: "index_invites_on_membership_id")
@@index([organization_id], map: "index_invites_on_organization_id")
}
model invoice_metadata {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
invoice_id String @db.Uuid
key String @db.VarChar
value String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
invoices invoices @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_8bb5b094c4")
@@unique([invoice_id, key], map: "index_invoice_metadata_on_invoice_id_and_key")
@@index([invoice_id], map: "index_invoice_metadata_on_invoice_id")
}
model invoice_subscriptions {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
invoice_id String @db.Uuid
subscription_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
recurring Boolean?
timestamp DateTime? @db.Timestamp(6)
from_datetime DateTime? @db.Timestamp(6)
to_datetime DateTime? @db.Timestamp(6)
charges_from_datetime DateTime? @db.Timestamp(6)
charges_to_datetime DateTime? @db.Timestamp(6)
invoices invoices @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_88349fc20a")
subscriptions subscriptions @relation(fields: [subscription_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_90d93bd016")
@@index([invoice_id], map: "index_invoice_subscriptions_on_invoice_id")
@@index([subscription_id], map: "index_invoice_subscriptions_on_subscription_id")
}
/// This table contains check constraints and requires additional setup for migrations. Visit https://pris.ly/d/check-constraints for more info.
model invoices {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
issuing_date DateTime? @db.Date
taxes_amount_cents BigInt @default(0)
total_amount_cents BigInt @default(0)
invoice_type Int @default(0)
payment_status Int @default(0)
number String @default("") @db.VarChar
sequential_id Int?
file String? @db.VarChar
customer_id String? @db.Uuid
taxes_rate Float @default(0.0)
status Int @default(1)
timezone String @default("UTC") @db.VarChar
payment_attempts Int @default(0)
ready_for_payment_processing Boolean @default(true)
organization_id String @db.Uuid
version_number Int @default(3)
currency String? @db.VarChar
fees_amount_cents BigInt @default(0)
coupons_amount_cents BigInt @default(0)
credit_notes_amount_cents BigInt @default(0)
prepaid_credit_amount_cents BigInt @default(0)
sub_total_excluding_taxes_amount_cents BigInt @default(0)
sub_total_including_taxes_amount_cents BigInt @default(0)
payment_due_date DateTime? @db.Date
net_payment_term Int @default(0)
credit_notes credit_notes[]
credits credits[]
fees fees[]
invoice_metadata invoice_metadata[]
invoice_subscriptions invoice_subscriptions[]
customers customers? @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_0d349e632f")
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_3a303bf667")
invoices_taxes invoices_taxes[]
payments payments[]
wallet_transactions wallet_transactions[]
@@index([customer_id], map: "index_invoices_on_customer_id")
@@index([organization_id], map: "index_invoices_on_organization_id")
}
model invoices_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
invoice_id String @db.Uuid
tax_id String @db.Uuid
tax_description String? @db.VarChar
tax_code String @db.VarChar
tax_name String @db.VarChar
tax_rate Float @default(0.0)
amount_cents BigInt @default(0)
amount_currency String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
fees_amount_cents BigInt @default(0)
invoices invoices @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_22af6c6d28")
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_6e148ccbb1")
@@index([invoice_id], map: "index_invoices_taxes_on_invoice_id")
@@index([tax_id], map: "index_invoices_taxes_on_tax_id")
}
model memberships {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
user_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
role Int @default(0)
status Int @default(0)
revoked_at DateTime? @db.Timestamp(6)
invites invites[]
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_64267aab58")
users users @relation(fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_99326fb65d")
@@index([organization_id], map: "index_memberships_on_organization_id")
@@index([user_id], map: "index_memberships_on_user_id")
}
/// This table contains check constraints and requires additional setup for migrations. Visit https://pris.ly/d/check-constraints for more info.
model organizations {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
name String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
api_key String? @unique(map: "index_organizations_on_api_key") @db.VarChar
webhook_url String? @db.VarChar
vat_rate Float @default(0.0)
country String? @db.VarChar
address_line1 String? @db.VarChar
address_line2 String? @db.VarChar
state String? @db.VarChar
zipcode String? @db.VarChar
email String? @db.VarChar
city String? @db.VarChar
logo String? @db.VarChar
legal_name String? @db.VarChar
legal_number String? @db.VarChar
invoice_footer String?
invoice_grace_period Int @default(0)
timezone String @default("UTC") @db.VarChar
document_locale String @default("en") @db.VarChar
email_settings String[] @default([]) @db.VarChar
tax_identification_number String? @db.VarChar
net_payment_term Int @default(0)
add_ons add_ons[]
billable_metrics billable_metrics[]
customers customers[]
events events[]
invites invites[]
invoices invoices[]
memberships memberships[]
payment_providers payment_providers[]
plans plans[]
taxes taxes[]
webhook_endpoints webhook_endpoints[]
}
model password_resets {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
user_id String @db.Uuid
token String @unique(map: "index_password_resets_on_token") @db.VarChar
expire_at DateTime @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
users users @relation(fields: [user_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_526379cd99")
@@index([user_id], map: "index_password_resets_on_user_id")
}
model payment_provider_customers {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
payment_provider_id String? @db.Uuid
type String @db.VarChar
provider_customer_id String? @db.VarChar
settings Json @default("{}")
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
payment_providers payment_providers? @relation(fields: [payment_provider_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_50d46d3679")
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_86676be631")
refunds refunds[]
@@unique([customer_id, type], map: "index_payment_provider_customers_on_customer_id_and_type")
@@index([payment_provider_id], map: "index_payment_provider_customers_on_payment_provider_id")
@@index([provider_customer_id], map: "index_payment_provider_customers_on_provider_customer_id")
}
model payment_providers {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
type String @db.VarChar
secrets String? @db.VarChar
settings Json @default("{}")
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
payment_provider_customers payment_provider_customers[]
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_26be2f764d")
payments payments[]
refunds refunds[]
@@index([organization_id], map: "index_payment_providers_on_organization_id")
}
model payments {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
invoice_id String @db.Uuid
payment_provider_id String? @db.Uuid
payment_provider_customer_id String? @db.Uuid
amount_cents BigInt
amount_currency String @db.VarChar
provider_payment_id String @db.VarChar
status String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
invoices invoices @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_62d18ea517")
payment_providers payment_providers? @relation(fields: [payment_provider_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_84f4587409")
refunds refunds[]
@@index([invoice_id], map: "index_payments_on_invoice_id")
@@index([payment_provider_customer_id], map: "index_payments_on_payment_provider_customer_id")
@@index([payment_provider_id], map: "index_payments_on_payment_provider_id")
}
model plans {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
name String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
code String @db.VarChar
interval Int
description String? @db.VarChar
amount_cents BigInt
amount_currency String @db.VarChar
trial_period Float?
pay_in_advance Boolean @default(false)
bill_charges_monthly Boolean?
parent_id String? @db.Uuid
deleted_at DateTime? @db.Timestamp(6)
pending_deletion Boolean @default(false)
invoice_display_name String? @db.VarChar
charges charges[]
coupon_targets coupon_targets[]
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_216ac8a975")
plans plans? @relation("plansToplans", fields: [parent_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_cbf700aeb8")
other_plans plans[] @relation("plansToplans")
plans_taxes plans_taxes[]
subscriptions subscriptions[]
@@index([deleted_at], map: "index_plans_on_deleted_at")
@@index([organization_id], map: "index_plans_on_organization_id")
@@index([parent_id], map: "index_plans_on_parent_id")
}
model plans_taxes {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
plan_id String @db.Uuid
tax_id String @db.Uuid
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
taxes taxes @relation(fields: [tax_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_9c704027e2")
plans plans @relation(fields: [plan_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_bacde7a063")
@@unique([plan_id, tax_id], map: "index_plans_taxes_on_plan_id_and_tax_id")
@@index([plan_id], map: "index_plans_taxes_on_plan_id")
@@index([tax_id], map: "index_plans_taxes_on_tax_id")
}
model quantified_events {
id String @id(map: "persisted_metrics_pkey") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
external_subscription_id String @db.VarChar
external_id String? @db.VarChar
added_at DateTime @db.Timestamp(6)
removed_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
billable_metric_id String? @db.Uuid
properties Json @default("{}")
deleted_at DateTime? @db.Timestamp(6)
group_id String? @db.Uuid
groups groups? @relation(fields: [group_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_3926855f12")
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_3da4e569a9")
@@index([billable_metric_id], map: "index_quantified_events_on_billable_metric_id")
@@index([customer_id], map: "index_quantified_events_on_customer_id")
@@index([deleted_at], map: "index_quantified_events_on_deleted_at")
@@index([external_id], map: "index_quantified_events_on_external_id")
@@index([group_id], map: "index_quantified_events_on_group_id")
@@index([customer_id, external_subscription_id, billable_metric_id], map: "index_search_quantified_events")
}
model refunds {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
payment_id String @db.Uuid
credit_note_id String @db.Uuid
payment_provider_id String? @db.Uuid
payment_provider_customer_id String @db.Uuid
amount_cents BigInt @default(0)
amount_currency String @db.VarChar
status String @db.VarChar
provider_refund_id String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
payments payments @relation(fields: [payment_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_25267b0e17")
payment_providers payment_providers? @relation(fields: [payment_provider_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_2dc6171f57")
credit_notes credit_notes @relation(fields: [credit_note_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_3f7be5debc")
payment_provider_customers payment_provider_customers @relation(fields: [payment_provider_customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_75577c354e")
@@index([credit_note_id], map: "index_refunds_on_credit_note_id")
@@index([payment_id], map: "index_refunds_on_payment_id")
@@index([payment_provider_customer_id], map: "index_refunds_on_payment_provider_customer_id")
@@index([payment_provider_id], map: "index_refunds_on_payment_provider_id")
}
model schema_migrations {
version String @id @db.VarChar
}
model subscriptions {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
plan_id String @db.Uuid
status Int
canceled_at DateTime? @db.Timestamp(6)
terminated_at DateTime? @db.Timestamp(6)
started_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
previous_subscription_id String? @db.Uuid
name String? @db.VarChar
external_id String @db.VarChar
billing_time Int @default(0)
subscription_at DateTime? @db.Timestamp(6)
ending_at DateTime? @db.Timestamp(6)
events events[]
fees fees[]
invoice_subscriptions invoice_subscriptions[]
plans plans @relation(fields: [plan_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_63d3df128b")
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_66eb6b32c1")
@@index([customer_id], map: "index_subscriptions_on_customer_id")
@@index([external_id], map: "index_subscriptions_on_external_id")
@@index([plan_id], map: "index_subscriptions_on_plan_id")
}
model taxes {
id String @id(map: "tax_rates_pkey") @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
description String? @db.VarChar
code String @db.VarChar
name String @db.VarChar
rate Float @default(0.0)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
applied_to_organization Boolean @default(false)
add_ons_taxes add_ons_taxes[]
charges_taxes charges_taxes[]
credit_notes_taxes credit_notes_taxes[]
customers_taxes customers_taxes[]
fees_taxes fees_taxes[]
invoices_taxes invoices_taxes[]
plans_taxes plans_taxes[]
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_23975f5a47")
@@unique([code, organization_id], map: "index_taxes_on_code_and_organization_id")
@@index([organization_id], map: "index_taxes_on_organization_id")
}
model users {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
email String? @db.VarChar
password_digest String? @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
memberships memberships[]
password_resets password_resets[]
}
model versions {
id BigInt @id @default(autoincrement())
item_type String @db.VarChar
item_id String @db.VarChar
event String @db.VarChar
whodunnit String? @db.VarChar
object Json?
object_changes Json?
created_at DateTime? @db.Timestamp(6)
@@index([item_type, item_id], map: "index_versions_on_item_type_and_item_id")
}
model wallet_transactions {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
wallet_id String @db.Uuid
transaction_type Int
status Int
amount Decimal @default(0.0) @db.Decimal(30, 5)
credit_amount Decimal @default(0.0) @db.Decimal(30, 5)
settled_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
invoice_id String? @db.Uuid
invoices invoices? @relation(fields: [invoice_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_01a4c0c7db")
wallets wallets @relation(fields: [wallet_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_d07bc24ce3")
@@index([invoice_id], map: "index_wallet_transactions_on_invoice_id")
@@index([wallet_id], map: "index_wallet_transactions_on_wallet_id")
}
model wallets {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
customer_id String @db.Uuid
status Int
name String? @db.VarChar
rate_amount Decimal @default(0.0) @db.Decimal(30, 5)
credits_balance Decimal @default(0.0) @db.Decimal(30, 5)
consumed_credits Decimal @default(0.0) @db.Decimal(30, 5)
expiration_at DateTime? @db.Timestamp(6)
last_balance_sync_at DateTime? @db.Timestamp(6)
last_consumed_credit_at DateTime? @db.Timestamp(6)
terminated_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
balance_cents BigInt @default(0)
balance_currency String @db.VarChar
consumed_amount_cents BigInt @default(0)
consumed_amount_currency String @db.VarChar
wallet_transactions wallet_transactions[]
customers customers @relation(fields: [customer_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_2b35eef34b")
@@index([customer_id], map: "index_wallets_on_customer_id")
}
model webhook_endpoints {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
organization_id String @db.Uuid
webhook_url String @db.VarChar
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
signature_algo Int @default(0)
organizations organizations @relation(fields: [organization_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_21808fa528")
webhooks webhooks[]
@@unique([webhook_url, organization_id], map: "index_webhook_endpoints_on_webhook_url_and_organization_id")
@@index([organization_id], map: "index_webhook_endpoints_on_organization_id")
}
model webhooks {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
object_id String? @db.Uuid
object_type String? @db.VarChar
status Int @default(0)
retries Int @default(0)
http_status Int?
endpoint String? @db.VarChar
webhook_type String? @db.VarChar
payload Json? @db.Json
response Json? @db.Json
last_retried_at DateTime? @db.Timestamp(6)
created_at DateTime @db.Timestamp(6)
updated_at DateTime @db.Timestamp(6)
webhook_endpoint_id String? @db.Uuid
webhook_endpoints webhook_endpoints? @relation(fields: [webhook_endpoint_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "fk_rails_20cc0de4c7")
@@index([webhook_endpoint_id], map: "index_webhooks_on_webhook_endpoint_id")
}
enum billable_metric_weighted_interval {
seconds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment