piccolo 1.27.0__py3-none-any.whl → 1.28.0__py3-none-any.whl

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.
Files changed (122) hide show
  1. piccolo/__init__.py +1 -1
  2. piccolo/apps/app/commands/new.py +3 -3
  3. piccolo/apps/asgi/commands/new.py +1 -2
  4. piccolo/apps/fixtures/commands/dump.py +8 -8
  5. piccolo/apps/fixtures/commands/load.py +5 -5
  6. piccolo/apps/fixtures/commands/shared.py +9 -9
  7. piccolo/apps/migrations/auto/diffable_table.py +12 -12
  8. piccolo/apps/migrations/auto/migration_manager.py +59 -66
  9. piccolo/apps/migrations/auto/operations.py +14 -14
  10. piccolo/apps/migrations/auto/schema_differ.py +35 -34
  11. piccolo/apps/migrations/auto/schema_snapshot.py +3 -4
  12. piccolo/apps/migrations/auto/serialisation.py +27 -24
  13. piccolo/apps/migrations/auto/serialisation_legacy.py +2 -2
  14. piccolo/apps/migrations/commands/backwards.py +1 -2
  15. piccolo/apps/migrations/commands/base.py +12 -12
  16. piccolo/apps/migrations/commands/check.py +2 -3
  17. piccolo/apps/migrations/commands/clean.py +3 -3
  18. piccolo/apps/migrations/commands/forwards.py +1 -2
  19. piccolo/apps/migrations/commands/new.py +6 -6
  20. piccolo/apps/migrations/tables.py +3 -3
  21. piccolo/apps/playground/commands/run.py +29 -13
  22. piccolo/apps/schema/commands/generate.py +49 -49
  23. piccolo/apps/schema/commands/graph.py +5 -5
  24. piccolo/apps/shell/commands/run.py +1 -2
  25. piccolo/apps/sql_shell/commands/run.py +4 -4
  26. piccolo/apps/tester/commands/run.py +3 -3
  27. piccolo/apps/user/commands/change_permissions.py +6 -6
  28. piccolo/apps/user/commands/create.py +7 -7
  29. piccolo/apps/user/commands/list.py +2 -2
  30. piccolo/apps/user/tables.py +8 -8
  31. piccolo/columns/base.py +84 -52
  32. piccolo/columns/choices.py +2 -2
  33. piccolo/columns/column_types.py +297 -175
  34. piccolo/columns/combination.py +15 -12
  35. piccolo/columns/defaults/base.py +4 -4
  36. piccolo/columns/defaults/date.py +4 -3
  37. piccolo/columns/defaults/interval.py +4 -3
  38. piccolo/columns/defaults/time.py +4 -3
  39. piccolo/columns/defaults/timestamp.py +4 -3
  40. piccolo/columns/defaults/timestamptz.py +4 -3
  41. piccolo/columns/defaults/uuid.py +3 -2
  42. piccolo/columns/m2m.py +28 -35
  43. piccolo/columns/readable.py +4 -3
  44. piccolo/columns/reference.py +9 -9
  45. piccolo/conf/apps.py +53 -54
  46. piccolo/custom_types.py +28 -6
  47. piccolo/engine/base.py +14 -14
  48. piccolo/engine/cockroach.py +5 -4
  49. piccolo/engine/finder.py +2 -2
  50. piccolo/engine/postgres.py +20 -19
  51. piccolo/engine/sqlite.py +23 -22
  52. piccolo/query/base.py +30 -29
  53. piccolo/query/functions/__init__.py +12 -0
  54. piccolo/query/functions/aggregate.py +4 -3
  55. piccolo/query/functions/array.py +151 -0
  56. piccolo/query/functions/base.py +3 -3
  57. piccolo/query/functions/datetime.py +22 -22
  58. piccolo/query/functions/string.py +4 -4
  59. piccolo/query/functions/type_conversion.py +30 -15
  60. piccolo/query/methods/alter.py +47 -46
  61. piccolo/query/methods/count.py +11 -10
  62. piccolo/query/methods/create.py +6 -5
  63. piccolo/query/methods/create_index.py +9 -8
  64. piccolo/query/methods/delete.py +7 -6
  65. piccolo/query/methods/drop_index.py +7 -6
  66. piccolo/query/methods/exists.py +6 -5
  67. piccolo/query/methods/indexes.py +4 -4
  68. piccolo/query/methods/insert.py +21 -14
  69. piccolo/query/methods/objects.py +60 -50
  70. piccolo/query/methods/raw.py +7 -6
  71. piccolo/query/methods/refresh.py +8 -7
  72. piccolo/query/methods/select.py +56 -49
  73. piccolo/query/methods/table_exists.py +5 -5
  74. piccolo/query/methods/update.py +8 -7
  75. piccolo/query/mixins.py +56 -61
  76. piccolo/query/operators/json.py +11 -11
  77. piccolo/query/proxy.py +8 -9
  78. piccolo/querystring.py +14 -15
  79. piccolo/schema.py +10 -10
  80. piccolo/table.py +93 -94
  81. piccolo/table_reflection.py +9 -9
  82. piccolo/testing/model_builder.py +12 -11
  83. piccolo/testing/random_builder.py +2 -2
  84. piccolo/testing/test_case.py +4 -4
  85. piccolo/utils/dictionary.py +3 -3
  86. piccolo/utils/encoding.py +5 -5
  87. piccolo/utils/lazy_loader.py +3 -3
  88. piccolo/utils/list.py +7 -8
  89. piccolo/utils/objects.py +4 -6
  90. piccolo/utils/pydantic.py +21 -24
  91. piccolo/utils/sql_values.py +3 -3
  92. piccolo/utils/sync.py +4 -3
  93. piccolo/utils/warnings.py +1 -2
  94. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/METADATA +1 -1
  95. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/RECORD +122 -121
  96. tests/apps/fixtures/commands/test_dump_load.py +1 -2
  97. tests/apps/migrations/auto/integration/test_migrations.py +32 -7
  98. tests/apps/migrations/auto/test_migration_manager.py +2 -2
  99. tests/apps/migrations/auto/test_schema_differ.py +22 -23
  100. tests/apps/migrations/commands/test_forwards_backwards.py +3 -3
  101. tests/columns/m2m/base.py +2 -2
  102. tests/columns/test_array.py +176 -10
  103. tests/columns/test_boolean.py +2 -4
  104. tests/columns/test_combination.py +29 -1
  105. tests/columns/test_db_column_name.py +2 -2
  106. tests/engine/test_extra_nodes.py +2 -2
  107. tests/engine/test_pool.py +3 -3
  108. tests/engine/test_transaction.py +4 -4
  109. tests/query/test_freeze.py +4 -4
  110. tests/table/instance/test_get_related.py +2 -2
  111. tests/table/test_alter.py +4 -4
  112. tests/table/test_indexes.py +1 -2
  113. tests/table/test_refresh.py +2 -2
  114. tests/table/test_select.py +58 -0
  115. tests/table/test_update.py +3 -3
  116. tests/testing/test_model_builder.py +1 -2
  117. tests/utils/test_pydantic.py +36 -36
  118. tests/utils/test_table_reflection.py +1 -2
  119. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/WHEEL +0 -0
  120. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/entry_points.txt +0 -0
  121. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/licenses/LICENSE +0 -0
  122. {piccolo-1.27.0.dist-info → piccolo-1.28.0.dist-info}/top_level.txt +0 -0
