Finds and returns the location of the database migrations directory.
    This function is used from a setuptools entry-point for db-migrator.
506373
def find_migrations_directory():
    
    here = os.path.abspath(os.path.dirname(__file__))
    return os.path.join(here, 'sql/migrations')
502467
def GetLocalPath(self, inode, cache, database):
    
    local_path = cache.GetResults('local_path')
    if not local_path:
      results = database.Query(self.LOCAL_PATH_CACHE_QUERY)

      cache.CacheQueryResults(
          results, 'local_path', 'child_inode_number',
          ('parent_inode_number', 'filename'))
      local_path = cache.GetResults('local_path')

    parent, path = local_path.get(inode, [None, None])

    # TODO: Read the local_sync_root from the sync_config.db and use that
    # for a root value.
    root_value = '%local_sync_root%/'

    if not path:
      return root_value

    paths = []
    while path:
      paths.append(path)
      parent, path = local_path.get(parent, [None, None])

    if not paths:
      return root_value

    # Paths are built top level to root so we need to reverse the list to
    # represent them in the traditional order.
    paths.reverse()
    return root_value + '/'.join(paths)
373636
def is_current?
      ::Sequel.extension(:migration)
      ::Sequel::Migrator.is_current?(database, migration_directory)
    rescue => e
      raise ConnectionFailed, e
    end
478080
private function importMigrations()
	{
		$databaseFolder = base_path( 'resources/database/migrations/' );
		if( ! file_exists( $databaseFolder ) ) {
			return $this->line( 'no migrations to move' );
		}
		$this->moveFilesToDatabaseMigrations( $databaseFolder );
	}
416719
def setup_migrate(app):
    """"""
    directory = path.join(path.dirname(__file__), 'migrations')
    migrate.init_app(app, db, directory=directory)
925389
def _sincedb_start_position(self):
        
        if not self._sincedb_path:
            return None

        self._sincedb_init()
        self._log_debug('retrieving start_position from sincedb')
        conn = sqlite3.connect(self._sincedb_path, isolation_level=None)
        cursor = conn.cursor()
        cursor.execute('select position from sincedb where fid = :fid and filename = :filename', {
            'fid': self._fid,
            'filename': self._filename
        })

        start_position = None
        for row in cursor.fetchall():
            start_position, = row

        return start_position
828343
def sorted_migrations(self):
        
        if not self._sorted_migrations:
            self._sorted_migrations = sorted(
                self.migration_registry.items(),
                # sort on the key... the migration number
                key=lambda migration_tuple: migration_tuple[0])

        return self._sorted_migrations
790878
def handle(self):
        
        database = self.option("database")

        self.resolver.set_default_connection(database)

        repository = DatabaseMigrationRepository(self.resolver, "migrations")

        migrator = Migrator(repository, self.resolver)

        if not migrator.repository_exists():
            return self.error("No migrations found")

        self._prepare_database(migrator, database)

        path = self.option("path")

        if path is None:
            path = self._get_migration_path()

        ran = migrator.get_repository().get_ran()

        migrations = []
        for migration in migrator._get_migration_files(path):
            if migration in ran:
                migrations.append(["<fg=cyan>%s</>" % migration, "<info>Yes</>"])
            else:
                migrations.append(["<fg=cyan>%s</>" % migration, "<fg=red>No</>"])

        if migrations:
            table = self.table(["Migration", "Ran?"], migrations)
            table.render()
        else:
            return self.error("No migrations found")

        for note in migrator.get_notes():
            self.line(note)
105354
function (directory) {
            var retClass = IntegerMigrator, MIGRATION_SPLITTER = this.MIGRATION_SPLITTER, MINIMUM_TIMESTAMP = this.MINIMUM_TIMESTAMP;
            return this.getFileNames(directory).chain(function (files) {
                var l = files.length;
                if (l) {
                    for (var i = 0; i < l; i++) {
                        var file = files[i];
                        if (parseInt(path.basename(file).split(MIGRATION_SPLITTER)[0], 10) > MINIMUM_TIMESTAMP) {
                            retClass = TimestampMigrator;
                            break;
                        }
                    }
                }
                return retClass;
            });
        }
