/drupal_migration

Code used to migrate my Drupal7 blog to Django/Wagtail.

Primary LanguagePython

This project provides the code I used to migrate my site from Drupal to Django
(Wagtail). When I went looking there were numerous posts with people explaining
that they did the migration but no one had provided code that would work (a few
close calls were broken by missing libraries).

While simple (it ignores importing files, types of nodes and many other details) this script can:
 * run idempotently
 * import revisions of a page
 * import change log history
 * act as a starting point for further customisation

Install
=======

Download the git repository to your new django project.

pip install -r requirements.txt

Pre flight
==========

MySQL
-----

Copy the MySQL db: django needs to be able to manage the primary keys ( Some classes don't have usable PKs)


Install mysqldbcopy (in mysql-utils) if it isn't already installed.

	mysqldbcopy --source=root:'password'@localhost \
							--destination=root:'password'@localhost \
							drupal7:drupal7copy --force

More help at https://dev.mysql.com/doc/mysql-utilities/1.5/en/utils-task-clone-db.html


Tables I had to alter (per https://stackoverflow.com/questions/2341576/updating-mysql-primary-key )

  mysql --user=root --password='password'
  \r drupal7copy
  alter table field_revision_body drop primary key, add column `id` int(10) unsigned primary KEY AUTO_INCREMENT;
  alter table field_revision_field_tags drop primary key, add column `id` int(10) unsigned primary KEY AUTO_INCREMENT;

Django
------

Add `drupal_migration` to INSTALLED_APPS.

Add new db stanza named drupaldb

	DATABASES = {
			'default': {
					'ENGINE': 'django.db.backends.sqlite3',
					'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
			},
			'drupaldb': {
					'ENGINE': 'django.db.backends.mysql',
					'NAME': 'drupal7copy',
					'USER': 'root',
					'PASSWORD': 'password',
					'HOST': '127.0.0.1',
					# Recommended by Django
					'OPTIONS': { 'init_command': "SET sql_mode='STRICT_TRANS_TABLES'" }
			}

Create a node called 'weblog' in your site.


Usage
=====

Page model
----------

Ensure the following fields exist (or further customise migration script)

    title = models.
    drupal_id = models.IntegerField(blank=True, null=True)
    date = models.DateTimeField("Last updated")
    preview = models.CharField(max_length=500)
    body = RichTextField(blank=True)
    revision_log = RichTextField(blank=True)
		tags = ClusterTaggableManager(through=LegacyBlogPageTag, blank=True)


Running code
------------

Customise drupal_to_django (eg change model imports if required)

python manage.py drupal_to_django

Contributing
============

Please get in touch via the issue tracker if you would like to request changes
or to offer patches.

The canonical public hosting for this repository is on GitLab, with a live mirror on GitHub.
https://gitlab.com/goetzk/drupal_migration
https://github.com/goetzk/drupal_migration/