예제 #1
0
파일: env.py 프로젝트: refaqtor/domogik
def run_migrations_online():
    """Run migrations in 'online' mode.

    In this scenario we need to create an Engine
    and associate a connection with the context.

    """
    alembic_config = config.get_section(config.config_ini_section)
    alembic_config['sqlalchemy.url'] = database.DbHelper(
    ).get_url_connection_string()

    engine = engine_from_config(alembic_config,
                                prefix='sqlalchemy.',
                                poolclass=pool.NullPool)

    connection = engine.connect()
    context.configure(connection=connection,
                      target_metadata=target_metadata,
                      compare_type=True)

    try:
        with context.begin_transaction():
            context.run_migrations()
    finally:
        connection.close()
예제 #2
0
    def __init__(self):
        """
        """
        from domogik.common import sql_schema
        from domogik.common import database
        from sqlalchemy import create_engine, MetaData, Table
        from alembic.config import Config
        from alembic import command

        self.db_backup_file = "{0}/domogik-{1}.sql".format(tempfile.gettempdir(), int(time.time()))
        self.alembic_cfg = Config("alembic.ini")

        self._db = database.DbHelper()
        self._url = self._db.get_url_connection_string()
        self._engine = create_engine(self._url)
예제 #3
0
파일: env.py 프로젝트: refaqtor/domogik
def run_migrations_offline():
    """Run migrations in 'offline' mode.

    This configures the context with just a URL
    and not an Engine, though an Engine is acceptable
    here as well.  By skipping the Engine creation
    we don't even need a DBAPI to be available.

    Calls to context.execute() here emit the given string to the
    script output.

    """
    # overruled for domogik
    # url = config.get_main_option("sqlalchemy.url")
    url = database.DbHelper().get_url_connection_string()
    context.configure(url=url)

    with context.begin_transaction():
        context.run_migrations()
예제 #4
0
def backup_database(folder):
    now = time.strftime("%Y%m%d-%H%M")
    db_backup_file = "{0}/domogik-database-{1}.sql.gz".format(folder, now)
    _db = database.DbHelper()
    if not _db.is_db_type_mysql():
        print(
            "Can't backup your database, only mysql is supported (you have : {0})"
            .format(_db.get_db_type()))
        return
    print("Backing up your database to {0}".format(db_backup_file))

    mysqldump_cmd = ['mysqldump', '-u', _db.get_db_user()]
    if _db.get_db_password():
        mysqldump_cmd.extend(
            ('-p{0}'.format(_db.get_db_password()), _db.get_db_name()))
    else:
        mysqldump_cmd.append(_db.get_db_name())
    mysqldump_cmd.append("| gzip ")
    mysqldump_cmd.append(">")
    mysqldump_cmd.append(db_backup_file)
    print(" ".join(mysqldump_cmd))
    os.system(" ".join(mysqldump_cmd))
예제 #5
0
from migrate.versioning.api import version as rep_version
from migrate.versioning.api import drop_version_control
from migrate.versioning.api import version_control
from migrate.versioning.api import upgrade as db_upgrade

from domogik.common import sql_schema
from domogik.common import database
from domogik.common.configloader import Loader

DB_BACKUP_FILE = tempfile.gettempdir() + "/domogik.sql"
# Get full path for 'upgrade_repository'
UPGRADE_REPOSITORY = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                  "upgrade_repository")
MIGRATE_VERSION_TABLE = "migrate_version"

_db = database.DbHelper()
_url = _db.get_url_connection_string()
_engine = create_engine(_url)

###
# Installer
###


def execute_system_command(arg_list,
                           p_stdout=subprocess.PIPE,
                           p_stderr=subprocess.PIPE):
    process = subprocess.Popen(arg_list,
                               shell=False,
                               stdout=p_stdout,
                               stderr=p_stderr)
예제 #6
0
파일: upgrade.py 프로젝트: wookiesh/domogik
@organization: Domogik
"""

import sys

from distutils2.version import NormalizedVersion, suggest_normalized_version

from sqlalchemy import create_engine
from sqlalchemy.ext.sqlsoup import SqlSoup

from domogik.common import database
from domogik import __version__, DB_VERSION

import upgrade_scripts

_url = database.DbHelper().get_url_connection_string()

class Upgrade:
    def __init__(self, engine):
        self.__db = SqlSoup(engine)

    def process(self):
        """Main function that run the update process"""
        #_upgrade_system_info_structure()
        old_app_version = self.get_current_app_version()
        old_db_version = self.get_current_db_version()
        print("=== Upgrade process")
        print("\t> Current version (application : %s, database = %s)" 
              % (self.get_current_app_version(), self.get_current_db_version()))
        print("\t> New version (application : %s, database = %s)" 
              % (self.get_new_app_version(), self.get_new_db_version()))