Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add script, fix schema comment

Steven Teyfb67dbc8d156
diff --git a/apps/web/scripts/sync-conversions.ts b/apps/web/scripts/sync-conversions.ts
new file mode 100644
index 0000000000..f75ec9dcb4
--- /dev/null
+++ b/apps/web/scripts/sync-conversions.ts
@@ -0,0 +1,37 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+const data: { [key: number]: string[] } = {};
+
+async function main() {
+ Papa.parse(fs.createReadStream("link_id_unique_customers.csv", "utf-8"), {
+ header: true,
+ step: (result: { data: { link_id: string; unique_customers: number } }) => {
+ data[result.data.unique_customers] = (
+ data[result.data.unique_customers] || []
+ ).concat(result.data.link_id);
+ },
+ complete: async () => {
+ const dataArray = Object.entries(data).map(([conversions, linkIds]) => ({
+ conversions: parseInt(conversions),
+ linkIds,
+ }));
+ console.table(dataArray);
+
+ for (const { conversions, linkIds } of dataArray) {
+ await prisma.link.updateMany({
+ where: {
+ id: { in: linkIds },
+ },
+ data: {
+ conversions,
+ },
+ });
+ }
+ },
+ });
+}
+
+main();
diff --git a/packages/prisma/schema/link.prisma b/packages/prisma/schema/link.prisma
index 790c439f17..43b7be9add 100644
--- a/packages/prisma/schema/link.prisma
+++ b/packages/prisma/schema/link.prisma
@@ -58,7 +58,7 @@ model Link {
leads Int @default(0) // number of leads
conversions Int @default(0) // number of leads that converted to sales
sales Int @default(0) // number of sales (includes recurring sales)
- saleAmount Int @default(0) // Deprecated: drop this column after migration is complete + backwards compatibility is added
+ saleAmount Int @default(0) // total revenue from sales (in cents)
lastClicked DateTime? // when the link was last clicked
createdAt DateTime @default(now())