piccolo/__init__.py CHANGED
@@ -1 +1 @@
1
- __VERSION__ = "1.27.0"
1
+ __VERSION__ = "1.28.0"
@@ -5,7 +5,7 @@ import os
5
5
  import pathlib
6
6
  import string
7
7
  import sys
8
- import typing as t
8
+ from typing import Any
9
9
 
10
10
  import black
11
11
  import jinja2
@@ -46,7 +46,7 @@ def validate_app_name(app_name: str):
46
46
 
47
47
  """
48
48
  for char in app_name:
49
- if not char.lower() in APP_NAME_ALLOWED_CHARACTERS:
49
+ if char.lower() not in APP_NAME_ALLOWED_CHARACTERS:
50
50
  raise ValueError(
51
51
  f"The app name contains a disallowed character: `{char}`. "
52
52
  "It must only include a-z, 0-9, and _ characters."
@@ -81,7 +81,7 @@ def new_app(app_name: str, root: str = ".", register: bool = False):
81
81
  with open(os.path.join(app_root, "__init__.py"), "w"):
82
82
  pass
83
83
 
84
- templates: t.Dict[str, t.Any] = {
84
+ templates: dict[str, Any] = {
85
85
  "piccolo_app.py": {"app_name": app_name},
86
86
  "tables.py": {},
87
87
  }
@@ -2,7 +2,6 @@ from __future__ import annotations
2
2
 
3
3
  import os
4
4
  import shutil
5
- import typing as t
6
5
 
7
6
  import black
8
7
  import colorama
@@ -28,7 +27,7 @@ def print_instruction(message: str):
28
27
  print(f"{colorama.Fore.CYAN}{message}{colorama.Fore.RESET}")
29
28
 
30
29
 
31
- def get_options_string(options: t.List[str]):
30
+ def get_options_string(options: list[str]):
32
31
  return ", ".join(f"{name} [{index}]" for index, name in enumerate(options))
33
32
 
34
33
 
@@ -1,6 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing as t
3
+ from typing import Any, Optional
4
4
 
5
5
  from piccolo.apps.fixtures.commands.shared import (
6
6
  FixtureConfig,
@@ -11,8 +11,8 @@ from piccolo.table import sort_table_classes
11
11
 
12
12
 
13
13
  async def get_dump(
14
- fixture_configs: t.List[FixtureConfig],
15
- ) -> t.Dict[str, t.Any]:
14
+ fixture_configs: list[FixtureConfig],
15
+ ) -> dict[str, Any]:
16
16
  """
