コード例 #1
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
     for domain in Domain.get_all():
         domain.delete()
     super(ReportConfigurationDbTest, cls).tearDownClass()
コード例 #2
0
ファイル: pillow.py プロジェクト: dslowikowski/commcare-hq
    def bootstrap(self, configs=None):
        # sets up the initial stuff
        if configs is None:
            configs = DataSourceConfiguration.all()

        self.tables = [IndicatorSqlAdapter(self.get_sql_engine(), config) for config in configs]
        self.bootstrapped = True
コード例 #3
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
     for domain in Domain.get_all():
         domain.delete()
     super(ReportConfigurationDbTest, cls).tearDownClass()
コード例 #4
0
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        engine_ids = self._get_engine_ids(data_sources,
                                          options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id in engine_ids:
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                migration_context = get_migration_context(
                    connection, include_object=_include_object)
                raw_diffs = compare_metadata(migration_context, metadata)

            diffs = reformat_alembic_diffs(raw_diffs)
            tables_to_remove_by_engine[engine_id] = [
                diff.table_name for diff in diffs
                if diff.type == 'remove_table'
            ]

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            engine = connection_manager.get_engine(engine_id)
            for tablename in tablenames:
                with engine.begin() as connection:
                    try:
                        result = connection.execute(
                            'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'
                            .format(tablename=tablename))
                    except Exception:
                        print(tablename,
                              "no inserted_at column, probably not UCR")
                    else:
                        print(tablename, result.fetchone())
コード例 #5
0
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        engine_ids = self._get_engine_ids(data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id in engine_ids:
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                migration_context = get_migration_context(connection, include_object=_include_object)
                raw_diffs = compare_metadata(migration_context, metadata)

            diffs = reformat_alembic_diffs(raw_diffs)
            tables_to_remove_by_engine[engine_id] = [
                diff.table_name for diff in diffs
                if diff.type == 'remove_table'
            ]

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            engine = connection_manager.get_engine(engine_id)
            for tablename in tablenames:
                with engine.begin() as connection:
                    try:
                        result = connection.execute(
                            'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'.format(tablename=tablename)
                        )
                    except Exception:
                        print(tablename, "no inserted_at column, probably not UCR")
                    else:
                        print(tablename, result.fetchone())
コード例 #6
0
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        tables_by_engine_id = self._get_tables_by_engine_id(
            data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id, expected_tables in tables_by_engine_id.items():
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                # Using string formatting rather than execute with %s syntax
                # is acceptable here because the strings we're inserting are static
                # and only templated for DRYness
                results = connection.execute(f"""
                SELECT table_name
                  FROM information_schema.tables
                WHERE table_schema='public'
                  AND table_type='BASE TABLE'
                  AND (
                    table_name LIKE '{UCR_TABLE_PREFIX}%%'
                    OR
                    table_name LIKE '{LEGACY_UCR_TABLE_PREFIX}%%'
                );
                """).fetchall()
                tables_in_db = {r[0] for r in results}

            tables_to_remove_by_engine[
                engine_id] = tables_in_db - expected_tables

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            print("\nTables no longer referenced in database: {}:\n".format(
                engine_id))
            engine = connection_manager.get_engine(engine_id)
            if not tablenames:
                print("\t No tables to prune")
                continue

            for tablename in tablenames:
                with engine.begin() as connection:
                    try:
                        result = connection.execute(
                            f'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'
                        )
                    except Exception:
                        print(
                            f"\t{tablename}: no inserted_at column, probably not UCR"
                        )
                    else:
                        row_count, idle_since = result.fetchone()
                        if row_count == 0:
                            print(f"\t{tablename}: {row_count} rows")
                            if options['drop_empty_tables']:
                                connection.execute(f'DROP TABLE "{tablename}"')
                                print(f'\t^-- deleted {tablename}')
                        else:
                            print(
                                f"\t{tablename}: {row_count} rows, idle since {idle_since}"
                            )
コード例 #7
0
    def setUpClass(cls):
        super(DataSourceConfigurationDbTest, cls).setUpClass()

        # TODO - handle cleanup appropriately so this isn't needed
        for data_source_config in DataSourceConfiguration.all():
            data_source_config.delete()

        DataSourceConfiguration(domain='foo', table_id='foo1', referenced_doc_type='XFormInstance').save()
        DataSourceConfiguration(domain='foo', table_id='foo2', referenced_doc_type='XFormInstance').save()
        DataSourceConfiguration(domain='bar', table_id='bar1', referenced_doc_type='XFormInstance').save()
コード例 #8
0
    def setUpClass(cls):
        super(DataSourceConfigurationDbTest, cls).setUpClass()

        # TODO - handle cleanup appropriately so this isn't needed
        for data_source_config in DataSourceConfiguration.all():
            data_source_config.delete()

        DataSourceConfiguration(domain='foo', table_id='foo1', referenced_doc_type='XFormInstance').save()
        DataSourceConfiguration(domain='foo', table_id='foo2', referenced_doc_type='XFormInstance').save()
        DataSourceConfiguration(domain='bar', table_id='bar1', referenced_doc_type='XFormInstance').save()
コード例 #9
0
def _data_sources_by_engine_id():
    by_engine_id = defaultdict(list)
    for ds in StaticDataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    for ds in DataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    return by_engine_id
コード例 #10
0
def _data_sources_by_engine_id():
    by_engine_id = defaultdict(list)
    for ds in StaticDataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    for ds in DataSourceConfiguration.all():
        ds_engine_id = ds['engine_id']
        by_engine_id[ds_engine_id].append(ds)

    return by_engine_id
コード例 #11
0
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        tables_by_engine_id = self._get_tables_by_engine_id(
            data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id, expected_tables in tables_by_engine_id.items():
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                results = connection.execute("""
                SELECT table_name
                  FROM information_schema.tables
                WHERE table_schema='public'
                  AND table_type='BASE TABLE'
                  AND (
                    table_name LIKE '{}%%'
                    OR
                    table_name LIKE '{}%%'
                );
                """.format(UCR_TABLE_PREFIX,
                           LEGACY_UCR_TABLE_PREFIX)).fetchall()
                tables_in_db = {r[0] for r in results}

            tables_to_remove_by_engine[
                engine_id] = tables_in_db - expected_tables

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            print("\nTables no longer referenced in database: {}:\n".format(
                engine_id))
            engine = connection_manager.get_engine(engine_id)
            if not tablenames:
                print("\t No tables to prune")
                continue

            for tablename in tablenames:
                if options['show_counts']:
                    with engine.begin() as connection:
                        try:
                            result = connection.execute(
                                'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'
                                .format(tablename=tablename))
                        except Exception:
                            print(
                                "\t{}: no inserted_at column, probably not UCR"
                                .format(tablename))
                        else:
                            print("\t{}: {}".format(tablename,
                                                    result.fetchone()))
                else:
                    print("\t{}".format(tablename))
コード例 #12
0
    def handle(self, **options):
        data_sources = list(DataSourceConfiguration.all())
        data_sources.extend(list(StaticDataSourceConfiguration.all()))

        tables_by_engine_id = self._get_tables_by_engine_id(data_sources, options.get('engine_id'))

        tables_to_remove_by_engine = defaultdict(list)
        for engine_id, expected_tables in tables_by_engine_id.items():
            engine = connection_manager.get_engine(engine_id)
            with engine.begin() as connection:
                results = connection.execute("""
                SELECT table_name
                  FROM information_schema.tables
                WHERE table_schema='public'
                  AND table_type='BASE TABLE'
                  AND (
                    table_name LIKE '{}%%'
                    OR
                    table_name LIKE '{}%%'
                );
                """.format(UCR_TABLE_PREFIX, LEGACY_UCR_TABLE_PREFIX)).fetchall()
                tables_in_db = {r[0] for r in results}

            tables_to_remove_by_engine[engine_id] = tables_in_db - expected_tables

        for engine_id, tablenames in tables_to_remove_by_engine.items():
            print("\nTables no longer referenced in database: {}:\n".format(engine_id))
            engine = connection_manager.get_engine(engine_id)
            if not tablenames:
                print("\t No tables to prune")
                continue

            for tablename in tablenames:
                if options['show_counts']:
                    with engine.begin() as connection:
                        try:
                            result = connection.execute(
                                'SELECT COUNT(*), MAX(inserted_at) FROM "{tablename}"'.format(tablename=tablename)
                            )
                        except Exception:
                            print("\t{}: no inserted_at column, probably not UCR".format(tablename))
                        else:
                            print("\t{}: {}".foramt(tablename, result.fetchone()))
                else:
                    print("\t{}".format(tablename))
コード例 #13
0
ファイル: pillow.py プロジェクト: ansarbek/commcare-hq
 def get_all_configs(self):
     return filter(lambda config: not config.is_deactivated, DataSourceConfiguration.all())
コード例 #14
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
     super(ReportTranslationTest, cls).tearDownClass()
コード例 #15
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     super(DataSourceConfigurationDbTest, cls).tearDownClass()
コード例 #16
0
 def tearDownClass(cls):
     cls.app.delete()
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
     super(ReportBuilderDBTest, cls).tearDownClass()
コード例 #17
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     super(DataSourceConfigurationDbTest, cls).tearDownClass()
コード例 #18
0
ファイル: test_view.py プロジェクト: sheelio/commcare-hq
 def _delete_everything(cls):
     delete_all_cases()
     for config in DataSourceConfiguration.all():
         config.delete()
     for config in ReportConfiguration.all():
         config.delete()
コード例 #19
0
 def get_all_configs(self):
     return DataSourceConfiguration.all()
コード例 #20
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
     super(ReportTranslationTest, cls).tearDownClass()
コード例 #21
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
コード例 #22
0
 def _delete_everything(cls):
     delete_all_cases()
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
コード例 #23
0
 def tearDownClass(cls):
     cls.app.delete()
     for config in DataSourceConfiguration.all():
         config.delete()
     delete_all_report_configs()
コード例 #24
0
 def get_data_sources(self):
     return filter(lambda config: not config.is_deactivated,
                   DataSourceConfiguration.all())
コード例 #25
0
 def test_get_all(self):
     self.assertEqual(3, len(list(DataSourceConfiguration.all())))
コード例 #26
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
コード例 #27
0
 def get_data_sources(self):
     return [
         config for config in DataSourceConfiguration.all()
         if not config.is_deactivated
     ]
コード例 #28
0
 def tearDownClass(cls):
     cls.app.delete()
     for config in DataSourceConfiguration.all():
         config.delete()
     for config in ReportConfiguration.all():
         config.delete()
コード例 #29
0
 def test_get_all(self):
     self.assertEqual(3, len(list(DataSourceConfiguration.all())))
コード例 #30
0
    def tearDown(self):
        delete_all_report_configs()
        for config in DataSourceConfiguration.all():
            config.delete()

        super().tearDown()
コード例 #31
0
 def tearDownClass(cls):
     for config in DataSourceConfiguration.all():
         config.delete()
     for config in ReportConfiguration.all():
         config.delete()
コード例 #32
0
ファイル: pillow.py プロジェクト: aristide/commcare-hq
 def get_all_configs(self):
     return DataSourceConfiguration.all()