-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
98 lines (86 loc) · 2.34 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const {db: newdb, sequelize} = require('./new/connect')
const olddb = require('./old/connect').db
void async function db_converter(){
await sequelize.sync({ force: true })
const customer_old_db = await olddb.Customer.findAll()
for(let each of customer_old_db){
await newdb.Customer.create(each.toJSON())
}
const user_old_db = await olddb.User.findAll()
for(let each of user_old_db){
await newdb.User.create(each.toJSON())
}
const group_old_db = await olddb.Group.findAll()
for(let each of group_old_db){
each = each.toJSON()
await newdb.Group.create(each)
const image = await newdb.Media.create({url: 'https://stxtch-dev.s3.amazonaws.com/photos/pictureurl/victor-kintanar---_VIX0649_2.jpg', type: 'image'})
await newdb.GroupMedia.create({groupId: each.id, mediaId: image.id})
const video = await newdb.Media.create({url: 'https://player.vimeo.com/video/428225141', type: 'video'})
await newdb.GroupMedia.create({groupId: each.id, mediaId: video.id})
}
const story_old_db = await olddb.Story.findAll()
for(let each of story_old_db){
each = each.toJSON()
await newdb.Story.create(each)
if(each.pictureUrl){
const media = await newdb.Media.create({url: each.pictureUrl, type: 'image'})
await newdb.StoryMedia.create({storyId: each.id, mediaId: media.id})
}
if(each.videoUrl){
const media = await newdb.Media.create({url: each.videoUrl, type: 'video'})
await newdb.StoryMedia.create({storyId: each.id, mediaId: media.id})
}
}
const homestory_old_db = await olddb.HomeStory.findAll()
for(let each of homestory_old_db){
await newdb.HomeStory.create(each.toJSON())
}
for(let tag of tags){
await newdb.Tag.create(tag)
}
for(let grouptag of groupTags){
await newdb.GroupTag.create(grouptag)
}
for(let storytag of storyTags){
await newdb.StoryTag.create(storytag)
}
}()
const tags = [
{
id: 1,
name: "Cristian",
},
{
id: 2,
name: "DevLearn",
},
{
id: 3,
name: "DevLearn",
},
]
const groupTags = [
{
id: 1,
tagId: 1,
groupId: 1,
},
{
id: 2,
tagId: 2,
groupId: 2,
}
]
const storyTags = [
{
id: 1,
tagId: 1,
storyId: 1,
},
{
id: 2,
tagId: 2,
storyId: 2,
}
]