예제 #1
0
    def django_db_setup(django_db_setup, django_db_keepdb):
        database = Database(
            CLICKHOUSE_DATABASE,
            db_url=CLICKHOUSE_HTTP_URL,
            username=CLICKHOUSE_USER,
            password=CLICKHOUSE_PASSWORD,
            verify_ssl_cert=CLICKHOUSE_VERIFY,
        )

        if not django_db_keepdb:
            try:
                database.drop_database()
            except:
                pass

        database.create_database()  # Create database if it doesn't exist
        table_count = sync_execute(
            "SELECT count() FROM system.tables WHERE database = %(database)s",
            {"database": CLICKHOUSE_DATABASE})[0][0]
        create_clickhouse_tables(table_count)

        yield

        if django_db_keepdb:
            reset_clickhouse_tables()
        else:
            try:
                database.drop_database()
            except:
                pass
예제 #2
0
    def handle(self, *args, **options):
        from django.test.runner import DiscoverRunner as TestRunner

        test_runner = TestRunner(interactive=False)
        test_runner.setup_databases()
        test_runner.setup_test_environment()

        if is_clickhouse_enabled():
            from infi.clickhouse_orm import Database  # type: ignore

            from posthog.settings import (
                CLICKHOUSE_DATABASE,
                CLICKHOUSE_HTTP_URL,
                CLICKHOUSE_PASSWORD,
                CLICKHOUSE_REPLICATION,
                CLICKHOUSE_USER,
                CLICKHOUSE_VERIFY,
            )

            database = Database(
                CLICKHOUSE_DATABASE,
                db_url=CLICKHOUSE_HTTP_URL,
                username=CLICKHOUSE_USER,
                password=CLICKHOUSE_PASSWORD,
                verify_ssl_cert=CLICKHOUSE_VERIFY,
            )

            try:
                database.create_database()
            except:
                pass
            database.migrate("ee.clickhouse.migrations",
                             replicated=CLICKHOUSE_REPLICATION)
예제 #3
0
def django_db_setup(django_db_setup, django_db_keepdb):
    database = Database(
        CLICKHOUSE_DATABASE,
        db_url=CLICKHOUSE_HTTP_URL,
        username=CLICKHOUSE_USER,
        password=CLICKHOUSE_PASSWORD,
        verify_ssl_cert=CLICKHOUSE_VERIFY,
    )

    if not django_db_keepdb:
        try:
            database.drop_database()
        except:
            pass

    if not django_db_keepdb or not database.db_exists:
        database.create_database()

    database.migrate("ee.clickhouse.migrations")
    # Make DELETE / UPDATE synchronous to avoid flaky tests
    sync_execute("SET mutations_sync = 1")

    yield

    if not django_db_keepdb:
        try:
            database.drop_database()
        except:
            pass
예제 #4
0
    def handle(self, *args, **options):
        if not TEST:
            raise ValueError(
                "TEST environment variable needs to be set for this command to function"
            )

        from django.test.runner import DiscoverRunner as TestRunner

        test_runner = TestRunner(interactive=False)
        test_runner.setup_databases()
        test_runner.setup_test_environment()

        from infi.clickhouse_orm import Database

        from posthog.settings import (
            CLICKHOUSE_CLUSTER,
            CLICKHOUSE_DATABASE,
            CLICKHOUSE_HTTP_URL,
            CLICKHOUSE_PASSWORD,
            CLICKHOUSE_REPLICATION,
            CLICKHOUSE_USER,
            CLICKHOUSE_VERIFY,
        )

        database = Database(
            CLICKHOUSE_DATABASE,
            db_url=CLICKHOUSE_HTTP_URL,
            username=CLICKHOUSE_USER,
            password=CLICKHOUSE_PASSWORD,
            cluster=CLICKHOUSE_CLUSTER,
            verify_ssl_cert=CLICKHOUSE_VERIFY,
        )

        try:
            database.create_database()
        except:
            pass
        database.migrate("ee.clickhouse.migrations",
                         replicated=CLICKHOUSE_REPLICATION)