forked from Cap-go/capgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_replicate.ts
More file actions
68 lines (54 loc) · 1.87 KB
/
add_replicate.ts
File metadata and controls
68 lines (54 loc) · 1.87 KB
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
import { createClient } from 'https://esm.sh/@supabase/supabase-js'
import type { Database } from '../supabase/functions/_backend/utils/supabase.types.ts'
const supabaseUrl = 'https://sb.capgo.app'
const supabaseServiceRole = '****'
const ids = []
async function fetchAllIds(supabase: ReturnType<typeof createClient<Database>>) {
let allIds: number[] = []
let lastId = 0
const pageSize = 1000
while (true) {
const { data, error } = await supabase
.from('app_versions')
.select('*')
.order('id', { ascending: true })
.gt('id', lastId)
.limit(pageSize)
if (error) {
console.error('Error fetching data:', error)
return []
}
if (data.length === 0) {
break
}
allIds = allIds.concat(data.map(item => item.id))
lastId = data[data.length - 1].id
if (data.length < pageSize) {
break
}
}
return allIds
}
function generateInsertQuery(idsToInsert: number[]): string {
const values = idsToInsert.map(id => `(${id})`).join(', ')
return `INSERT INTO devices_override (id) VALUES ${values};`
}
async function main() {
const supabase = createClient<Database>(supabaseUrl, supabaseServiceRole, {
auth: {
autoRefreshToken: false,
persistSession: false,
detectSessionInUrl: false,
},
})
const idsInSupabase = await fetchAllIds(supabase)
const idsSet = new Set(ids.map(item => item.id))
const idsInSupabaseNotInIds = idsInSupabase.filter(obj => !idsSet.has(obj.id))
console.log('IDs in Supabase but not in ids array:', idsInSupabaseNotInIds)
console.log('Total IDs in Supabase:', idsInSupabase.length)
console.log('Total IDs in ids array:', ids.length)
console.log('Total IDs in Supabase but not in ids array:', idsInSupabaseNotInIds.length)
const insertQuery = generateInsertQuery(idsInSupabaseNotInIds)
console.log('SQL Insert Query:', insertQuery)
}
await main()