Permalink
Browse files

Added migrations to skink.

  • Loading branch information...
heynemann committed Jun 17, 2009
1 parent 392c356 commit 847cfc2494d199554607dc7cdc267d490887e47d
View
@@ -28,6 +28,8 @@ help:
@echo " targets:"
@echo " help displays this help text"
@echo " all compiles the code and runs all tests"
+ @echo " createdb drops the database and runs all migrations"
+ @echo " upgradedb runs all migrations without dropping the db"
@echo " compile compiles the python code"
@echo " test runs all tests (unit, functional and acceptance)"
@echo " run_unit runs all unit tests"
@@ -55,6 +57,12 @@ clean: remove_build_dir
# action targets
+createdb:
+ @skink/skink_console.py createdb
+
+upgradedb:
+ @skink/skink_console.py upgradedb
+
report_success:
@echo "Build succeeded!"
View
@@ -45,6 +45,10 @@ db_verbose = False
#What db to connect to
#db_connection = sqlite:///skinkdb.db
db_connection = mysql://skinkuser:skinkpass@localhost/skink
+db_host = localhost
+db_name = skink
+db_user = skinkuser
+db_pass = skinkpass
#Plugins
[EmailPlugin]
@@ -0,0 +1,209 @@
+SQL_UP = """
+CREATE DATABASE IF NOT EXISTS skink;
+USE skink;
+
+--
+-- Definition of table `skink`.`build_files`
+--
+
+DROP TABLE IF EXISTS `skink`.`build_files`;
+CREATE TABLE `skink`.`build_files` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(255) default NULL,
+ `original_path` varchar(2000) default NULL,
+ `content` longblob,
+ `build_id` int(11) default NULL,
+ PRIMARY KEY (`id`),
+ KEY `ix_build_files_build_id` (`build_id`)
+);
+
+--
+-- Dumping data for table `skink`.`build_files`
+--
+
+/*!40000 ALTER TABLE `build_files` DISABLE KEYS */;
+LOCK TABLES `build_files` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `build_files` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`build_tabs`
+--
+
+DROP TABLE IF EXISTS `skink`.`build_tabs`;
+CREATE TABLE `skink`.`build_tabs` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(255) default NULL,
+ `command` varchar(2000) default NULL,
+ `content_type` varchar(100) default NULL,
+ `build_id` int(11) default NULL,
+ `log` text,
+ PRIMARY KEY (`id`),
+ KEY `ix_build_tabs_build_id` (`build_id`)
+);
+
+--
+-- Dumping data for table `skink`.`build_tabs`
+--
+
+/*!40000 ALTER TABLE `build_tabs` DISABLE KEYS */;
+LOCK TABLES `build_tabs` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `build_tabs` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`builds`
+--
+
+DROP TABLE IF EXISTS `skink`.`builds`;
+CREATE TABLE `skink`.`builds` (
+ `id` int(11) NOT NULL auto_increment,
+ `number` int(11) default NULL,
+ `date` datetime default NULL,
+ `status` varchar(20) default NULL,
+ `scm_status` varchar(20) default NULL,
+ `log` text,
+ `commit_number` varchar(40) default NULL,
+ `commit_author` varchar(400) default NULL,
+ `commit_committer` varchar(400) default NULL,
+ `commit_text` text,
+ `commit_author_date` datetime default NULL,
+ `commit_committer_date` datetime default NULL,
+ `project_id` int(11) default NULL,
+ PRIMARY KEY (`id`),
+ KEY `ix_builds_project_id` (`project_id`)
+);
+
+--
+-- Dumping data for table `skink`.`builds`
+--
+
+/*!40000 ALTER TABLE `builds` DISABLE KEYS */;
+LOCK TABLES `builds` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `builds` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`pipeline_items`
+--
+
+DROP TABLE IF EXISTS `skink`.`pipeline_items`;
+CREATE TABLE `skink`.`pipeline_items` (
+ `id` int(11) NOT NULL auto_increment,
+ `pipeline_id` int(11) default NULL,
+ `project_id` int(11) default NULL,
+ PRIMARY KEY (`id`),
+ KEY `ix_pipeline_items_pipeline_id` (`pipeline_id`),
+ KEY `ix_pipeline_items_project_id` (`project_id`)
+);
+
+--
+-- Dumping data for table `skink`.`pipeline_items`
+--
+
+/*!40000 ALTER TABLE `pipeline_items` DISABLE KEYS */;
+LOCK TABLES `pipeline_items` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `pipeline_items` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`pipelines`
+--
+
+DROP TABLE IF EXISTS `skink`.`pipelines`;
+CREATE TABLE `skink`.`pipelines` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(100) default NULL,
+ PRIMARY KEY (`id`)
+);
+
+--
+-- Dumping data for table `skink`.`pipelines`
+--
+
+/*!40000 ALTER TABLE `pipelines` DISABLE KEYS */;
+LOCK TABLES `pipelines` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `pipelines` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`project_file_locators`
+--
+
+DROP TABLE IF EXISTS `skink`.`project_file_locators`;
+CREATE TABLE `skink`.`project_file_locators` (
+ `id` int(11) NOT NULL auto_increment,
+ `locator` varchar(255) default NULL,
+ `project_id` int(11) default NULL,
+ PRIMARY KEY (`id`),
+ KEY `ix_project_file_locators_project_id` (`project_id`)
+);
+
+--
+-- Dumping data for table `skink`.`project_file_locators`
+--
+
+/*!40000 ALTER TABLE `project_file_locators` DISABLE KEYS */;
+LOCK TABLES `project_file_locators` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `project_file_locators` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`project_tabs`
+--
+
+DROP TABLE IF EXISTS `skink`.`project_tabs`;
+CREATE TABLE `skink`.`project_tabs` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(255) default NULL,
+ `command` varchar(2000) default NULL,
+ `content_type` varchar(100) default NULL,
+ `project_id` int(11) default NULL,
+ PRIMARY KEY (`id`),
+ KEY `ix_project_tabs_project_id` (`project_id`)
+);
+
+--
+-- Dumping data for table `skink`.`project_tabs`
+--
+
+/*!40000 ALTER TABLE `project_tabs` DISABLE KEYS */;
+LOCK TABLES `project_tabs` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `project_tabs` ENABLE KEYS */;
+
+
+--
+-- Definition of table `skink`.`projects`
+--
+
+DROP TABLE IF EXISTS `skink`.`projects`;
+CREATE TABLE `skink`.`projects` (
+ `id` int(11) NOT NULL auto_increment,
+ `name` varchar(255) default NULL,
+ `build_script` varchar(2000) default NULL,
+ `scm_repository` varchar(1500) default NULL,
+ `monitor_changes` tinyint(1) default NULL,
+ `build_status` varchar(15) default NULL,
+ PRIMARY KEY (`id`)
+);
+
+--
+-- Dumping data for table `skink`.`projects`
+--
+
+/*!40000 ALTER TABLE `projects` DISABLE KEYS */;
+LOCK TABLES `projects` WRITE;
+UNLOCK TABLES;
+/*!40000 ALTER TABLE `projects` ENABLE KEYS */;
+"""
+
+SQL_DOWN = """
+DROP DATABASE SKINK
+"""
View
@@ -0,0 +1,10 @@
+# example config file
+import os
+
+HOST = os.getenv("DB_HOST") or "localhost"
+USERNAME = "skink"
+PASSWORD = "skinkuser"
+DATABASE = "skinkpass"
+
+# relative path from the location of this file
+MIGRATIONS_DIR = os.getenv("MIGRATIONS_DIR") or "."
View
@@ -36,6 +36,10 @@ def current(cls):
cls.instance.webserver_verbose = config.get("General", "webserver_verbose") == "True"
cls.instance.db_verbose = config.get("Database", "db_verbose") == "True"
cls.instance.db_connection = config.get("Database", "db_connection")
+ cls.instance.db_host = config.get("Database", "db_host")
+ cls.instance.db_name = config.get("Database", "db_name")
+ cls.instance.db_user = config.get("Database", "db_user")
+ cls.instance.db_pass = config.get("Database", "db_pass")
cls.instance.plugin_path = config.get("General", "plugin_path")
@@ -106,7 +106,7 @@ def verify_and_create(cls):
metadata.bind = ctx.db_connection
metadata.bind.echo = ctx.db_verbose
setup_all()
-
+
if not cls.is_db_created():
create_all()
View
No changes.
View
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+from simple_db_migrate.cli import CLI
+from simple_db_migrate.core import Config
+from simple_db_migrate.main import Main
+
+(options, args) = CLI().parse()
+
+# Create config
+config = Config(options.config_file)
+config.put("schema_version", options.schema_version)
+config.put("show_sql", options.show_sql)
+config.put("show_sql_only", options.show_sql_only)
+config.put("new_migration", options.new_migration)
+config.put("drop_db_first", options.drop_db_first)
+
+# If CLI was correctly parsed, execute db-migrate.
+Main(config).execute()
No changes.
@@ -0,0 +1,79 @@
+from optparse import OptionParser
+import sys
+
+class CLI(object):
+
+ color = {
+ #"PINK": "\033[95m",
+ #"BLUE": "\033[94m",
+ #"CYAN": "\033[96m",
+ #"GREEN": "\033[92m",
+ #"YELLOW": "\033[93m",
+ #"RED": "\033[91m",
+ #"GRAY": "\033[90m",
+ #"END": "\033[0m",
+ "PINK": "",
+ "BLUE": "",
+ "CYAN": "",
+ "GREEN": "",
+ "YELLOW": "",
+ "RED": "",
+ "GRAY": "",
+ "END": "",
+ }
+
+ def __init__(self):
+ self.__config_parser()
+
+ def __config_parser(self):
+ self.__parser = OptionParser()
+
+ self.__parser.add_option("-v", "--version",
+ dest="schema_version",
+ default=None,
+ help="Schema version to migrate to. If not provided will migrate to the last version available in the migrations directory.")
+
+ self.__parser.add_option("-c", "--config",
+ dest="config_file",
+ default="simple-db-migrate.conf",
+ help="Use a specific config file. If not provided, will search for 'simple-db-migrate.conf' in the current directory.")
+
+ self.__parser.add_option("--showsql",
+ action="store_true",
+ dest="show_sql",
+ default=False,
+ help="Show all SQL statements executed.")
+
+ self.__parser.add_option("--showsqlonly",
+ action="store_true",
+ dest="show_sql_only",
+ default=False,
+ help="Show all SQL statements that would be executed but DON'T execute them in the database.")
+
+ self.__parser.add_option("--create", "--new",
+ dest="new_migration",
+ default=None,
+ help="Create migration file with the given nickname. The nickname should contain only lowercase characters and underscore '_'. Example: 'create_table_xyz'.")
+
+ self.__parser.add_option("--drop", "--drop-database-first",
+ action="store_true",
+ dest="drop_db_first",
+ default=False,
+ help="Drop database before running migrations to create everything from scratch. Useful when the database schema is corrupted and the migration scripts are not working.")
+
+ def get_parser(self):
+ return self.__parser
+
+ def parse(self):
+ return self.__parser.parse_args()
+
+ def error_and_exit(self, msg):
+ self.msg("[ERROR] %s\n" % msg, "RED")
+ sys.exit(1)
+
+ def info_and_exit(self, msg):
+ self.msg("%s\n" % msg, "BLUE")
+ sys.exit(0)
+
+ def msg(self, msg, color="CYAN"):
+ print "%s%s%s" % (self.color[color], msg, self.color["END"])
Oops, something went wrong.

0 comments on commit 847cfc2

Please sign in to comment.