Prints filename of a new migration
195894
def print_new(ctx, name, migration_type):
    """"""
    click.echo(ctx.obj.repository.generate_migration_name(name, migration_type))
510249
function getNewFilename(list, name) {
  if (list.indexOf(name) === -1) {
    return name;
  }
  const parsed = parseFilename(name);
  const base = parsed.base;
  const ext = parsed.ext;
  if (!base) {
    const newName = getNextNumberName(ext);
    return getNewFilename(list, newName);
  } else {
    const basename = getNextNumberName(base);
    return getNewFilename(list, `${basename}${ext}`);
  }
}
1128264
def announce_migration(message)
      text = "#{name}: #{message}"
      length = [0, 75 - text.length].max
      puts "== %s %s" % [text, "=" * length]
    end
954463
def apply_migrations(engine, connection, path):
    

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

    # Get migrations folder
    for file in get_migrations_files(path):
        # Set vars
        basename = os.path.basename(os.path.dirname(file))

        # Skip migrations if they are already applied
        if is_applied(migrations_applied, basename):
            continue

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

        # Run migration
        run_migration(connection, source, engine)

        # Save migration
        save_migration(connection, basename)

        # Log
        print('   -> Migration `%s` applied' % (basename))

    # Log
    print(' * Migrations applied')

    return True
102907
def runSql(self, migrationName, version):
        
        sys.stdout.write("Running migration %s to version %s: ..."%(migrationName, version))
        sqlPath = os.path.join(self.migrationDirectory, migrationName)
        sql = open(sqlPath, "r").read()
        try:
            if self.session.is_active:
                print "session is active"
                self.session.commit()
            self.session.begin()
            executeBatch(self.session, sql)
            self.session.add(models.Migration(version, migrationName))
        except:
            print "\n"
            self.session.rollback()
            raise
        else:
            self.session.commit()
        sys.stdout.write("\r")
        sys.stdout.flush()
        sys.stdout.write("Running migration %s to version %s: SUCCESS!\n"%(migrationName, version))
517655
def list_migrations(self):
        
        connection = connections[self._database_name]
        loader = MigrationLoader(connection, ignore_no_migrations=True)
        unapplied = self._get_unapplied_migrations(loader)
        currents = self._get_current_migration_state(loader, [u[0] for u in unapplied])
        return unapplied, currents
1029470
def get_migration(plugin, filename):
    ''''''
    db = get_db()
    return db.migrations.find_one({'plugin': plugin, 'filename': filename})
592141
def record_migration(plugin, filename, script, **kwargs):
    ''''''
    db = get_db()
    db.eval(RECORD_WRAPPER, plugin, filename, script)
    return True
159109
def next_migration_number(dirname)
      next_migration_number = current_migration_number(dirname) + 1
      if ActiveRecord::Base.timestamped_migrations
        [Time.now.utc.strftime("%Y%m%d%H%M%S"), format("%.14d", next_migration_number)].max
      else
        format("%.3d", next_migration_number)
      end
    end
866750
def get_new_filename(diff_part):
    
    regexps = (
        # e.g. "+++ b/foo/bar"
        r'^\+\+\+ b/(.*)',
        # e.g. "+++ /dev/null"
        r'^\+\+\+ (.*)',
    )
    for regexp in regexps:
        r = re.compile(regexp, re.MULTILINE)
        match = r.search(diff_part)
        if match is not None:
            return match.groups()[0]
    raise MalformedGitDiff("No new filename in diff part found.  "
                           "Examined diff part: {}".format(diff_part))
1110545
def migrate_connections(new_data_path: str):
    
    dest_connections = os.path.join(
        new_data_path, 'lib', 'NetworkManager', 'system-connections')
    os.makedirs(dest_connections, exist_ok=True)

    with mount_state_partition() as state_path:
        src_connections = os.path.join(
            state_path, 'root-overlay', 'etc', 'NetworkManager',
            'system-connections')
        LOG.info(f"migrate_connections: moving nmcli connections from"
                 f" {src_connections} to {dest_connections}")
        found = migrate_system_connections(src_connections, dest_connections)

    if found:
        return

    LOG.info(
        "migrate_connections: No connections found in state, checking boot")

    with mount_boot_partition() as boot_path:
        src_connections = os.path.join(
            boot_path, 'system-connections')
        LOG.info(f"migrate_connections: moving nmcli connections from"
                 f" {src_connections} to {dest_connections}")
        found = migrate_system_connections(src_connections, dest_connections)
        if not found:
            LOG.info("migrate_connections: No connections found in boot")
989765
async def getFormTodo(self, name):
        '''
        
        '''
        size = 0
        logger.warning(f'MIGRATION: calculating form todo: {name}')
        async with self.getTempSlab() as slab:

            for layr in self.layers:

                async for buid, valu in layr.iterFormRows(name):
                    slab.put(buid, s_msgpack.en(valu), overwrite=False)
                    size += 1

            logger.warning(f'MIGRATION: {name} todo size: {size}')

            for buid, byts in slab.scanByFull():
                yield buid, s_msgpack.un(byts)
