Skip to content

Instantly share code, notes, and snippets.

@andyj
Last active December 25, 2015 19:59
Show Gist options
  • Save andyj/7031528 to your computer and use it in GitHub Desktop.
Save andyj/7031528 to your computer and use it in GitHub Desktop.
Some SQL (mysql) for exporting from BlogCFC to Ghost (www.ghost.org)
-- This was tested on Ghost v0.3.0
-- I have 2 databases set up which I reference in my SQL - you need to change accordingly
-- 1: ajdev (this holds my BlogCFC data)
-- 2: ghost-dev (this holds my Ghost blog data)
--
-- 1) Check for duplicate alias's
-- I don't know how I got these but I did, so clean your entries up first but looking
-- for duplicates and changing the `alias` value to something unique.
SELECT lower(`alias`) , count(lower(`alias`) )
FROM ajdev.tblblogentries
WHERE released = 1
GROUP BY lower(`alias`)
HAVING count(lower(`alias`) ) > 1
-- 2) The import
INSERT INTO `ghost-dev`.`posts` (
`uuid`,
`title`,
`slug`,
`html`,
`status`,
`language`,
`author_id`,
`created_at`,
`created_by`,
`updated_at`,
`updated_by`,
`published_at`,
`published_by`
)
SELECT
uuid(),
`title`,
lower(`alias`) AS `slug`,
concat_ws(' ',`body`,`morebody`) AS `html`,
'published' AS `status`,
'en_US' AS `language`,
1 AS `author_id`, -- You might want to change this to your author_id
`posted` AS `created_at`,
1 AS `created_by`, -- You might want to change this to your author_id
`posted` AS `updated_at`,
1 AS `updated_by`, -- You might want to change this to your author_id
`posted` AS `published_at`,
1 AS `published_by` -- You might want to change this to your author_id
FROM ajdev.tblblogentries
WHERE released = 1
ORDER BY posted ASC
-- Use this to reset the ID if you start playing around
-- ALTER TABLE `posts` AUTO_INCREMENT = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment