-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwait-shadow-db-setup.js
81 lines (63 loc) · 1.65 KB
/
wait-shadow-db-setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { PrismaClient } = require("@prisma/client");
const client = new PrismaClient({
datasources: {
db: {
url: process.env.SHADOW_DATABASE_URL,
},
},
});
const waitingMessages = {
2: `You love Remix.Run ? Check the doc
💿 https://remix.run/docs
`,
4: `Still love Remix.Run ? Join the Discord
💿 https://discord.com/invite/remix
`,
6: `I love Supabase, and you ?
🔨 https://supabase.com/docs
`,
8: `You love it ? Join the Discord
🔨 https://discord.supabase.com/
`,
};
const MAX_ATTEMPTS = 60; // increase if your computer or Internet connection is slow 😅
let attempt = 1;
console.log(
"\x1b[35m%s\x1b[0m",
`☕️ Take a coffee break... I'm running docker-compose to setup supabase-shadow-db
This step is required to use prisma migrate
👉 https://www.prisma.io/docs/concepts/components/prisma-migrate/shadow-database
`
);
const wait = setInterval(() => {
if (attempt > MAX_ATTEMPTS) {
clearInterval(wait);
console.error(
"\x1b[31m%s\x1b[0m",
"👾 supabase-shadow-db takes too many time to setup.\nPlease retry or open an issue."
);
return;
}
client
.$connect()
.then(() => {
clearInterval(wait);
console.log("\x1b[32m%s\x1b[0m", "🥳 supabase-shadow-db is ready");
})
.catch(() => {
console.log(
"\x1b[33m%s\x1b[0m",
"⏱ Waiting for supabase-shadow-db to finish setup ..."
);
const waitingMessage = waitingMessages[attempt];
if (waitingMessage) {
console.log(
"\x1b[34m%s\x1b[0m",
`
${waitingMessage}
`
);
}
});
attempt++;
}, 2_000);