-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Old version updated] Sync Stripe with Database Version 2 #1063
Comments
We have to update the Prisma Schema to make it workThe documentation comparison between the old and new source code focuses on the Prisma schema for a database application. This comparison highlights the structural changes made to the database schema and their implications. Overview of SchemaBoth versions of the source code define a database schema using Prisma, aimed at a PostgreSQL database. The schema includes definitions for various models such as Key Changes
Implications of the Changes
Unchanged Aspects
ConclusionThe modifications from the old to the new source code represent a focused enhancement of the application's user and subscription management capabilities, specifically through the integration of Stripe and a clearer association between users and their subscriptions. These changes are indicative of an application's evolution to incorporate more complex billing and subscription management features directly within its data model, improving overall functionality and user experience. Complete New Source Codegenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
enum Role {
ADMIN
OWNER
MEMBER
}
model Account {
id String @id @default(uuid())
userId String
type String
provider String
providerAccountId String
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
}
model Session {
id String @id @default(uuid())
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
model VerificationToken {
identifier String
token String @unique
expires DateTime
@@unique([identifier, token])
}
model User {
id String @id @default(uuid())
name String
email String @unique
emailVerified DateTime?
password String?
image String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
invalid_login_attempts Int @default(0)
lockedAt DateTime?
stripeCustomerId String? // Ajoutez cette ligne
teamMembers TeamMember[]
accounts Account[]
sessions Session[]
invitations Invitation[]
subscriptions Subscription[]
}
model Team {
id String @id @default(uuid())
name String
slug String @unique
domain String? @unique
defaultRole Role @default(MEMBER)
billingId String?
billingProvider String?
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
members TeamMember[]
invitations Invitation[]
apiKeys ApiKey[]
}
model TeamMember {
id String @id @default(uuid())
teamId String
userId String
role Role @default(MEMBER)
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([teamId, userId])
@@index([userId])
}
model Invitation {
id String @id @default(uuid())
teamId String
email String?
role Role @default(MEMBER)
token String @unique
expires DateTime
invitedBy String
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
sentViaEmail Boolean @default(true)
allowedDomains String[] @default([])
user User @relation(fields: [invitedBy], references: [id], onDelete: Cascade)
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
@@unique([teamId, email])
}
model PasswordReset {
id Int @id @default(autoincrement())
email String
token String @unique
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
expiresAt DateTime
}
model ApiKey {
id String @id @default(uuid())
name String
teamId String
hashedKey String @unique
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
expiresAt DateTime?
lastUsedAt DateTime?
team Team @relation(fields: [teamId], references: [id], onDelete: Cascade)
}
model Subscription {
id String @id
customerId String
priceId String
active Boolean @default(false)
startDate DateTime
endDate DateTime
cancelAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
userId String
User User? @relation(fields: [userId], references: [id])
@@index([customerId])
}
model Service {
id String @id @default(uuid())
description String
features String[]
image String
name String
created DateTime
createdAt DateTime @default(now())
updatedAt DateTime @default(now())
Price Price[]
}
model Price {
id String @id @default(uuid())
billingScheme String
currency String
serviceId String
amount Int?
metadata Json
type String
created DateTime
service Service @relation(fields: [serviceId], references: [id], onDelete: Cascade)
}
|
Thank you @KazeroG |
+1 much needed update |
Any update on this? |
This source code demonstrates how to synchronize data from Stripe, a payment processing platform, with a local database using Prisma, an ORM (Object Relational Mapping) tool. The script performs several key operations, including fetching data from Stripe, mapping Stripe customers to local users, updating user information with Stripe customer IDs, and seeding the local database with Stripe products, prices, and subscriptions. Below is a detailed breakdown of the code, including its structure, functions, and purpose.
Overview
sync
asynchronous function orchestrates the entire synchronization process.Detailed Documentation
Prisma Client Initialization
@prisma/client
package.Stripe Instance Creation
STRIPE_SECRET_KEY
and sets the API version to'2023-10-16'
.Synchronization Function (
sync
)Helper Functions
getStripeInstance
: Ensures that the Stripe secret key is set and returns the Stripe instance.fetchStripeData
: Fetches active products, prices, subscriptions, and customers from Stripe.mapUsersToCustomers
: Maps local user records to Stripe customers based on email.updateUsersWithStripeCustomerId
: Updates local users with their corresponding Stripe customer IDs.performDatabaseOperations
: Orchestrates database operations including cleaning up old data and seeding with new data from Stripe.cleanup
,seedServices
,seedPrices
,seedSubscriptions
: Helper functions to perform specific database seeding operations.printStats
: Logs the count of products, prices, and subscriptions synced to the database.Error Handling
Complete New Source Code
The text was updated successfully, but these errors were encountered: