Exemplo n.º 1
0
 def modify_column(self, model: "Type[Model]", field_object: Field):
     db_table = model._meta.db_table
     return self._MODIFY_COLUMN_TEMPLATE.format(
         table_name=db_table,
         column=field_object.model_field_name,
         datatype=field_object.get_for_dialect(self.DIALECT, "SQL_TYPE"),
     )
Exemplo n.º 2
0
 def _change_field(cls, model: Type[Model], old_field: Field,
                   new_field: Field):
     return cls.ddl.change_column(
         model,
         old_field.model_field_name,
         new_field.model_field_name,
         new_field.get_for_dialect(cls.dialect, "SQL_TYPE"),
     )
Exemplo n.º 3
0
 def modify_column(self, model: "Type[Model]", field_object: Field):
     db_table = model._meta.db_table
     return self._MODIFY_COLUMN_TEMPLATE.format(
         table_name=db_table,
         column=self.schema_generator._create_string(
             db_column=field_object.model_field_name,
             field_type=field_object.get_for_dialect(
                 self.DIALECT, "SQL_TYPE"),
             nullable="NOT NULL" if not field_object.null else "",
             unique="",
             comment=self.schema_generator._column_comment_generator(
                 table=db_table,
                 column=field_object.model_field_name,
                 comment=field_object.description,
             ) if field_object.description else "",
             is_primary_key=field_object.pk,
             default=self._get_default(model, field_object),
         ),
     )
Exemplo n.º 4
0
 def add_column(self, model: "Type[Model]", field_object: Field):
     db_table = model._meta.db_table
     default = field_object.default
     db_column = field_object.model_field_name
     auto_now_add = getattr(field_object, "auto_now_add", False)
     auto_now = getattr(field_object, "auto_now", False)
     if default is not None or auto_now_add:
         if callable(default) or isinstance(
                 field_object, (UUIDField, TextField, JSONField)):
             default = ""
         else:
             default = field_object.to_db_value(default, model)
             try:
                 default = self.schema_generator._column_default_generator(
                     db_table,
                     db_column,
                     self.schema_generator._escape_default_value(default),
                     auto_now_add,
                     auto_now,
                 )
             except NotImplementedError:
                 default = ""
     else:
         default = ""
     return self._ADD_COLUMN_TEMPLATE.format(
         table_name=db_table,
         column=self.schema_generator._create_string(
             db_column=field_object.model_field_name,
             field_type=field_object.get_for_dialect(
                 self.DIALECT, "SQL_TYPE"),
             nullable="NOT NULL" if not field_object.null else "",
             unique="UNIQUE" if field_object.unique else "",
             comment=self.schema_generator._column_comment_generator(
                 table=db_table,
                 column=field_object.model_field_name,
                 comment=field_object.description,
             ) if field_object.description else "",
             is_primary_key=field_object.pk,
             default=default,
         ),
     )