341137
def rollback_migration(engine, connection, path, migration_to_rollback):
    

    # Get migrations applied
    migrations_applied = get_migrations_applied(engine, connection)

    # Ensure that the migration was previously applied
    if not is_applied(migrations_applied, migration_to_rollback):
        raise RuntimeError(
            '`%s` is not in the list of previously applied migrations.' % (migration_to_rollback))

    # Rollback file
    file = path + migration_to_rollback + '/down.sql'

    # Ensure that the file exists
    check_exists(file)

    # Set vars
    basename = os.path.basename(os.path.dirname(file))

    # Get migration source
    source = get_migration_source(file)
    # print (source);

    # Run migration rollback
    run_migration(connection, source, engine)

    # Delete migration
    delete_migration(connection, basename)

    # Log
    print('   -> Migration `%s` has been rolled back' % (basename))

    return True
311742
def _MigrationFilenameToInt(fname):
  """"""
  base, _ = os.path.splitext(fname)
  return int(base)
1103017
def get_schema_dir(db_version=1):
    
    v = str(db_version)
    return os.path.join(_top_dir, '..', 'schemata', 'versions', v)
712885
def _call_migrate(self, module, connection_param):
        
        args = [connection_param]
        spec = inspect.getargspec(module.migrate)
        if len(spec.args) == 2:
            args.append(self.db_config)
        return module.migrate(*args)
966545
def create_migration_ctx(**kwargs):
    """"""
    env = EnvironmentContext(Config(), None)
    env.configure(
        connection=db.engine.connect(),
        sqlalchemy_module_prefix='db.',
        **kwargs
    )
    return env.get_context()
430343
def get_dropbox_folder_location():
    
    host_db_path = os.path.join(os.environ['HOME'], '.dropbox/host.db')
    try:
        with open(host_db_path, 'r') as f_hostdb:
            data = f_hostdb.read().split()
    except IOError:
        error("Unable to find your Dropbox install =(")
    dropbox_home = base64.b64decode(data[1]).decode()

    return dropbox_home
150807
def _GetDirectory(self):
    
    if self.entry_type != definitions.FILE_ENTRY_TYPE_DIRECTORY:
      return None
    return SQLiteBlobDirectory(self._file_system, self.path_spec)
392201
def deploy_db(rollback=False):
    
    if not rollback:

        if env.DEFAULT_DATABASE_ENGINE=='django.db.backends.sqlite3':
            db_dir = '/'.join([deployment_root(),'database'])
            db_name = ''.join([env.project_name,'_','site_1','.db'])
            dest_db_path = '/'.join([db_dir,db_name])
            if exists(dest_db_path): return
            if env.verbosity:
                print env.host,"DEPLOYING DEFAULT SQLITE DATABASE"
            if not env.DEFAULT_DATABASE_NAME:
                print "ERROR: A database name has not been defined in your Django settings file"
                sys.exit(1)

            if env.DEFAULT_DATABASE_NAME[0] not in [os.path.sep,'.']: #relative path
                db_path = os.path.join(os.getcwd(),env.project_package_name,env.DEFAULT_DATABASE_NAME)

            elif env.DEFAULT_DATABASE_NAME[:2] == '..':
                print "ERROR: Use a full expanded path to the database in your Django settings"
                sys.exit(1)
            else:
                db_path = env.DEFAULT_DATABASE_NAME

            if not db_path or not os.path.exists(db_path):
                print "ERROR: the database %s does not exist. \nRun python manage.py syncdb to create your database locally first, or check your settings."% db_path
                sys.exit(1)

            db_name = os.path.split(db_path)[1]  
            run('mkdir -p '+db_dir)
            put(db_path,dest_db_path)
            #directory and file must be writable by webserver
            sudo("chown -R %s:www-data %s"% (env.user,db_dir))
            sudo("chmod -R ug+w %s"% db_dir)
        
        elif env.DEFAULT_DATABASE_ENGINE=='django.db.backends.':
            print "ERROR: The default database engine has not been defined in your Django settings file"
            print "At a minimum you must define an sqlite3 database for woven to deploy, or define a database that is managed outside of woven."
            sys.exit(1)
    elif rollback and env.DEFAULT_DATABASE_ENGINE=='django.db.backends.sqlite3':
        if env.INTERACTIVE:
            delete = confirm('DELETE the database on the host?',default=False)
            if delete:
                run('rm -f '+db_name)
    return