-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.js
67 lines (50 loc) · 2.39 KB
/
message.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
// import { createClient } from '@supabase/supabase-js'
const { createClient } = require('@supabase/supabase-js')
require('dotenv').config()
const { faker } = require('@faker-js/faker');
(async () => {
try {
const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY
)
// var table = 'relationships.dev'
// const email = '[email protected]'
// const statuses = ['Accepted']
// var data1 = (await supabase.from(table)
// .select(`user1 (id, first_name, last_name, avatar_url, cover_url, title, city, email, phone_number, country, birthday, description)`)
// .eq('user2', email).in('status', statuses)).data
// data1 = JSON.parse(JSON.stringify(data1).split('"user1":').join('"friend":'))
// var data2 = (await supabase.from(table)
// .select(`user2 (id, first_name, last_name, avatar_url, cover_url, title, city, email, phone_number, country, birthday, description)`)
// .eq('user1', email).in('status', statuses)).data
// data2 = JSON.parse(JSON.stringify(data2).split('"user2":').join('"friend":'))
// var data = data1.concat(data2)
var table = 'users.dev'
var { data, error } = await supabase.from(table).select()
var emails = data.map(x => x.email)
var table = 'messages.dev'
// var emails = data.map(d => d.friend.email)
var ids = (await supabase.from('messages.dev').select('id').eq('related_id', 918)).data.map((item) => item.id).sort(() => 0.5 - Math.random())
// .not("related_id", "is", null)) .in('author', emails)
// var emails = (await supabase.from('users.dev').select('email')).data.map((item) => item.email).sort(() => 0.5 - Math.random())
// var ids = (await supabase.from('messages.dev').select('id').not("related_id", "is", null)).data.map((item) => item.id).sort(() => 0.5 - Math.random())
const num = 1000
// var ids = [7979, 8024]
for (let index = 0; index < num; index++) {
var { data, error } = await supabase.from(table).insert({
related_id: 8605, //ids[index % ids.length],
created_at: faker.date.recent(20),
author: emails[index % emails.length],
content: faker.lorem.text(),
num_like: Math.round(Math.random() * 10),
num_impr: Math.round(Math.random() * 100)
}).select('*')
console.log({
index, data
});
}
} catch (error) {
console.log(error)
}
})();