Replace a database with the data from the specified source.
761671
def run(self):
        
        self.print_message("\nBeginning database replacement process.\n")

        if self.args.source_settings:
            settings = self.parse_db_settings(self.args.source_settings)
            self.initialize_db_args(settings, 'source')

        if self.args.settings:
            settings = self.parse_db_settings(self.args.settings)
            self.initialize_db_args(settings, 'destination')

        if self.args.capture:
            self.capture_heroku_database()

        file_url = self.args.url
        if self.args.source_app:
            self.print_message("Sourcing data from backup for Heroku app '%s'"
                               % self.args.source_app)
            file_url = self.get_file_url_for_heroku_app(self.args.source_app)

        if self.args.destination_app:
            self.replace_heroku_db(file_url)
        elif self.databases['destination']['name']:
            self.replace_postgres_db(file_url)

        self.print_message("\nDone.\n\nDon't forget to update the Django Site entry if necessary!")
1245265
def from_db(cls, db, force=False):
        
        if force or db not in cls._cache:
            cls._cache[db] = cls._new_from_db(db)
        return cls._cache[db]
1215545
def DeleteDatabase(self, database_link, options=None):
        
        if options is None:
            options = {}

        path = base.GetPathFromLink(database_link)
        database_id = base.GetResourceIdOrFullNameFromLink(database_link)
        return self.DeleteResource(path,
                                   'dbs',
                                   database_id,
                                   None,
                                   options)
1016568
def database_rename(object_id, input_params={}, always_retry=True, **kwargs):
    
    return DXHTTPRequest('/%s/rename' % object_id, input_params, always_retry=always_retry, **kwargs)
1057716
def db_create():
    """"""
    try:
        migrate_api.version_control(url=db_url, repository=db_repo)
        db_upgrade()
    except DatabaseAlreadyControlledError:
        print 'ERROR: Database is already version controlled.'
1255218
def replace_non_data_file(self, dataset_identifier, params, file_data):
        '''
        
        '''
        resource = _format_old_api_request(dataid=dataset_identifier, content_type="txt")

        if not params.get('method', None):
            params['method'] = 'replaceBlob'

        params['id'] = dataset_identifier

        return self._perform_request("post", resource, params=params, files=file_data)
834854
def createDatabase(self, name, **dbArgs) :
        ""
        dbArgs['name'] = name
        payload = json.dumps(dbArgs, default=str)
        url = self.URL + "/database"
        r = self.session.post(url, data = payload)
        data = r.json()
        if r.status_code == 201 and not data["error"] :
            db = Database(self, name)
            self.databases[name] = db
            return self.databases[name]
        else :
            raise CreationError(data["errorMessage"], r.content)
191491
def migrate(name=None, database=None, directory=None, verbose=None, fake=False):
    """"""
    router = get_router(directory, database, verbose)
    migrations = router.run(name, fake=fake)
    if migrations:
        click.echo('Migrations completed: %s' % ', '.join(migrations))
1020609
def make_dbsource(**kwargs):
    """"""
    if 'spatialite' in connection.settings_dict.get('ENGINE'):
        kwargs.setdefault('file', connection.settings_dict['NAME'])
        return mapnik.SQLite(wkb_format='spatialite', **kwargs)
    names = (('dbname', 'NAME'), ('user', 'USER'),
             ('password', 'PASSWORD'), ('host', 'HOST'), ('port', 'PORT'))
    for mopt, dopt in names:
        val = connection.settings_dict.get(dopt)
        if val:
            kwargs.setdefault(mopt, val)
    return mapnik.PostGIS(**kwargs)
1269854
def _upgrade_db(self):
        """"""
        migration_path = "_data/migrations"
        sqlite3.connect(self._db_path).close()    # ensure that it exists
        db_url = "sqlite:///" + self._db_path
        backend = yoyo.get_backend(db_url)
        migration_dir = pkg_resources.resource_filename(__package__, migration_path)
        migrations = yoyo.read_migrations(migration_dir)
        assert len(migrations) > 0, "no migration scripts found -- wrong migraion path for " + __package__
        migrations_to_apply = backend.to_apply(migrations)
        backend.apply_migrations(migrations_to_apply)
718360
def sql(self):
        """"""
        from fasta.indexed import DatabaseFASTA, fasta_to_sql
        db = DatabaseFASTA(self.prefix_path + ".db")
        if not db.exists: fasta_to_sql(self.path, db.path)
        return db
550394
def db(self):
        
        if self.database is NotImplemented:
            self.database = Session

        return self.database
523549
def connect(url=None, schema=None, sql_path=None, multiprocessing=False):
    
    if url is None:
        url = os.environ.get("DATABASE_URL")
    return Database(url, schema, sql_path=sql_path, multiprocessing=multiprocessing)
881798
def update(database, table, key):
    """"""
    field = random.randrange(10)
    value = ''.join(random.choice(string.printable) for i in range(100))
    with database.batch() as batch:
        batch.update(table=table, columns=('id', 'field%d' % field),
                     values=[(key, value)])
165348
def update(self, **data):
        
        data = data.items()
        update_command_arg = ", ".join("{} = ?".format(entry[0])
                                       for entry in data)
        cmd = "update {table} set {update_command_arg} {where_clause}".format(
            update_command_arg=update_command_arg,
            where_clause=self.where_clause,
            table=self.table_name).rstrip()
        Repo.db.execute(cmd, [entry[1] for entry in data] + self.where_values)
1354027
def alter_database(self, dbname, db):
    
    self.send_alter_database(dbname, db)
    self.recv_alter_database()
83741
def _update_datasource(self, source, data):
        
        if isinstance(source, ColumnDataSource):
            if self.handles['static_source']:
                source.trigger('data', source.data, data)
            else:
                source.data.update(data)
        else:
            source.graph_layout = data