Esempio n. 1
0
    def _init_sqldbstaging(self, request_stagingversion=None):
        """Initializes the *staging* database object"""
        # FIXME (12-Jan-12021) Disabled automatic schema upgrade
        DB_VERSION_EXPECTED = '1.2.0'

        if self.is_using_postgres_db:
            uri = self._base_uri
        else:
            uri = f'{self.base_uri}/{self.sqlstaging_fname}'
        fname = Path(self.sqlstaging_fname).stem  # filename without extension
        self.staging = dtool.SQLDatabaseController(uri, fname)

        # BBB (12-Jan-12021) Disabled the ability to make the database read-only
        self.readonly = False

        # Upgrade the database
        from wbia.control._sql_helpers import ensure_correct_version
        from wbia.control import STAGING_SCHEMA

        ensure_correct_version(
            self,
            self.staging,
            DB_VERSION_EXPECTED,
            STAGING_SCHEMA,
            verbose=True,
            dobackup=not self.readonly,
        )
Esempio n. 2
0
def copy_database(src_fpath, dst_fpath):
    from wbia import dtool

    # Load database and ask it to copy itself, which enforces an exclusive
    # blocked lock for all processes potentially writing to the database
    timeout = 12 * 60 * 60  # Allow a lock of up to 12 hours for a database backup routine
    db = dtool.SQLDatabaseController(fpath=src_fpath,
                                     inmemory=False,
                                     timeout=timeout)
    db.backup(dst_fpath)
Esempio n. 3
0
def copy_database(src_fpath, dst_fpath):
    from wbia import dtool

    # Load database and ask it to copy itself, which enforces an exclusive
    # blocked lock for all processes potentially writing to the database
    timeout = 12 * 60 * 60  # Allow a lock of up to 12 hours for a database backup routine
    if not src_fpath.startswith('file:'):
        src_fpath = 'sqlite:///{}'.format(realpath(src_fpath))
    db = dtool.SQLDatabaseController(src_fpath, 'copy', timeout=timeout)
    db.backup(dst_fpath)
Esempio n. 4
0
def _devcheck_backups():
    from wbia import dtool as dt

    dbdir = ut.truepath('~/work/PZ_Master1/_ibsdb')
    sorted(ut.glob(join(dbdir, '_wbia_backups'), '*staging_back*.sqlite3'))
    fpaths = sorted(
        ut.glob(join(dbdir, '_wbia_backups'), '*database_back*.sqlite3'))
    for fpath in fpaths:
        db = dt.SQLDatabaseController(fpath=fpath)
        logger.info('fpath = %r' % (fpath, ))
        num_edges = len(db.executeone('SELECT rowid from annotmatch'))
        logger.info('num_edges = %r' % (num_edges, ))
        num_names = len(
            db.executeone('SELECT DISTINCT name_rowid from annotations'))
        logger.info('num_names = %r' % (num_names, ))
Esempio n. 5
0
    def _init_sqldbstaging(ibs, request_stagingversion=None):
        """
        Example:
            >>> # DISABLE_DOCTEST
            >>> from wbia.control.IBEISControl import *  # NOQA
            >>> import wbia  # NOQA
            >>> #ibs = wbia.opendb('PZ_MTEST')
            >>> #ibs = wbia.opendb('PZ_Master0')
            >>> ibs = wbia.opendb('testdb1')
            >>> #ibs = wbia.opendb('PZ_Master0')

        Ignore:
            aid_list = ibs.get_valid_aids()
            #ibs.update_annot_visual_uuids(aid_list)
            vuuid_list = ibs.get_annot_visual_uuids(aid_list)
            aid_list2 =  ibs.get_annot_aids_from_visual_uuid(vuuid_list)
            assert aid_list2 == aid_list
            # v1.3.0 testdb1:264us, PZ_MTEST:3.93ms, PZ_Master0:11.6s
            %timeit ibs.get_annot_aids_from_visual_uuid(vuuid_list)
            # v1.3.1 testdb1:236us, PZ_MTEST:1.83ms, PZ_Master0:140ms

            ibs.print_imageset_table(exclude_columns=['imageset_uuid'])
        """
        from wbia.control import _sql_helpers
        from wbia.control import STAGING_SCHEMA

        # Before load, ensure database has been backed up for the day
        backup_idx = ut.get_argval('--loadbackup-staging',
                                   type_=int,
                                   default=None)
        sqlstaging_fpath = None
        if backup_idx is not None:
            backups = _sql_helpers.get_backup_fpaths(ibs)
            logger.info('backups = %r' % (backups, ))
            sqlstaging_fpath = backups[backup_idx]
            logger.info('CHOSE BACKUP sqlstaging_fpath = %r' %
                        (sqlstaging_fpath, ))
        # HACK
        if backup_idx is None and ibs._needs_backup():
            try:
                _sql_helpers.ensure_daily_database_backup(
                    ibs.get_ibsdir(), ibs.sqlstaging_fname, ibs.backupdir)
            except IOError as ex:
                ut.printex(
                    ex,
                    ('Failed making daily backup. '
                     'Run with --nobackup to disable'),
                )
                raise
        # IBEIS SQL State Database
        if request_stagingversion is None:
            ibs.staging_version_expected = '1.2.0'
        else:
            ibs.staging_version_expected = request_stagingversion
        # TODO: add this functionality to SQLController
        if backup_idx is None:
            new_version, new_fname = dtool.sql_control.dev_test_new_schema_version(
                ibs.get_dbname(),
                ibs.get_ibsdir(),
                ibs.sqlstaging_fname,
                ibs.staging_version_expected,
                version_next='1.2.0',
            )
            ibs.staging_version_expected = new_version
            ibs.sqlstaging_fname = new_fname
        if sqlstaging_fpath is None:
            assert backup_idx is None
            sqlstaging_fpath = join(ibs.get_ibsdir(), ibs.sqlstaging_fname)
            readonly = None
        else:
            readonly = True
        ibs.staging = dtool.SQLDatabaseController(
            fpath=sqlstaging_fpath,
            inmemory=False,
            readonly=readonly,
            always_check_metadata=False,
        )
        ibs.readonly = ibs.staging.readonly

        if backup_idx is None:
            # Ensure correct schema versions
            _sql_helpers.ensure_correct_version(
                ibs,
                ibs.staging,
                ibs.staging_version_expected,
                STAGING_SCHEMA,
                verbose=ut.VERBOSE,
            )