peewee-migrate 2.2.0__tar.gz → 2.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: peewee-migrate
3
- Version: 2.2.0
3
+ Version: 2.3.0
4
4
  Summary: Support for migrations in Peewee ORM
5
5
  Keywords: peewee,migrations,orm
6
6
  Author: Kirill Klenov
@@ -68,14 +68,15 @@ class Migrator:
68
68
 
69
69
  def __call__(self):
70
70
  """Run operations."""
71
- for op in self.__ops__:
72
- if isinstance(op, Operation):
73
- logger.info("%s %s", op.fn.__name__, op.args)
74
- op.run()
75
- else:
76
- logger.info("Run %s", op.__name__)
77
- op()
78
- self.__ops__ = []
71
+ with self.__migrator__.migration_context():
72
+ for op in self.__ops__:
73
+ if isinstance(op, Operation):
74
+ logger.info("%s %s", op.fn.__name__, op.args)
75
+ op.run()
76
+ else:
77
+ logger.info("Run %s", op.__name__)
78
+ op()
79
+ self.__ops__ = []
79
80
 
80
81
  def __iter__(self):
81
82
  """Iterate over models."""
@@ -146,10 +147,13 @@ class Migrator:
146
147
  self.__migrator__.drop_table(meta.table_name, cascade=cascade, schema=meta.schema)
147
148
  )
148
149
 
149
- def add_fields(self, model: str | TModelType, **fields: pw.Field) -> TModelType:
150
+ def add_fields(
151
+ self, model: str | TModelType, *, allow_not_null: bool = False, **fields: pw.Field
152
+ ) -> TModelType:
150
153
  """Change fields.
151
154
 
152
155
  :param model: Model class or table name
156
+ :param allow_not_null: Allow adding NOT NULL columns without a default.
153
157
 
154
158
  >> migrator.change_fields(Model, name=pw.CharField(null=True))
155
159
  """
@@ -160,7 +164,7 @@ class Migrator:
160
164
 
161
165
  self.__ops__.append(
162
166
  self.__migrator__.add_column( # type: ignore[]
163
- meta.table_name, field.column_name, field
167
+ meta.table_name, field.column_name, field, allow_not_null=allow_not_null
164
168
  )
165
169
  )
166
170
 
@@ -282,7 +282,7 @@ class Router(BaseRouter):
282
282
  name = "{:03}_".format(num + 1) + name
283
283
  filename = name + ".py"
284
284
  path = self.migrate_dir / filename
285
- with path.open("w") as f:
285
+ with path.open("w", encoding="utf-8") as f:
286
286
  f.write(TEMPLATE.format(migrate=migrate, rollback=rollback, name=filename))
287
287
 
288
288
  return name
@@ -14,7 +14,7 @@ Some examples (model - class or model name)::
14
14
  > migrator.run(func, *args, **kwargs) # Run python function with the given args
15
15
  > migrator.create_model(Model) # Create a model (could be used as decorator)
16
16
  > migrator.remove_model(model, cascade=True) # Remove a model
17
- > migrator.add_fields(model, **fields) # Add fields to a model
17
+ > migrator.add_fields(model, **fields) # Add fields (allow_not_null=True skips default)
18
18
  > migrator.change_fields(model, **fields) # Change fields
19
19
  > migrator.remove_fields(model, *field_names, cascade=True)
20
20
  > migrator.rename_field(model, old_field_name, new_field_name)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "peewee-migrate"
3
- version = "2.2.0"
3
+ version = "2.3.0"
4
4
  description = "Support for migrations in Peewee ORM"
5
5
  requires-python = ">=3.11,<4"
6
6
  readme = "README.rst"
@@ -97,7 +97,7 @@ project-excludes = [
97
97
  addopts = "-svx"
98
98
 
99
99
  [tool.bumpversion]
100
- current_version = "2.2.0"
100
+ current_version = "2.3.0"
101
101
  commit = false
102
102
  tag = false
103
103
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "peewee-migrate"
3
- version = "2.2.0"
3
+ version = "2.3.0"
4
4
  description = "Support for migrations in Peewee ORM"
5
5
  authors = [{ name = "Kirill Klenov", email = "horneds@gmail.com" }]
6
6
  requires-python = ">=3.11,<4"
@@ -61,7 +61,7 @@ project-excludes = ["tests", "pyproject.toml"]
61
61
  addopts = "-svx"
62
62
 
63
63
  [tool.bumpversion]
64
- current_version = "2.2.0"
64
+ current_version = "2.3.0"
65
65
  commit = false
66
66
  tag = false
67
67