posthog/management/commands/setup_test_environment.py
help = "Set up databases for non-Python tests that depend on the Django server"
    def handle(self, *args, **options):
        if not TEST:
            raise ValueError("TEST environment variable needs to be set for this command to function")
        test_runner = TestRunner(interactive=False)
        disable_migrations()
        test_runner.setup_databases()
        test_runner.setup_test_environment()
        print("\nCreating test ClickHouse database...")  
        database = Database(
            CLICKHOUSE_DATABASE,
            db_url=CLICKHOUSE_HTTP_URL,
            username=CLICKHOUSE_USER,
            password=CLICKHOUSE_PASSWORD,
            cluster=CLICKHOUSE_CLUSTER,
            verify_ssl_cert=CLICKHOUSE_VERIFY,
            autocreate=False,
        )
        if database.db_exists:
            print(  
                f'Got an error creating the test ClickHouse database: database "{CLICKHOUSE_DATABASE}" already exists\n'
            )
            print("Destroying old test ClickHouse database...")  
            database.drop_database()
        database.create_database()
        create_clickhouse_schema_in_parallel(CREATE_MERGETREE_TABLE_QUERIES)
        create_clickhouse_schema_in_parallel(CREATE_KAFKA_TABLE_QUERIES)
        create_clickhouse_schema_in_parallel(CREATE_DISTRIBUTED_TABLE_QUERIES)
        create_clickhouse_schema_in_parallel(CREATE_MV_TABLE_QUERIES)
def create_clickhouse_schema_in_parallel(queries):