Exemplo n.º 1
0
    async def init_with_old_models(cls, config: dict, app: str, location: str):
        await Tortoise.init(config=config)
        last_version = await cls.get_last_version()
        cls.app = app
        cls.migrate_location = os.path.join(location, app)
        if last_version:
            content = last_version.content
            with open(cls.get_old_model_file(app, location), "w", encoding="utf-8") as f:
                f.write(content)

            migrate_config = cls._get_migrate_config(config, app, location)
            cls.migrate_config = migrate_config
            await Tortoise.init(config=migrate_config)

        connection = get_app_connection(config, app)
        cls.dialect = connection.schema_generator.DIALECT
        if cls.dialect == "mysql":
            from aerich.ddl.mysql import MysqlDDL

            cls.ddl = MysqlDDL(connection)
        elif cls.dialect == "sqlite":
            from aerich.ddl.sqlite import SqliteDDL

            cls.ddl = SqliteDDL(connection)
        elif cls.dialect == "postgres":
            from aerich.ddl.postgres import PostgresDDL

            cls.ddl = PostgresDDL(connection)
Exemplo n.º 2
0
 def setUp(self) -> None:
     client = Tortoise.get_connection("models")
     if client.schema_generator is MySQLSchemaGenerator:
         self.ddl = MysqlDDL(client)
     elif client.schema_generator is SqliteSchemaGenerator:
         self.ddl = SqliteDDL(client)
     elif client.schema_generator is AsyncpgSchemaGenerator:
         self.ddl = PostgresDDL(client)
Exemplo n.º 3
0
    async def init_with_old_models(cls, config: dict, app: str, location: str):
        migrate_config = cls._get_migrate_config(config, app, location)

        cls.app = app
        cls.migrate_config = migrate_config
        cls.migrate_location = os.path.join(location, app)

        await Tortoise.init(config=migrate_config)

        connection = get_app_connection(config, app)
        if connection.schema_generator is MySQLSchemaGenerator:
            cls.ddl = MysqlDDL(connection)
        else:
            raise NotImplementedError("Current only support MySQL")
Exemplo n.º 4
0
async def initialize_tests(event_loop, request):
    await Tortoise.init(config=tortoise_orm, _create_db=True)
    await generate_schema_for_client(Tortoise.get_connection("default"),
                                     safe=True)

    client = Tortoise.get_connection("default")
    if client.schema_generator is MySQLSchemaGenerator:
        Migrate.ddl = MysqlDDL(client)
    elif client.schema_generator is SqliteSchemaGenerator:
        Migrate.ddl = SqliteDDL(client)
    elif client.schema_generator is AsyncpgSchemaGenerator:
        Migrate.ddl = PostgresDDL(client)
    Migrate.dialect = Migrate.ddl.DIALECT
    request.addfinalizer(
        lambda: event_loop.run_until_complete(Tortoise._drop_databases()))
Exemplo n.º 5
0
async def initialize_tests(event_loop, request):
    tortoise_orm["connections"]["diff_models"] = "sqlite://:memory:"
    tortoise_orm["apps"]["diff_models"] = {
        "models": ["tests.diff_models"],
        "default_connection": "diff_models",
    }

    await Tortoise.init(config=tortoise_orm, _create_db=True)
    await generate_schema_for_client(Tortoise.get_connection("default"), safe=True)

    client = Tortoise.get_connection("default")
    if client.schema_generator is MySQLSchemaGenerator:
        Migrate.ddl = MysqlDDL(client)
    elif client.schema_generator is SqliteSchemaGenerator:
        Migrate.ddl = SqliteDDL(client)
    elif client.schema_generator is AsyncpgSchemaGenerator:
        Migrate.ddl = PostgresDDL(client)

    request.addfinalizer(lambda: event_loop.run_until_complete(Tortoise._drop_databases()))
Exemplo n.º 6
0
    async def init_with_old_models(cls, config: dict, app: str, location: str):
        migrate_config = cls._get_migrate_config(config, app, location)

        cls.app = app
        cls.migrate_config = migrate_config
        cls.migrate_location = os.path.join(location, app)

        await Tortoise.init(config=migrate_config)

        connection = get_app_connection(config, app)
        if connection.schema_generator.DIALECT == "mysql":
            from aerich.ddl.mysql import MysqlDDL

            cls.ddl = MysqlDDL(connection)
        elif connection.schema_generator.DIALECT == "sqlite":
            from aerich.ddl.sqlite import SqliteDDL

            cls.ddl = SqliteDDL(connection)
        elif connection.schema_generator.DIALECT == "postgres":
            from aerich.ddl.postgres import PostgresDDL

            cls.ddl = PostgresDDL(connection)
Exemplo n.º 7
0
    async def init(cls, config: dict, app: str, location: str):
        await Tortoise.init(config=config)
        last_version = await cls.get_last_version()
        cls.app = app
        cls.migrate_location = Path(location, app)
        if last_version:
            cls._last_version_content = last_version.content

        connection = get_app_connection(config, app)
        cls.dialect = connection.schema_generator.DIALECT
        if cls.dialect == "mysql":
            from aerich.ddl.mysql import MysqlDDL

            cls.ddl = MysqlDDL(connection)
        elif cls.dialect == "sqlite":
            from aerich.ddl.sqlite import SqliteDDL

            cls.ddl = SqliteDDL(connection)
        elif cls.dialect == "postgres":
            from aerich.ddl.postgres import PostgresDDL

            cls.ddl = PostgresDDL(connection)
        await cls._get_db_version(connection)
Exemplo n.º 8
0
 async def setUp(self) -> None:
     await Tortoise.init(config=TORTOISE_ORM)
     self.client = Tortoise.get_connection("default")
     self.ddl = MysqlDDL(self.client)