Exemple #1
0
class SchemaTableCommand(SchemaCommand):
    def add_arguments(self, parser):
        parser.add_argument(
            'args',
            metavar='table_name',
            nargs='+',
            help='Table names.'
        )
        super(SchemaTableCommand, self).add_arguments(parser)

    def handle(self, *args, **options):
        try:
            self.schema_tool = SchemaTool()
        except UnsupportedDBError as e:
            raise CommandError(e)

        all_tables = self.schema_tool.get_tables()
        if not set(args).issubset(set(all_tables)):
            raise CommandError("Unrecognized tables: %s" %
                               list(set(args) - set(all_tables)))

        result = SchemaDump()
        for table_name in args:
            app_label = self.schema_tool.get_app_by_table(table_name)
            if not result.app_exists(app_label):
                app_result = SchemaAppDump(app_label)
                result.add_app(app_result)
            else:
                app_result = result.get_app(app_label)
            app_result.add_table(
                self.handle_table(table_name, **options))

        self.stdout.write(str(result))
Exemple #2
0
class SchemaTableCommand(SchemaCommand):
    def add_arguments(self, parser):
        parser.add_argument('args',
                            metavar='table_name',
                            nargs='+',
                            help='Table names.')
        super(SchemaTableCommand, self).add_arguments(parser)

    def handle(self, *args, **options):
        try:
            self.schema_tool = SchemaTool()
        except UnsupportedDBError as e:
            raise CommandError(e)

        all_tables = self.schema_tool.get_tables()
        if not set(args).issubset(set(all_tables)):
            raise CommandError("Unrecognized tables: %s" %
                               list(set(args) - set(all_tables)))

        result = SchemaDump()
        for table_name in args:
            app_label = self.schema_tool.get_app_by_table(table_name)
            if not result.app_exists(app_label):
                app_result = SchemaAppDump(app_label)
                result.add_app(app_result)
            else:
                app_result = result.get_app(app_label)
            app_result.add_table(self.handle_table(table_name, **options))

        self.stdout.write(str(result))
Exemple #3
0
def test_schema_table(capfd):
    if get_current_db_type() != 'mysql':
        pytest.skip("unsupported database")

    call_command('schema', 'table', 'pootle_store_store')
    out, err = capfd.readouterr()
    schema_tool = SchemaTool()
    result = SchemaDump()
    result.load(json.loads(out))
    app_label = schema_tool.get_app_by_table('pootle_store_store')
    table_result = result.apps[app_label].tables['pootle_store_store']
    _test_table_result(schema_tool, table_result, 'pootle_store_store')