Permalink
Browse files

added migrate and cleanup scripts as well as migration documentation

  • Loading branch information...
1 parent 0b1fa52 commit ba3d2e346f0cc7bae381a82f4b33411f58a0bffa @vicapow vicapow committed Mar 14, 2013
Showing with 152 additions and 5 deletions.
  1. +24 −0 MIGRATE.txt
  2. +4 −5 Makefile
  3. +68 −0 migrate.sh
  4. +56 −0 resources/scripts/sql/cleanup.sql
View
24 MIGRATE.txt
@@ -0,0 +1,24 @@
+
+to migrate the site, first make sure to BACKUP THE DATABASE!
+also, make sure to run all these scripts from a new database just incase there
+so that are any issues in the new database schema are not destructive to the old
+site.
+
+next, run the migrate.sh script, providing the sql dump as the first argument.
+here's an example:
+
+./migrate.sh ../openclipart.org-2013-01-14.sql
+
+this script reads the contents of config.json to read the database credentials
+so make sure they're set correctly and the config file exists.
+
+finally, copy over all files from the "people" folder from the old site into the
+new site at "public/people"
+
+After making sure everything works properly, you can optionally run
+resources/scripts/sql/cleanup.sql which will remove all the old, now unused,
+tables. BUT AGAIN! if you run this script it will remove all the old tables, so
+make sure to backup the old site code, tables and files just in case something
+goes wrong.
+
+That's all folks!
View
9 Makefile
@@ -4,7 +4,7 @@ LESS = $(shell find styles -name "*.less" -type f | sort)
COMPONENT = $(shell find client -name "*.js" -type f | sort)
# ----- Rules -----------------------------------------------------------------
-.PHONY: clean schema drop migration
+.PHONY: clean db-schema db-drop db-migrate migrate
less: $(LESS)
lessc styles/main.less > public/css/main.css || rm -f public/css/main.css
@@ -17,15 +17,14 @@ components: $(COMPONENT)
minify: public/js/main.js
uglifyjs public/js/main.js --output=public/js/main.min.js
-schema:
+db-schema:
mysql -D ocal < resources/scripts/sql/schema.sql
-drop:
+db-drop:
mysql -D ocal < resources/scripts/sql/drop.sql
-migrate:
+db-migrate:
mysql -D ocal < resources/scripts/sql/migration.sql
-
clean:
rm public/css/main.css
View
68 migrate.sh
@@ -0,0 +1,68 @@
+#!/bin/bash
+
+
+if [ -z "$1" ];
+ then echo "please provide the path to the sql file that contains the old
+ database";
+ exit 1;
+fi
+
+if [ ! -f $1 ];
+ then echo "sql file not found!";
+ exit 1;
+fi
+
+SQL_FILE=$1;
+
+echo "using sql file: $SQL_FILE";
+
+if [ -z "config.json" ];
+ then echo "config.json file is missing and need to read database credentials";
+ exit 1;
+fi
+
+echo "found config.json"
+
+DB_USER=`python -c 'import json; c=json.load(open("config.json")); print c["db_user"]'`
+
+DB_PASS=`python -c 'import json; c=json.load(open("config.json")); print c["db_user"]'`
+
+DB_NAME=`python -c 'import json; c=json.load(open("config.json")); print c["db_name"]'`
+
+MYSQL="mysql --user=$DB_USER --password=$DB_PASS -D $DB_NAME"
+
+echo "using mysql username $DB_USER"
+echo "using mysql database $DB_NAME"
+
+$MYSQL < $SQL_FILE
+rc=$?;
+if [ $rc -ne 0 ]; then
+ echo "ERROR: unable to import the provided sql file.";
+ exit 1;
+fi
+echo "successfully imported provided sql file";
+
+$MYSQL < resources/scripts/sql/drop.sql;
+rc=$?;
+if [ $rc -ne 0 ]; then
+ echo "ERROR: failed to drop previous version of new schema in database $DB_NAME.";
+ exit 1;
+fi
+echo "successfully removed previous version of the new schema in database $DB_NAME.";
+
+$MYSQL < resources/scripts/sql/schema.sql;
+rc=$?;
+if [ $rc -ne 0 ]; then
+ echo "ERROR: failed to create new schema tables in database $DB_NAME.";
+ exit 1;
+fi
+echo "successfully created new table schemas in database $DB_NAME.";
+
+
+$MYSQL < resources/scripts/sql/migration.sql;
+rc=$?;
+if [ $rc -ne 0 ]; then
+ echo "ERROR: failed to migrate to new schema in database $DB_NAME.";
+ exit 1;
+fi
+echo "successfully migrated tables to new schema in database $DB_NAME.";
View
56 resources/scripts/sql/cleanup.sql
@@ -0,0 +1,56 @@
+DROP TABLE IF EXISTS aiki_apps;
+DROP TABLE IF EXISTS aiki_config;
+DROP TABLE IF EXISTS aiki_configs;
+DROP TABLE IF EXISTS aiki_css;
+DROP TABLE IF EXISTS aiki_databases;
+DROP TABLE IF EXISTS aiki_dictionaries;
+DROP TABLE IF EXISTS aiki_dictionary;
+DROP TABLE IF EXISTS aiki_events;
+DROP TABLE IF EXISTS aiki_flow;
+DROP TABLE IF EXISTS aiki_forms;
+DROP TABLE IF EXISTS aiki_guests;
+DROP TABLE IF EXISTS aiki_internal_links;
+DROP TABLE IF EXISTS aiki_javascript;
+DROP TABLE IF EXISTS aiki_languages;
+DROP TABLE IF EXISTS aiki_plugin_configurations;
+DROP TABLE IF EXISTS aiki_plugins;
+DROP TABLE IF EXISTS aiki_redirects;
+DROP TABLE IF EXISTS aiki_revisions;
+DROP TABLE IF EXISTS aiki_sessions;
+DROP TABLE IF EXISTS aiki_settings;
+DROP TABLE IF EXISTS aiki_sites;
+DROP TABLE IF EXISTS aiki_synchronization;
+DROP TABLE IF EXISTS aiki_template;
+DROP TABLE IF EXISTS aiki_url_type;
+DROP TABLE IF EXISTS aiki_urls;
+DROP TABLE IF EXISTS aiki_user_links;
+DROP TABLE IF EXISTS aiki_users;
+DROP TABLE IF EXISTS aiki_users_groups;
+DROP TABLE IF EXISTS aiki_users_sessions;
+DROP TABLE IF EXISTS aiki_views;
+DROP TABLE IF EXISTS aiki_widgets;
+DROP TABLE IF EXISTS apps_photo_archive;
+DROP TABLE IF EXISTS apps_picatcha;
+DROP TABLE IF EXISTS apps_planet_posts;
+DROP TABLE IF EXISTS apps_planet_sources;
+DROP TABLE IF EXISTS apps_recaptcha;
+DROP TABLE IF EXISTS apps_wiki_links;
+DROP TABLE IF EXISTS apps_wiki_templates;
+DROP TABLE IF EXISTS apps_wiki_text;
+DROP TABLE IF EXISTS categorys;
+DROP TABLE IF EXISTS cc_tbl_contests;
+DROP TABLE IF EXISTS cc_tbl_ratings;
+DROP TABLE IF EXISTS cc_tbl_tags;
+DROP TABLE IF EXISTS cc_tbl_topics;
+DROP TABLE IF EXISTS cc_tbl_tree;
+DROP TABLE IF EXISTS cc_tbl_user;
+DROP TABLE IF EXISTS counter;
+DROP TABLE IF EXISTS ocal_favs;
+DROP TABLE IF EXISTS ocal_files;
+DROP TABLE IF EXISTS ocal_logs;
+DROP TABLE IF EXISTS ocal_msgs;
+DROP TABLE IF EXISTS pages_text;
+DROP TABLE IF EXISTS set_list_contents;
+DROP TABLE IF EXISTS set_list_titles;
+DROP TABLE IF EXISTS tmp;
+DROP TABLE IF EXISTS aiki_users_tmp;

0 comments on commit ba3d2e3

Please sign in to comment.