forked from hashrocket/tilex
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigrate.sql
More file actions
69 lines (63 loc) · 1.16 KB
/
migrate.sql
File metadata and controls
69 lines (63 loc) · 1.16 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
69
truncate channels cascade;
truncate developers cascade;
insert into channels (
id,
name,
twitter_hashtag,
inserted_at,
updated_at
) select
lc.id,
lc.name,
lc.twitter_hashtag,
lc.created_at,
lc.updated_at
from legacy.channels as lc;
select setval('channels_id_seq', (select max(id) from legacy.channels));
insert into developers (
id,
email,
username,
google_id,
twitter_handle
inserted_at,
updated_at,
) select
ld.id,
ld.email,
ld.username,
ld.username,
ld.twitter_handle,
ld.created_at,
ld.updated_at
from legacy.developers ld;
select setval('developers_id_seq', (select max(id) from legacy.developers));
insert into posts (
id,
title,
body,
inserted_at,
updated_at,
channel_id,
slug,
likes,
max_likes,
published_at,
tweeted_at,
developer_id
) select
lp.id,
lp.title,
lp.body,
lp.created_at,
lp.updated_at,
lp.channel_id,
lp.slug,
lp.likes,
lp.max_likes,
lp.published_at,
lp.created_at, -- default the tweeted at column to the time the post was created
lp.developer_id
from legacy.posts as lp
where lp.published_at is not null;
select setval('posts_id_seq', (select max(id) from legacy.posts));