Пример #1
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.database.migration import StoqlibSchemaMigration
        from stoqlib.lib.environment import is_developer_mode
        from stoqlib.net.server import ServerProxy

        self._read_config(options,
                          check_schema=False,
                          load_plugins=False,
                          register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()

        if is_developer_mode():
            backup = False
        else:
            backup = options.disable_backup

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')

        try:
            retval = migration.update(backup=backup)
        finally:
            # The schema was upgraded. If it was running before,
            # restart it so it can load the new code
            if running:
                server.call('restart')

        return 0 if retval else 1
Пример #2
0
def create_base_schema():
    log.info('Creating base schema')
    create_log.info("SCHEMA")

    # Functions
    functions = environ.find_resource('sql', 'functions.sql')
    if db_settings.execute_sql(functions) != 0:
        error(u'Failed to create functions')

    # A Base schema shared between all RDBMS implementations
    schema = _get_latest_schema()
    if db_settings.execute_sql(schema) != 0:
        error(u'Failed to create base schema')

    try:
        schema = environ.find_resource('sql',
                                       '%s-schema.sql' % db_settings.rdbms)
        if db_settings.execute_sql(schema) != 0:
            error(u'Failed to create %s specific schema' %
                  (db_settings.rdbms, ))
    except EnvironmentError:
        pass

    migration = StoqlibSchemaMigration()
    migration.apply_all_patches()
Пример #3
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.database.migration import StoqlibSchemaMigration
        from stoqlib.lib.environment import is_developer_mode
        from stoqlib.net.server import ServerProxy

        self._read_config(options, check_schema=False, load_plugins=False,
                          register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()

        if is_developer_mode():
            backup = False
        else:
            backup = options.disable_backup

        server = ServerProxy()
        running = server.check_running()
        if running:
            server.call('pause_tasks')

        try:
            retval = migration.update(backup=backup)
        finally:
            # The schema was upgraded. If it was running before,
            # restart it so it can load the new code
            if running:
                server.call('restart')

        return 0 if retval else 1
Пример #4
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.database.migration import StoqlibSchemaMigration

        self._read_config(options, check_schema=False, load_plugins=False, register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()
        if not migration.update(backup=options.disable_backup):
            return 1
Пример #5
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.database.migration import StoqlibSchemaMigration

        self._read_config(options, check_schema=False, load_plugins=False,
                          register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()
        if not migration.update(backup=options.disable_backup):
            return 1
Пример #6
0
def create_base_schema():
    log.info('Creating base schema')
    create_log.info("SCHEMA")

    create_database_functions()

    # A Base schema shared between all RDBMS implementations
    schema = _get_latest_schema()
    if db_settings.execute_sql(schema) != 0:
        error(u'Failed to create base schema')

    migration = StoqlibSchemaMigration()
    migration.apply_all_patches()
Пример #7
0
def create_base_schema():
    log.info('Creating base schema')
    create_log.info("SCHEMA")

    create_database_functions()

    # A Base schema shared between all RDBMS implementations
    schema = _get_latest_schema()
    if db_settings.execute_sql(schema) != 0:
        error(u'Failed to create base schema')

    migration = StoqlibSchemaMigration()
    migration.apply_all_patches()
Пример #8
0
    def _check_schema_migration(self):
        from stoqlib.lib.message import error
        from stoqlib.database.migration import needs_schema_update
        from stoqlib.exceptions import DatabaseInconsistency
        if needs_schema_update():
            self._run_update_wizard()

        from stoqlib.database.migration import StoqlibSchemaMigration
        migration = StoqlibSchemaMigration()
        try:
            migration.check()
        except DatabaseInconsistency as e:
            error(_('The database version differs from your installed '
                    'version.'), str(e))
Пример #9
0
def create_base_schema():
    log.info('Creating base schema')
    create_log.info("SCHEMA")

    create_database_functions()

    # A Base schema shared between all RDBMS implementations
    schema = _get_latest_schema()
    if db_settings.execute_sql(schema) != 0:
        error(u'Failed to create base schema')

    try:
        schema = environ.find_resource('sql', '%s-schema.sql' % db_settings.rdbms)
        if db_settings.execute_sql(schema) != 0:
            error(u'Failed to create %s specific schema' % (db_settings.rdbms, ))
    except EnvironmentError:
        pass

    migration = StoqlibSchemaMigration()
    migration.apply_all_patches()
Пример #10
0
 def test_migration_check(self, check_plugins, check_uptodate, error):
     migration = StoqlibSchemaMigration()
     check_uptodate.return_value = False
     self.assertFalse(migration.check())
     check_uptodate.return_value = True
     self.assertTrue(migration.check(check_plugins=False))
     check_plugins.return_value = False
     self.assertFalse(migration.check(check_plugins=True))
     check_plugins.return_value = True
     self.assertTrue(migration.check(check_plugins=True))
Пример #11
0
    def cmd_updateschema(self, options):
        """Update the database schema"""
        from stoqlib.api import api
        from stoqlib.database.migration import StoqlibSchemaMigration
        from stoqlib.lib.environment import is_developer_mode
        from stoqlib.net.server import ServerProxy
        from twisted.internet import reactor

        self._read_config(options,
                          check_schema=False,
                          load_plugins=False,
                          register_station=False)

        # This is a little bit tricky to be able to apply the initial
        # plugin infrastructure
        migration = StoqlibSchemaMigration()

        if is_developer_mode():
            backup = False
        else:
            backup = options.disable_backup

        @api. async
        def migrate(retval):
            server = ServerProxy()
            running = yield server.check_running()
            if running:
                yield server.call('pause_tasks')

            try:
                retval[0] = yield migration.update_async(backup=backup)
            finally:
                # The schema was upgraded. If it was running before,
                # restart it so it can load the new code
                if running:
                    yield server.call('restart')

                if reactor.running:
                    reactor.stop()

        retval = [False]
        reactor.callWhenRunning(migrate, retval)
        reactor.run()

        return 0 if retval[0] else 1
Пример #12
0
def schema_migration():
    return StoqlibSchemaMigration()
Пример #13
0
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    if register_station:
        try:
            default_store = get_default_store()
        except DatabaseError as e:
            error(e.short, str(e.msg))

        config.get_settings().check_version(default_store)

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        default_store = get_default_store()
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()
Пример #14
0
        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager

        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        default_store = get_default_store()
        if not default_store.table_exists("system_table"):
            error(
                _("Database schema error"),
                _(
                    "Table 'system_table' does not exist.\n"
                    "Consult your database administrator to solve this problem."
                ),
            )

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()
Пример #15
0
def setup(config=None, options=None, register_station=True, check_schema=True,
          load_plugins=True):
    """
    Loads the configuration from arguments and configuration file.

    @param config: a StoqConfig instance
    @param options: a Optionparser instance
    @param register_station: if we should register the branch station.
    @param check_schema: if we should check the schema
    @param load_plugins: if we should load plugins for the system
    """

    # NOTE: No GUI calls are allowed in here
    #       If you change anything here, you need to verify that all
    #       callsites are still working properly.
    #       bin/stoq
    #       bin/stoqdbadmin
    #       python stoq/tests/runtest.py

    if options is None:
        parser = get_option_parser()
        options, args = parser.parse_args(sys.argv)

    if options.verbose:
        from kiwi.log import set_log_level
        set_log_level('stoq*', 0)

    setup_path()

    if config is None:
        config = StoqConfig()
        if options.filename:
            config.load(options.filename)
        else:
            config.load_default()
    config.set_from_options(options)

    register_config(config)

    if options and options.sqldebug:
        enable_debugging()

    from stoq.lib.applist import ApplicationDescriptions
    provide_utility(IApplicationDescriptions, ApplicationDescriptions(),
                    replace=True)

    db_settings = config.get_settings()
    try:
        default_store = get_default_store()
    except DatabaseError as e:
        # Only raise an error if a database is actually required
        if register_station or load_plugins or check_schema:
            error(e.short, str(e.msg))
        else:
            default_store = None

    if register_station:
        db_settings.check_version(default_store)
        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()

        if options and options.sqldebug:
            enable_debugging()

        set_current_branch_station(default_store, station_name=None)

    if load_plugins:
        from stoqlib.lib.pluginmanager import get_plugin_manager
        manager = get_plugin_manager()
        manager.activate_installed_plugins()

    if check_schema:
        if not default_store.table_exists('system_table'):
            error(
                _("Database schema error"),
                _("Table 'system_table' does not exist.\n"
                  "Consult your database administrator to solve this problem."))

        if check_schema:
            migration = StoqlibSchemaMigration()
            migration.check()