delete from typecho_contents;
insert into typecho_contents (cid,title,slug,created,modified,`text`,`order`,authorid,`type`
,`status`,`password`,commentsNum,allowComment,allowPing,allowFeed,parent)
select post_id,post_title,post_url,UNIX_TIMESTAMP(post_dt),UNIX_TIMESTAMP(post_upddt),post_content_xhtml,0,1,post_type
,case when post_status=1 then 'publish' else post_status end as post_status,post_password,nb_comment,post_open_comment,post_open_tb,
1,0
from dc_post;

select * from typecho_comments;


delete from typecho_comments;
insert into typecho_comments(cid,created,author,authorid,ownerID,mail,url,ip,agent,text,type,status,parent)
select post_id,UNIX_TIMESTAMP(comment_dt),comment_author,case when comment_author = 'Ray' then 1 else 0 end as authorid
,1,comment_email,comment_site,comment_ip,'Import By Ray',comment_words,'comment','approved',0
from dc_comment;



delete from typecho_metas;
insert into typecho_metas (mid,name,slug,type)
select cat_id,cat_title,cat_url,'category'
from dc_category;

insert into typecho_metas (name,slug,type)
select meta_id,meta_id,'tag'
from dc_meta;

delete  from typecho_relationships;
insert into typecho_relationships(cid,mid)

select post_id,mid
from typecho_metas a join dc_meta b on a.name=b.meta_id
union
select post_id,cat_id
from dc_post
where cat_id is not null
order by 1,2;