Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
4 posts Page 1 of 1
Hey, if you ever needed a tool to data migration, I'm developing one and will post here.
It's best usage is transferring data selectively from one database to another database which both are hosted in the same server whether local or online.
Example: massive delete cloned pages, massive create identical cloned pages or transfer data from filled editable fields - it all goes here.

I am coding a website for a client that is a bit different from the previous one, but with the same portfolio items. Would be a nightmare to copy-paste several hundreds of cloned pages and data in editables. So here tool helps.

Post your stories, samples or requests.
active topics, google
Free support is never free.. Donate!
Ok, here is the first version, which already helps me. It can be considered as alpha.
(66.85 KiB) Downloaded 77 times

List of funcitons:
  • Create cloned pages
  • Delete cloned pages
  • Update text field (text, textarea, nicedit)
  • Update relation field
  • Read text field

Once you download the zip, you will find a folder 'screenshots', a template 'db-migration.php' and 'snippets/db' folder. Place them appropriately. Screenshots can be removed, of course.
Register template in the system, by visiting it as super-admin and it will show list of links to supported functions.
This tool is coded to be used in target installation, not the source one. So register it in the new website, not the old one. It will not work otherwise, because CouchCMS doesn't support writing info to other databases, only current one.

All functions rely on several variables:
source database (any database in the system that has `couch_*` tables.
target database - current couch installation, which you are running this template on.
source template - clonable template in source database.
target template - clonable template in current installation database.
source field - regular editable field, that you defined in source template
target field - regular editable from target template.

I did some effort to dynamically fetch databases, templates and fields to avoid manual typing.
I did not always use a 'paginated' approach with pauses, so some operations might complete at once. If number of cloned pages is not big (several hundreds - small, several thousands - average, 10k-100k - big), then things complete quickly in mere seconds of faster.

1. Create cloned pages

Provide necessary data to form fields and function will create the same pages based on page_title as it will find in source clonable template.
A problem: If several of your source pages have the same title - then several pages will be created with the same title (names are assigned automatically by CouchCMS). Identical titles can be bad for proper data migration, so maybe it is good to rename them in source template.

2. Delete cloned pages

Select a template to be cleaned up and click Start.
active topics, google
Free support is never free.. Donate!
3. Update text field (textarea, nicedit and text fields are tested OK, the others not coded yet)
4. Update relation field (relation OK, reverse_relation not coded yet)
update-relation-field.png (22.94 KiB) Viewed 809 times

Consequtively choose variables and click Next or Start (once everything is chosen).
Both 3rd and 4th functions work very similar, so I post here only one screenshot.

Most data-reading operations are coded with 'cms:query' tag with direct SQL requests, inherited from those CouchCMS uses. Every data-writing operation is coded with 'cms:db_persist' tag, so data is written by CouchCMS itself, doing it natively, as if you inputted data manually in backend and saved it.
I think it is the only way at the moment to do this and results are therefore very reliable.
active topics, google
Free support is never free.. Donate!
Added 'richtext' support.
Added new function 'Read text field' - outputs content of some text field from all pages of a chosen template in chosen db.
Also zip now contains more snippets that do the same, but unpublish target page if text/relation field in source has no value.
active topics, google
Free support is never free.. Donate!
4 posts Page 1 of 1

Who is online

In total there are 2 users online :: 0 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: No registered users and 2 guests