17
17
  Gets the data for each table specified and returns a data structure like:
18
18
 
@@ -32,7 +32,7 @@ async def get_dump(
32
32
  """
33
33
  finder = Finder()
34
34
 
35
- output: t.Dict[str, t.Any] = {}
35
+ output: dict[str, Any] = {}
36
36
 
37
37
  for fixture_config in fixture_configs:
38
38
  app_config = finder.get_app_config(app_name=fixture_config.app_name)
@@ -53,7 +53,7 @@ async def get_dump(
53
53
 
54
54
 
55
55
  async def dump_to_json_string(
56
- fixture_configs: t.List[FixtureConfig],
56
+ fixture_configs: list[FixtureConfig],
57
57
  ) -> str:
58
58
  """
59
59
  Dumps all of the data for the given tables into a JSON string.
@@ -65,7 +65,7 @@ async def dump_to_json_string(
65
65
  return pydantic_model(**dump).model_dump_json(indent=4)
66
66
 
67
67
 
68
- def parse_args(apps: str, tables: str) -> t.List[FixtureConfig]:
68
+ def parse_args(apps: str, tables: str) -> list[FixtureConfig]:
69
69
  """
70
70
  Works out which apps and tables the user is referring to.
71
71
  """
@@ -80,11 +80,11 @@ def parse_args(apps: str, tables: str) -> t.List[FixtureConfig]:
80
80
  # Must be a single app name
81
81
  app_names.append(apps)
82
82
 
83
- table_class_names: t.Optional[t.List[str]] = None
83
+ table_class_names: Optional[list[str]] = None
84
84
 
85
85
  if tables != "all":
86
86
  table_class_names = tables.split(",") if "," in tables else [tables]
87
- output: t.List[FixtureConfig] = []
87
+ output: list[FixtureConfig] = []
88
88
 
89
89
  for app_name in app_names:
90
90
  app_config = finder.get_app_config(app_name=app_name)
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import sys
4
- import typing as t
4
+ from typing import Optional
5
5
 
6
6
  import typing_extensions
7
7
 
@@ -20,7 +20,7 @@ from piccolo.utils.list import batch
20
20
  async def load_json_string(
21
21
  json_string: str,
22
22
  chunk_size: int = 1000,
23
- on_conflict_action: t.Optional[OnConflictAction] = None,
23
+ on_conflict_action: Optional[OnConflictAction] = None,
24
24
  ):
25
25
  """
26
26
  Parses the JSON string, and inserts the parsed data into the database.
@@ -55,7 +55,7 @@ async def load_json_string(
55
55
  raise Exception("Unable to find the engine.")
56
56
 
57
57
  # This is what we want to the insert into the database:
58
- data: t.Dict[t.Type[Table], t.List[Table]] = {}
58
+ data: dict[type[Table], list[Table]] = {}
59
59
 
60
60
  for app_name in app_names:
61
61
  app_model = getattr(fixture_pydantic_model, app_name)
@@ -94,7 +94,7 @@ async def load_json_string(
94
94
  async def load(
95
95
  path: str = "fixture.json",
96
96
  chunk_size: int = 1000,
97
- on_conflict: t.Optional[
97
+ on_conflict: Optional[
98
98
  typing_extensions.Literal["DO NOTHING", "DO UPDATE"]
99
99
  ] = None,
100
100
  ):
@@ -118,7 +118,7 @@ async def load(
118
118
  with open(path, "r") as f:
119
119
  contents = f.read()
120
120
 
121
- on_conflict_action: t.Optional[OnConflictAction] = None
121
+ on_conflict_action: Optional[OnConflictAction] = None
122
122
 
123
123
  if on_conflict:
124
124
  try:
@@ -1,42 +1,42 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing as t
4
3
  from dataclasses import dataclass
4
+ from typing import TYPE_CHECKING, Any
5
5
 
6
6
  import pydantic
7
7
 
8
8
  from piccolo.conf.apps import Finder
9
9
  from piccolo.utils.pydantic import create_pydantic_model
10
10
 
11
- if t.TYPE_CHECKING: # pragma: no cover
11
+ if TYPE_CHECKING: # pragma: no cover
12
12
  from piccolo.table import Table
13
13
 
14
14
 
15
15
  @dataclass
16
16
  class FixtureConfig:
17
17
  app_name: str
18
- table_class_names: t.List[str]
18
+ table_class_names: list[str]
19
19
 
20
20
 
21
- def create_pydantic_fixture_model(fixture_configs: t.List[FixtureConfig]):
21
+ def create_pydantic_fixture_model(fixture_configs: list[FixtureConfig]):
22
22
  """
23
23
  Returns a nested Pydantic model for serialising and deserialising fixtures.
24
24
  """
25
- columns: t.Dict[str, t.Any] = {}
25
+ columns: dict[str, Any] = {}
26
26
 
27
27
  finder = Finder()
28
28
 
29
29
  for fixture_config in fixture_configs:
30
30
 
31
- app_columns: t.Dict[str, t.Any] = {}
31
+ app_columns: dict[str, Any] = {}
32
32
 
33
33
  for table_class_name in fixture_config.table_class_names:
34
- table_class: t.Type[Table] = finder.get_table_with_name(
34
+ table_class: type[Table] = finder.get_table_with_name(
35
35
  app_name=fixture_config.app_name,
36
36
  table_class_name=table_class_name,
37
37
  )
38
38
  app_columns[table_class_name] = (
39
- t.List[ # type: ignore
39
+ list[ # type: ignore
40
40
  create_pydantic_model(
41
41
  table_class, include_default_columns=True
42
42
  )
@@ -44,7 +44,7 @@ def create_pydantic_fixture_model(fixture_configs: t.List[FixtureConfig]):
44
44
  ...,
45
45
  )
46
46
 
47
- app_model: t.Any = pydantic.create_model(
47
+ app_model: Any = pydantic.create_model(
48
48
  f"{fixture_config.app_name.title()}Model", **app_columns
49
49
  )
50
50
 
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing as t
4
3
  from dataclasses import dataclass, field
4
+ from typing import Any, Optional
5
5
 
6
6
  from piccolo.apps.migrations.auto.operations import (
7
7
  AddColumn,
@@ -17,8 +17,8 @@ from piccolo.table import Table, create_table_class
17
17
 
18
18
 
19
19
  def compare_dicts(
20
- dict_1: t.Dict[str, t.Any], dict_2: t.Dict[str, t.Any]
21
- ) -> t.Dict[str, t.Any]:
20
+ dict_1: dict[str, Any], dict_2: dict[str, Any]
21
+ ) -> dict[str, Any]:
22
22
  """
23
23
  Returns a new dictionary which only contains key, value pairs which are in
24
24
  the first dictionary and not the second.
@@ -59,9 +59,9 @@ def compare_dicts(
59
59
 
60
60
  @dataclass
61
61
  class TableDelta:
62
- add_columns: t.List[AddColumn] = field(default_factory=list)
63
- drop_columns: t.List[DropColumn] = field(default_factory=list)
64
- alter_columns: t.List[AlterColumn] = field(default_factory=list)
62
+ add_columns: list[AddColumn] = field(default_factory=list)
63
+ drop_columns: list[DropColumn] = field(default_factory=list)
64
+ alter_columns: list[AlterColumn] = field(default_factory=list)
65
65
 
66
66
  def __eq__(self, value: TableDelta) -> bool: # type: ignore
67
67
  """
@@ -101,12 +101,12 @@ class DiffableTable:
101
101
 
102
102
  class_name: str
103
103
  tablename: str
104
- schema: t.Optional[str] = None
105
- columns: t.List[Column] = field(default_factory=list)
106
- previous_class_name: t.Optional[str] = None
104
+ schema: Optional[str] = None
105
+ columns: list[Column] = field(default_factory=list)
106
+ previous_class_name: Optional[str] = None
107
107
 
108
108
  def __post_init__(self) -> None:
109
- self.columns_map: t.Dict[str, Column] = {
109
+ self.columns_map: dict[str, Column] = {
110
110
  i._meta.name: i for i in self.columns
111
111
  }
112
112
 
@@ -163,7 +163,7 @@ class DiffableTable:
163
163
 
164
164
  #######################################################################
165
165
 
166
- alter_columns: t.List[AlterColumn] = []
166
+ alter_columns: list[AlterColumn] = []
167
167
 
168
168
  for existing_column in value.columns:
169
169
  column = self.columns_map.get(existing_column._meta.name)
@@ -221,7 +221,7 @@ class DiffableTable:
221
221
  def __str__(self):
222
222
  return f"{self.class_name} - {self.tablename}"
223
223
 
224
- def to_table_class(self) -> t.Type[Table]:
224
+ def to_table_class(self) -> type[Table]:
225
225
  """
226
226
  Converts the DiffableTable into a Table subclass.
227
227
  """
@@ -2,8 +2,9 @@ from __future__ import annotations
2
2
 
3
3
  import inspect
4
4
  import logging
5
- import typing as t
5
+ from collections.abc import Callable, Coroutine
6
6
  from dataclasses import dataclass, field
7
+ from typing import Any, Optional, Union
7
8
 
8
9
  from piccolo.apps.migrations.auto.diffable_table import DiffableTable
9
10
  from piccolo.apps.migrations.auto.operations import (
@@ -32,19 +33,19 @@ class AddColumnClass:
32
33
  column: Column
33
34
  table_class_name: str
34
35
  tablename: str
35
- schema: t.Optional[str]
36
+ schema: Optional[str]
36
37
 
37
38
 
38
39
  @dataclass
39
40
  class AddColumnCollection:
40
- add_columns: t.List[AddColumnClass] = field(default_factory=list)
41
+ add_columns: list[AddColumnClass] = field(default_factory=list)
41
42
 
42
43
  def append(self, add_column: AddColumnClass):
43
44
  self.add_columns.append(add_column)
44
45
 
45
46
  def for_table_class_name(
46
47
  self, table_class_name: str
47
- ) -> t.List[AddColumnClass]:
48
+ ) -> list[AddColumnClass]:
48
49
  return [
49
50
  i
50
51
  for i in self.add_columns
@@ -53,7 +54,7 @@ class AddColumnCollection:
53
54
 
54
55
  def columns_for_table_class_name(
55
56
  self, table_class_name: str
56
- ) -> t.List[Column]:
57
+ ) -> list[Column]:
57
58
  return [
58
59
  i.column
59
60
  for i in self.add_columns
@@ -61,20 +62,18 @@ class AddColumnCollection:
61
62
  ]
62
63
 
63
64
  @property
64
- def table_class_names(self) -> t.List[str]:
65
+ def table_class_names(self) -> list[str]:
65
66
  return list({i.table_class_name for i in self.add_columns})
66
67
 
67
68
 
68
69
  @dataclass
69
70
  class DropColumnCollection:
70
- drop_columns: t.List[DropColumn] = field(default_factory=list)
71
+ drop_columns: list[DropColumn] = field(default_factory=list)
71
72
 
72
73
  def append(self, drop_column: DropColumn):
73
74
  self.drop_columns.append(drop_column)
74
75
 
75
- def for_table_class_name(
76
- self, table_class_name: str
77
- ) -> t.List[DropColumn]:
76
+ def for_table_class_name(self, table_class_name: str) -> list[DropColumn]:
78
77
  return [
79
78
  i
80
79
  for i in self.drop_columns
@@ -82,20 +81,20 @@ class DropColumnCollection:
82
81
  ]
83
82
 
84
83
  @property
85
- def table_class_names(self) -> t.List[str]:
84
+ def table_class_names(self) -> list[str]:
86
85
  return list({i.table_class_name for i in self.drop_columns})
87
86
 
88
87
 
89
88
  @dataclass
90
89
  class RenameColumnCollection:
91
- rename_columns: t.List[RenameColumn] = field(default_factory=list)
90
+ rename_columns: list[RenameColumn] = field(default_factory=list)
92
91
 
93
92
  def append(self, rename_column: RenameColumn):
94
93
  self.rename_columns.append(rename_column)
95
94
 
96
95
  def for_table_class_name(
97
96
  self, table_class_name: str
98
- ) -> t.List[RenameColumn]:
97
+ ) -> list[RenameColumn]:
99
98
  return [
100
99
  i
101
100
  for i in self.rename_columns
@@ -103,20 +102,18 @@ class RenameColumnCollection:
103
102
  ]
104
103
 
105
104
  @property
106
- def table_class_names(self) -> t.List[str]:
105
+ def table_class_names(self) -> list[str]:
107
106
  return list({i.table_class_name for i in self.rename_columns})
108
107
 
109
108
 
110
109
  @dataclass
111
110
  class AlterColumnCollection:
112
- alter_columns: t.List[AlterColumn] = field(default_factory=list)
111
+ alter_columns: list[AlterColumn] = field(default_factory=list)
113
112
 
114
113
  def append(self, alter_column: AlterColumn):
115
114
  self.alter_columns.append(alter_column)
116
115
 
117
- def for_table_class_name(
118
- self, table_class_name: str
119
- ) -> t.List[AlterColumn]:
116
+ def for_table_class_name(self, table_class_name: str) -> list[AlterColumn]:
120
117
  return [
121
118
  i
122
119
  for i in self.alter_columns
@@ -124,11 +121,11 @@ class AlterColumnCollection:
124
121
  ]
125
122
 
126
123
  @property
127
- def table_class_names(self) -> t.List[str]:
124
+ def table_class_names(self) -> list[str]:
128
125
  return list({i.table_class_name for i in self.alter_columns})
129
126
 
130
127
 
131
- AsyncFunction = t.Callable[[], t.Coroutine]
128
+ AsyncFunction = Callable[[], Coroutine]
132
129
 
133
130
 
134
131
  class SkippedTransaction:
@@ -158,12 +155,10 @@ class MigrationManager:
158
155
  app_name: str = ""
159
156
  description: str = ""
160
157
  preview: bool = False
161
- add_tables: t.List[DiffableTable] = field(default_factory=list)
162
- drop_tables: t.List[DiffableTable] = field(default_factory=list)
163
- rename_tables: t.List[RenameTable] = field(default_factory=list)
164
- change_table_schemas: t.List[ChangeTableSchema] = field(
165
- default_factory=list
166
- )
158
+ add_tables: list[DiffableTable] = field(default_factory=list)
159
+ drop_tables: list[DiffableTable] = field(default_factory=list)
160
+ rename_tables: list[RenameTable] = field(default_factory=list)
161
+ change_table_schemas: list[ChangeTableSchema] = field(default_factory=list)
167
162
  add_columns: AddColumnCollection = field(
168
163
  default_factory=AddColumnCollection
169
164
  )
@@ -176,10 +171,8 @@ class MigrationManager:
176
171
  alter_columns: AlterColumnCollection = field(
177
172
  default_factory=AlterColumnCollection
178
173
  )
179
- raw: t.List[t.Union[t.Callable, AsyncFunction]] = field(
180
- default_factory=list
181
- )
182
- raw_backwards: t.List[t.Union[t.Callable, AsyncFunction]] = field(
174
+ raw: list[Union[Callable, AsyncFunction]] = field(default_factory=list)
175
+ raw_backwards: list[Union[Callable, AsyncFunction]] = field(
183
176
  default_factory=list
184
177
  )
185
178
  fake: bool = False
@@ -189,8 +182,8 @@ class MigrationManager:
189
182
  self,
190
183
  class_name: str,
191
184
  tablename: str,
192
- schema: t.Optional[str] = None,
193
- columns: t.Optional[t.List[Column]] = None,
185
+ schema: Optional[str] = None,
186
+ columns: Optional[list[Column]] = None,
194
187
  ):
195
188
  if not columns:
196
189
  columns = []
@@ -205,7 +198,7 @@ class MigrationManager:
205
198
  )
206
199
 
207
200
  def drop_table(
208
- self, class_name: str, tablename: str, schema: t.Optional[str] = None
201
+ self, class_name: str, tablename: str, schema: Optional[str] = None
209
202
  ):
210
203
  self.drop_tables.append(
211
204
  DiffableTable(
@@ -217,8 +210,8 @@ class MigrationManager:
217
210
  self,
218
211
  class_name: str,
219
212
  tablename: str,
220
- new_schema: t.Optional[str] = None,
221
- old_schema: t.Optional[str] = None,
213
+ new_schema: Optional[str] = None,
214
+ old_schema: Optional[str] = None,
222
215
  ):
223
216
  self.change_table_schemas.append(
224
217
  ChangeTableSchema(
@@ -235,7 +228,7 @@ class MigrationManager:
235
228
  old_tablename: str,
236
229
  new_class_name: str,
237
230
  new_tablename: str,
238
- schema: t.Optional[str] = None,
231
+ schema: Optional[str] = None,
239
232
  ):
240
233
  self.rename_tables.append(
241
234
  RenameTable(
@@ -252,11 +245,11 @@ class MigrationManager:
252
245
  table_class_name: str,
253
246
  tablename: str,
254
247
  column_name: str,
255
- db_column_name: t.Optional[str] = None,
248
+ db_column_name: Optional[str] = None,
256
249
  column_class_name: str = "",
257
- column_class: t.Optional[t.Type[Column]] = None,
258
- params: t.Optional[t.Dict[str, t.Any]] = None,
259
- schema: t.Optional[str] = None,
250
+ column_class: Optional[type[Column]] = None,
251
+ params: Optional[dict[str, Any]] = None,
252
+ schema: Optional[str] = None,
260
253
  ):
261
254
  """
262
255
  Add a new column to the table.
@@ -297,8 +290,8 @@ class MigrationManager:
297
290
  table_class_name: str,
298
291
  tablename: str,
299
292
  column_name: str,
300
- db_column_name: t.Optional[str] = None,
301
- schema: t.Optional[str] = None,
293
+ db_column_name: Optional[str] = None,
294
+ schema: Optional[str] = None,
302
295
  ):
303
296
  self.drop_columns.append(
304
297
  DropColumn(
@@ -316,9 +309,9 @@ class MigrationManager:
316
309
  tablename: str,
317
310
  old_column_name: str,
318
311
  new_column_name: str,
319
- old_db_column_name: t.Optional[str] = None,
320
- new_db_column_name: t.Optional[str] = None,
321
- schema: t.Optional[str] = None,
312
+ old_db_column_name: Optional[str] = None,
313
+ new_db_column_name: Optional[str] = None,
314
+ schema: Optional[str] = None,
322
315
  ):
323
316
  self.rename_columns.append(
324
317
  RenameColumn(
@@ -337,12 +330,12 @@ class MigrationManager:
337
330
  table_class_name: str,
338
331
  tablename: str,
339
332
  column_name: str,
340
- db_column_name: t.Optional[str] = None,
341
- params: t.Optional[t.Dict[str, t.Any]] = None,
342
- old_params: t.Optional[t.Dict[str, t.Any]] = None,
343
- column_class: t.Optional[t.Type[Column]] = None,
344
- old_column_class: t.Optional[t.Type[Column]] = None,
345
- schema: t.Optional[str] = None,
333
+ db_column_name: Optional[str] = None,
334
+ params: Optional[dict[str, Any]] = None,
335
+ old_params: Optional[dict[str, Any]] = None,
336
+ column_class: Optional[type[Column]] = None,
337
+ old_column_class: Optional[type[Column]] = None,
338
+ schema: Optional[str] = None,
346
339
  ):
347
340
  """
348
341
  All possible alterations aren't currently supported.
@@ -365,14 +358,14 @@ class MigrationManager:
365
358
  )
366
359
  )
367
360
 
368
- def add_raw(self, raw: t.Union[t.Callable, AsyncFunction]):
361
+ def add_raw(self, raw: Union[Callable, AsyncFunction]):
369
362
  """
370
363
  A migration manager can execute arbitrary functions or coroutines when
371
364
  run. This is useful if you want to execute raw SQL.
372
365
  """
373
366
  self.raw.append(raw)
374
367
 
375
- def add_raw_backwards(self, raw: t.Union[t.Callable, AsyncFunction]):
368
+ def add_raw_backwards(self, raw: Union[Callable, AsyncFunction]):
376
369
  """
377
370
  When reversing a migration, you may want to run extra code to help
378
371
  clean up.
@@ -384,10 +377,10 @@ class MigrationManager:
384
377
  async def get_table_from_snapshot(
385
378
  self,
386
379
  table_class_name: str,
387
- app_name: t.Optional[str],
380
+ app_name: Optional[str],
388
381
  offset: int = 0,
389
- migration_id: t.Optional[str] = None,
390
- ) -> t.Type[Table]:
382
+ migration_id: Optional[str] = None,
383
+ ) -> type[Table]:
391
384
  """
392
385
  Returns a Table subclass which can be used for modifying data within
393
386
  a migration.
@@ -416,13 +409,13 @@ class MigrationManager:
416
409
  ###########################################################################
417
410
 
418
411
  @staticmethod
419
- async def _print_query(query: t.Union[DDL, Query, SchemaDDLBase]):
412
+ async def _print_query(query: Union[DDL, Query, SchemaDDLBase]):
420
413
  if isinstance(query, DDL):
421
414
  print("\n", ";".join(query.ddl) + ";")
422
415
  else:
423
416
  print(str(query))
424
417
 
425
- async def _run_query(self, query: t.Union[DDL, Query, SchemaDDLBase]):
418
+ async def _run_query(self, query: Union[DDL, Query, SchemaDDLBase]):
426
419
  """
427
420
  If MigrationManager is in preview mode then it just print the query
428
421
  instead of executing it.
@@ -441,7 +434,7 @@ class MigrationManager:
441
434
  if not alter_columns:
442
435
  continue
443
436
 
444
- _Table: t.Type[Table] = create_table_class(
437
+ _Table: type[Table] = create_table_class(
445
438
  class_name=table_class_name,
446
439
  class_kwargs={
447
440
  "tablename": alter_columns[0].tablename,
@@ -494,7 +487,7 @@ class MigrationManager:
494
487
  alter_column.db_column_name
495
488
  )
496
489
 
497
- using_expression: t.Optional[str] = None
490
+ using_expression: Optional[str] = None
498
491
 
499
492
  # Postgres won't automatically cast some types to
500
493
  # others. We may as well try, as it will definitely
@@ -739,7 +732,7 @@ class MigrationManager:
739
732
  else rename_table.new_tablename
740
733
  )
741
734
 
742
- _Table: t.Type[Table] = create_table_class(
735
+ _Table: type[Table] = create_table_class(
743
736
  class_name=class_name,
744
737
  class_kwargs={
745
738
  "tablename": tablename,
@@ -760,7 +753,7 @@ class MigrationManager:
760
753
  if not columns:
761
754
  continue
762
755
 
763
- _Table: t.Type[Table] = create_table_class(
756
+ _Table: type[Table] = create_table_class(
764
757
  class_name=table_class_name,
765
758
  class_kwargs={
766
759
  "tablename": columns[0].tablename,
@@ -788,12 +781,12 @@ class MigrationManager:
788
781
  )
789
782
 
790
783
  async def _run_add_tables(self, backwards: bool = False):
791
- table_classes: t.List[t.Type[Table]] = []
784
+ table_classes: list[type[Table]] = []
792
785
  for add_table in self.add_tables:
793
- add_columns: t.List[AddColumnClass] = (
786
+ add_columns: list[AddColumnClass] = (
794
787
  self.add_columns.for_table_class_name(add_table.class_name)
795
788
  )
796
- _Table: t.Type[Table] = create_table_class(
789
+ _Table: type[Table] = create_table_class(
797
790
  class_name=add_table.class_name,
798
791
  class_kwargs={
799
792
  "tablename": add_table.tablename,
@@ -845,7 +838,7 @@ class MigrationManager:
845
838
  if table_class_name in [i.class_name for i in self.add_tables]:
846
839
  continue # No need to add columns to new tables
847
840
 
848
- add_columns: t.List[AddColumnClass] = (
841
+ add_columns: list[AddColumnClass] = (
849
842
  self.add_columns.for_table_class_name(table_class_name)
850
843
  )
851
844