コード例 #1
0
ファイル: AlembicUtils.py プロジェクト: hannahp/PyGlass
    def initializeDatabase(cls, databaseUrl):
        migrationRootPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(databaseUrl, root=True)
        migrationPath     = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(databaseUrl)
        configPath        = os.path.join(migrationPath, 'alembic.ini')
        workingPath       = os.curdir

        if not os.path.exists(migrationRootPath):
            os.makedirs(migrationRootPath)

        if os.path.exists(migrationPath + 'alembic.ini'):
            return False

        os.chdir(migrationRootPath)

        config                  = alembicConfig.Config()
        config.config_file_name = configPath

        alembicCmd.init(
            config=config,
            directory=migrationPath
        )

        # Refresh config with proper settings
        cp = ConfigParser.ConfigParser()
        cp.read(configPath)
        cp.set('alembic', 'sqlalchemy.url', PyGlassModelUtils.getEngineUrl(databaseUrl))

        f = open(configPath, 'w+')
        cp.write(f)
        f.close()

        os.chdir(workingPath)
        return True
コード例 #2
0
ファイル: AlembicUtils.py プロジェクト: sernst/PyGlass
    def getConfig(cls, databaseUrl, resourcesPath, localResourcesPath, writeCallback =None):
        """ Retrieves the Alembic configuration for the specified database URL stored within the
            resources and local resources path for the target application """

        logger = Logger(
            databaseUrl.replace('://', '~').replace('/', '--').replace('.vdb', ''),
            useStorageBuffer=True)

        if writeCallback is not None:
            logger.addWriteCallback(writeCallback)

        migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(
            databaseUrl, resourcesPath=resourcesPath)

        config = alembicConfig.Config(os.path.join(migrationPath, 'alembic.ini'), stdout=logger)

        engineUrl = PyGlassModelUtils.getEngineUrl(
            databaseUrl=databaseUrl, localResourcesPath=localResourcesPath)

        # These options are overridden during loading to prevent issues of absolute path corruption
        # when running in different deployment modes and when installed on different computers
        config.set_main_option('url', engineUrl)
        config.set_section_option('alembic', 'script_location', migrationPath)
        config.set_section_option('alembic', 'sqlalchemy.url', engineUrl)
        config.set_section_option('alembic', 'url', migrationPath)

        return config
コード例 #3
0
ファイル: AlembicUtils.py プロジェクト: hannahp/PyGlass
    def getConfig(cls, databaseUrl, writeCallback =None):
        logger = Logger(
            databaseUrl.replace(u'://', u'~').replace(u'/', u'--').replace(u'.vdb', u''),
            useStorageBuffer=True
        )
        if writeCallback is not None:
            logger.addWriteCallback(writeCallback)

        migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(databaseUrl)
        config = alembicConfig.Config(os.path.join(migrationPath, 'alembic.ini'), stdout=logger)

        config.set_main_option(
            'script_location',
            migrationPath
        )

        config.set_main_option(
            'sqlalchemy.url',
            PyGlassModelUtils.getEngineUrl(databaseUrl)
        )

        config.set_main_option(
            'url',
            PyGlassModelUtils.getEngineUrl(databaseUrl)
        )

        return config
コード例 #4
0
ファイル: AlembicUtils.py プロジェクト: hannahp/PyGlass
 def hasMigrationEnvironment(cls, databaseUrl):
     migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(databaseUrl)
     if not os.path.exists(migrationPath):
         return False
     if not os.path.exists(os.path.join(migrationPath, 'alembic.ini')):
         return False
     if not os.path.exists(migrationPath + 'versions'):
         return False
     return True
コード例 #5
0
ファイル: AlembicUtils.py プロジェクト: sernst/PyGlass
    def initializeDatabase(cls, databaseUrl, resourcesPath =None, localResourcesPath =None):

        migrationRootPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(
            databaseUrl=databaseUrl,
            root=True,
            resourcesPath=resourcesPath)

        migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(
            databaseUrl=databaseUrl,
            resourcesPath=resourcesPath)

        configPath = FileUtils.makeFilePath(migrationPath, 'alembic.ini')

        if not os.path.exists(migrationRootPath):
            os.makedirs(migrationRootPath)

        if os.path.exists(migrationPath + 'alembic.ini'):
            return False

        os.chdir(migrationRootPath)

        config = alembicConfig.Config()
        config.config_file_name = configPath

        alembicCmd.init(config=config, directory=migrationPath)

        # Refresh config with proper settings
        cp = configparser.ConfigParser()
        cp.read(configPath)
        cp.set('alembic', 'sqlalchemy.url', PyGlassModelUtils.getEngineUrl(
            databaseUrl=databaseUrl,
            localResourcesPath=localResourcesPath))

        f = open(configPath, 'w+')
        cp.write(f)
        f.close()

        return True
コード例 #6
0
ファイル: AlembicUtils.py プロジェクト: sernst/PyGlass
    def hasMigrationEnvironment(cls, databaseUrl, resourcesPath =None):
        """ Determines whether or not the specified application database currently has a migration
            environment setup
            :param databaseUrl:
            :param resourcesPath:
            :return: True or false depending on the presence of a migration environment """

        if not resourcesPath:
            resourcesPath = PyGlassEnvironment.getRootResourcePath(isDir=True)

        migrationPath = PyGlassModelUtils.getMigrationPathFromDatabaseUrl(
            databaseUrl=databaseUrl, resourcesPath=resourcesPath)

        if not os.path.exists(migrationPath):
            return False
        if not os.path.exists(FileUtils.makeFilePath(migrationPath, 'alembic.ini')):
            return False
        if not os.path.exists(FileUtils.makeFolderPath(migrationPath, 'versions')):
            return False
        return True