Example #1
0
    def make_update_script_for_model(cls, engine, oldmodel, model, repository,
                                     **opts):
        """Create a migration script"""

        # Compute differences.
        if isinstance(repository, basestring):
            from migrate.versioning.repository import Repository  # oh dear, an import cycle!
            repository = Repository(repository)
        oldmodel = loadModel(oldmodel)
        model = loadModel(model)
        diff = schemadiff.getDiffOfModelAgainstModel(
            oldmodel, model, engine, excludeTables=[repository.version_table])
        decls, upgradeCommands, downgradeCommands = genmodel.ModelGenerator(
            diff).toUpgradeDowngradePython()

        # Store differences into file.
        template_file = None
        src = template.get_script(template_file)
        contents = open(src).read()
        search = 'def upgrade():'
        contents = contents.replace(search, decls + '\n\n' + search, 1)
        if upgradeCommands:
            contents = contents.replace('    pass', upgradeCommands, 1)
        if downgradeCommands:
            contents = contents.replace('    pass', downgradeCommands, 1)
        return contents
Example #2
0
    def make_update_script_for_model(cls, engine, oldmodel,
                                     model, repository, **opts):
        """Create a migration script"""
        
        # Compute differences.
        if isinstance(repository, basestring):
            # oh dear, an import cycle!
            from migrate.versioning.repository import Repository
            repository = Repository(repository)
        oldmodel = load_model(oldmodel)
        model = load_model(model)
        diff = schemadiff.getDiffOfModelAgainstModel(
            oldmodel,
            model,
            engine,
            excludeTables=[repository.version_table])
        decls, upgradeCommands, downgradeCommands = \
            genmodel.ModelGenerator(diff).toUpgradeDowngradePython()

        # Store differences into file.
        template_file = None
        src = template.get_script(template_file)
        contents = open(src).read()
        search = 'def upgrade():'
        contents = contents.replace(search, '\n\n'.join((decls, search)), 1)
        if upgradeCommands:
            contents = contents.replace('    pass', upgradeCommands, 1)
        if downgradeCommands:
            contents = contents.replace('    pass', downgradeCommands, 1)
        return contents
Example #3
0
    def create(cls, path, **opts):
        """Create an empty migration script"""
        cls.require_notfound(path)

        filename = None
        if opts.get('logsql', False):
            filename = 'logsql.py_tmpl'
        src = template.get_script(filename)
        shutil.copy(src, path)
Example #4
0
    def create(cls,path,**opts):
        """Create an empty migration script"""
        cls.require_notfound(path)

        filename = None
        if opts.get('logsql',False):
            filename = 'logsql.py_tmpl'
        src=template.get_script(filename)
        shutil.copy(src,path)
Example #5
0
    def create(cls,path,**opts):
        """Create an empty migration script"""
        cls.require_notfound(path)

        # TODO: Use the default script template (defined in the template
        # module) for now, but we might want to allow people to specify a
        # different one later.
        template_file = None
        src = template.get_script(template_file)
        shutil.copy(src,path)
Example #6
0
    def create(cls, path, **opts):
        """Create an empty migration script"""
        cls.require_notfound(path)

        # TODO: Use the default script template (defined in the template
        # module) for now, but we might want to allow people to specify a
        # different one later.
        template_file = None
        src = template.get_script(template_file)
        shutil.copy(src, path)