1357982
def show_status(self):
        """"""
        if not self.check_directory():
            return

        migrations = self.get_unregistered_migrations()
        if migrations:
            logger.info('Unregistered migrations:')
            for migration in migrations:
                logger.info(migration.filename)
        else:
            logger.info(self.NO_MIGRATIONS_MSG)
177231
def get_connection_filename(filename, tmp_path = None, replace_file = False, verbose = False):
	
	def mktmp(path, suffix = ".sqlite", verbose = False):
		with temporary_files_lock:
			# make sure the clean-up signal traps are installed
			install_signal_trap()
			# create the remporary file and replace it's
			# unlink() function
			temporary_file = tempfile.NamedTemporaryFile(suffix = suffix, dir = path if path != "_CONDOR_SCRATCH_DIR" else os.getenv("_CONDOR_SCRATCH_DIR"))
			def new_unlink(self, orig_unlink = temporary_file.unlink):
				# also remove a -journal partner, ignore all errors
				try:
					orig_unlink("%s-journal" % self)
				except:
					pass
				orig_unlink(self)
			temporary_file.unlink = new_unlink
			filename = temporary_file.name
			# hang onto reference to prevent its removal
			temporary_files[filename] = temporary_file
		if verbose:
			print >>sys.stderr, "using '%s' as workspace" % filename
		# mkstemp() ignores umask, creates all files accessible
		# only by owner;  we should respect umask.  note that
		# os.umask() sets it, too, so we have to set it back after
		# we know what it is
		umsk = os.umask(0777)
		os.umask(umsk)
		os.chmod(filename, 0666 & ~umsk)
		return filename

	def truncate(filename, verbose = False):
		if verbose:
			print >>sys.stderr, "'%s' exists, truncating ..." % filename,
		try:
			fd = os.open(filename, os.O_WRONLY | os.O_TRUNC)
		except Exception as e:
			if verbose:
				print >>sys.stderr, "cannot truncate '%s': %s" % (filename, str(e))
			return
		os.close(fd)
		if verbose:
			print >>sys.stderr, "done."

	def cpy(srcname, dstname, verbose = False):
		if verbose:
			print >>sys.stderr, "copying '%s' to '%s' ..." % (srcname, dstname),
		shutil.copy2(srcname, dstname)
		if verbose:
			print >>sys.stderr, "done."
		try:
			# try to preserve permission bits.  according to
			# the documentation, copy() and copy2() are
			# supposed preserve them but don't.  maybe they
			# don't preserve them if the destination file
			# already exists?
			shutil.copystat(srcname, dstname)
		except Exception as e:
			if verbose:
				print >>sys.stderr, "warning: ignoring failure to copy permission bits from '%s' to '%s': %s" % (filename, target, str(e))

	database_exists = os.access(filename, os.F_OK)

	if tmp_path is not None:
		# for suffix, can't use splitext() because it only keeps
		# the last bit, e.g. won't give ".xml.gz" but just ".gz"
		target = mktmp(tmp_path, suffix = ".".join(os.path.split(filename)[-1].split(".")[1:]), verbose = verbose)
		if database_exists:
			if replace_file:
				# truncate database so that if this job
				# fails the user won't think the database
				# file is valid
				truncate(filename, verbose = verbose)
			else:
				# need to copy existing database to work
				# space for modifications
				i = 1
				while True:
					try:
						cpy(filename, target, verbose = verbose)
					except IOError as e:
						import errno
						import time
						if e.errno not in (errno.EPERM, errno.ENOSPC):
							# anything other
							# than out-of-space
							# is a real error
							raise
						if i < 5:
							if verbose:
								print >>sys.stderr, "warning: attempt %d: %s, sleeping and trying again ..." % (i, errno.errorcode[e.errno])
							time.sleep(10)
							i += 1
							continue
						if verbose:
							print >>sys.stderr, "warning: attempt %d: %s: working with original file '%s'" % (i, errno.errorcode[e.errno], filename)
						with temporary_files_lock:
							del temporary_files[target]
						target = filename
					break
	else:
		with temporary_files_lock:
			if filename in temporary_files:
				raise ValueError("file '%s' appears to be in use already as a temporary database file and is to be deleted" % filename)
		target = filename
		if database_exists and replace_file:
			truncate(target, verbose = verbose)

	del mktmp
	del truncate
	del cpy

	return target
1019926
protected function getFileGenerationPath()
	{
		$path = $this->getPathByOptionOrConfig( 'path', 'migration_target_path' );
		$migrationName = str_replace('/', '_', $this->migrationName);
		$fileName = $this->getDatePrefix() . '_' . $migrationName . '.php';

		return "{$path}/{$fileName}";
	}
796176
def get_migrations_dir(graph):
    
    try:
        migrations_dir = graph.migrations_dir
    except (LockedGraphError, NotBoundError):
        migrations_dir = graph.metadata.get_path("migrations")

    if not isdir(migrations_dir):
        raise Exception("Migrations dir must exist: {}".format(migrations_dir))
    return migrations_dir
617595
def get_migrations(path):
    '''
    
    '''
    pattern = re.compile(r"\d+_[\w\d]+")
    modules = [name for _, name, _ in pkgutil.iter_modules([path])
                if pattern.match(name)
            ]

    return sorted(modules, key=lambda name: int(name.split("_")[0]))