예제 #1
0
파일: __init__.py 프로젝트: opmuse/opmuse
        def _opmuse_setup_server():
            configure(config_file=test_config_file, environment='production')

            remove_db()

            session = get_raw_session(create_all=True)
            run_fixtures(session)
            session.close()
예제 #2
0
파일: __init__.py 프로젝트: opmuse/opmuse
def setup_db(self):
    configure(config_file=test_config_file, environment='production')

    remove_db()

    self.session = get_raw_session(create_all=True)

    run_fixtures(self.session)
예제 #3
0
파일: commands.py 프로젝트: opmuse/opmuse
def command_database(action=None):
    config_path = os.path.join(root_path, "alembic.ini")

    if not os.path.exists(config_path):
        config_path = "/usr/share/opmuse/alembic.ini"

    alembic_config = Config(config_path)

    database_type = get_database_type()

    if action == "create":
        if database_type == "mysql":
            try:
                engine = get_engine(no_database=True)
                engine.execute("CREATE DATABASE IF NOT EXISTS %s" % get_database_name())
            except ProgrammingError as e:
                parser.error('Error occured while creating database: %s' % e)

        engine = get_engine()
        Base.metadata.create_all(engine)
        command.stamp(alembic_config, "head")
    # TODO rename to upgrade
    elif action == "update":
        try:
            command.upgrade(alembic_config, "head")
        except ProgrammingError as e:
            parser.error('Error occured while updating database: %s' % e)
    elif action == "downgrade":
        try:
            command.downgrade(alembic_config, "-1")
        except ProgrammingError as e:
            parser.error('Error occured while downgrading database: %s' % e)
    elif action == "drop":
        if database_type == "sqlite":
            parser.error('Dropping is unsupported for sqlite.')

        engine = get_engine(no_database=True)
        engine.execute("DROP DATABASE IF EXISTS %s" % get_database_name())
        command_whoosh("drop")
    elif action == "fixtures":
        from opmuse.test.fixtures import run_fixtures
        run_fixtures()
    elif action == "reset":
        engine = get_engine()
        engine.execute(Queue.__table__.delete())
        engine.execute(TrackPath.__table__.delete())
        engine.execute(Track.__table__.delete())
        engine.execute(ListenedTrack.__table__.delete())
        engine.execute(UserAndAlbum.__table__.delete())
        engine.execute(Album.__table__.delete())
        engine.execute(Artist.__table__.delete())
        engine.execute(CacheObject.__table__.delete())
        command_whoosh("drop")
    else:
        parser.error('Needs to provide a valid action (create, update, downgrade, drop, fixtures, reset).')