Source

fabulator / src / fabulator / core / db / mysql.py

Diff from to

src/fabulator/core/db/mysql.py

 
     def create_database(self, database_name=None):
         """create database"""
-        run("echo 'CREATE DATABASE IF NOT EXISTS %(db)s' | mysql --user=%(user)s --password=%(pw)s" % self.conf)
+        conf = self.conf.copy()
+        if database_name:
+            conf["db"] = database_name
+
+        run("echo 'CREATE DATABASE IF NOT EXISTS %(db)s' | mysql --user=%(user)s --password=%(pw)s --host=%(host)s" % conf)
 
     def backup(self, filename="plop"):
         """Backups your mysql database"""
         run("mkdir -p %(backup)s" % self.conf)
         run("""mysqldump --host=%(host)s --user=%(user)s --password=%(pw)s %(db)s > %(backup_fname)s""" % self.conf)
 
-    def migrate(self, revision):
+    def migrate(self, revision, sqlfile):
         """migrate the database"""
-        raise NotImplementedError
+        if not isinstance(sqlfile, list):
+            sqlfile = [sqlfile]
+        conf = self.conf.copy()
 
-    def fallback(self, revision):
+        for sql in sqlfile:
+            conf["sqlfile"] = sql
+            run("mysql --host=%(host)s --user=%(user)s --password=%(pw)s < %(sqlfile)s" % conf)
+            
+        
+    def populate(self, sqlfile):
+        """inserts data into your db"""
+        conf = self.conf.copy()
+        conf["sqlfile"] = filename
+        run("mysql --host=%(host)s --user=%(user)s --password=%(pw)s < %(sqlfile)s" % conf)
+
+    def fallback(self, revision, sqlfile):
         """fallback to an old revision"""
-        raise NotImplementedError
+        #well, we have to drop db, create db, populate from
+        self.drop_database()
+        self.create_database()
+        self.populate(sqlfile)
 
     def drop_table(self, table_name):
         """Drop a table"""
-        raise NotImplementedError
+        conf = self.conf.copy()
+        conf["table"] = table_name
+        run("""DROP TABLE %(table)s | mysql --host=%(host)s --user=%(user)s --password=%(pw)s""" % conf)
 
-    def drop_database(self, database_name):
-        run("echo 'DROP DATABASE %(db)s' | mysql --user=%(user)s --password=%(pw)s" % self.conf)
+    def drop_database(self, database_name=None):
+        conf = self.conf.copy()
+        if database_name:
+            conf["db"] = database_name
+        run("echo 'DROP DATABASE %(db)s' | mysql --user=%(user)s --password=%(pw)s" % conf)
 
     def list_revision(self):
         """Return a list of available database revision"""
         run("ls -l %(backup)s" % self.conf)
-        raise NotImplementedError