Exemple #1
0
    def post(self, request, schema, table):
        """
        Changes properties of tables and table columns
        :param request:
        :param schema:
        :param table:
        :return:
        """
        if schema not in PLAYGROUNDS and schema not in UNVERSIONED_SCHEMAS:
            raise PermissionDenied
        if schema.startswith("_"):
            raise PermissionDenied
        json_data = request.data

        if "column" in json_data["type"]:

            column_definition = api.parser.parse_scolumnd_from_columnd(
                schema, table, json_data["name"], json_data
            )
            result = actions.queue_column_change(schema, table, column_definition)
            return ModHttpResponse(result)

        elif "constraint" in json_data["type"]:

            # Input has nothing to do with DDL from Postgres.
            # Input is completely different.
            # Using actions.parse_sconstd_from_constd is not applicable
            # dict.get() returns None, if key does not exist
            constraint_definition = {
                "action": json_data["action"],  # {ADD, DROP}
                "constraint_type": json_data.get(
                    "constraint_type"
                ),  # {FOREIGN KEY, PRIMARY KEY, UNIQUE, CHECK}
                "constraint_name": json_data.get(
                    "constraint_name"
                ),  # {myForeignKey, myUniqueConstraint}
                "constraint_parameter": json_data.get("constraint_parameter"),
                # Things in Brackets, e.g. name of column
                "reference_table": json_data.get("reference_table"),
                "reference_column": json_data.get("reference_column"),
            }

            result = actions.queue_constraint_change(
                schema, table, constraint_definition
            )
            return ModHttpResponse(result)
        else:
            return ModHttpResponse(
                actions.get_response_dict(False, 400, "type not recognised")
            )
Exemple #2
0
    def post(self, request, schema, table):
        """
        Changes properties of tables and table columns
        :param request:
        :param schema:
        :param table:
        :return:
        """
        if schema not in ['model_draft', 'sandbox', 'test']:
            raise PermissionDenied
        if schema.startswith('_'):
            raise PermissionDenied
        json_data = request.data

        if 'column' in json_data['type']:

            column_definition = api.parser.parse_scolumnd_from_columnd(
                schema, table, json_data['name'], json_data)
            result = actions.queue_column_change(schema, table,
                                                 column_definition)
            return ModHttpResponse(result)

        elif 'constraint' in json_data['type']:

            # Input has nothing to do with DDL from Postgres.
            # Input is completely different.
            # Using actions.parse_sconstd_from_constd is not applicable
            # dict.get() returns None, if key does not exist
            constraint_definition = {
                'action': json_data['action'],  # {ADD, DROP}
                'constraint_type':
                json_data.get('constraint_type'
                              ),  # {FOREIGN KEY, PRIMARY KEY, UNIQUE, CHECK}
                'constraint_name': json_data.get(
                    'constraint_name'),  # {myForeignKey, myUniqueConstraint}
                'constraint_parameter': json_data.get('constraint_parameter'),
                # Things in Brackets, e.g. name of column
                'reference_table': json_data.get('reference_table'),
                'reference_column': json_data.get('reference_column')
            }

            result = actions.queue_constraint_change(schema, table,
                                                     constraint_definition)
            return ModHttpResponse(result)
        else:
            return ModHttpResponse(
                actions.get_response_dict(False, 400, 'type not recognised'))