piccolo 1.27.1__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.
- piccolo/__init__.py +1 -1
- piccolo/apps/app/commands/new.py +3 -3
- piccolo/apps/asgi/commands/new.py +1 -2
- piccolo/apps/fixtures/commands/dump.py +8 -8
- piccolo/apps/fixtures/commands/load.py +5 -5
- piccolo/apps/fixtures/commands/shared.py +9 -9
- piccolo/apps/migrations/auto/diffable_table.py +12 -12
- piccolo/apps/migrations/auto/migration_manager.py +59 -66
- piccolo/apps/migrations/auto/operations.py +14 -14
- piccolo/apps/migrations/auto/schema_differ.py +35 -34
- piccolo/apps/migrations/auto/schema_snapshot.py +3 -4
- piccolo/apps/migrations/auto/serialisation.py +27 -24
- piccolo/apps/migrations/auto/serialisation_legacy.py +2 -2
- piccolo/apps/migrations/commands/backwards.py +1 -2
- piccolo/apps/migrations/commands/base.py +12 -12
- piccolo/apps/migrations/commands/check.py +2 -3
- piccolo/apps/migrations/commands/clean.py +3 -3
- piccolo/apps/migrations/commands/forwards.py +1 -2
- piccolo/apps/migrations/commands/new.py +6 -6
- piccolo/apps/migrations/tables.py +3 -3
- piccolo/apps/playground/commands/run.py +29 -13
- piccolo/apps/schema/commands/generate.py +49 -49
- piccolo/apps/schema/commands/graph.py +5 -5
- piccolo/apps/shell/commands/run.py +1 -2
- piccolo/apps/sql_shell/commands/run.py +4 -4
- piccolo/apps/tester/commands/run.py +3 -3
- piccolo/apps/user/commands/change_permissions.py +6 -6
- piccolo/apps/user/commands/create.py +7 -7
- piccolo/apps/user/commands/list.py +2 -2
- piccolo/apps/user/tables.py +8 -8
- piccolo/columns/base.py +84 -52
- piccolo/columns/choices.py +2 -2
- piccolo/columns/column_types.py +297 -175
- piccolo/columns/combination.py +15 -12
- piccolo/columns/defaults/base.py +4 -4
- piccolo/columns/defaults/date.py +4 -3
- piccolo/columns/defaults/interval.py +4 -3
- piccolo/columns/defaults/time.py +4 -3
- piccolo/columns/defaults/timestamp.py +4 -3
- piccolo/columns/defaults/timestamptz.py +4 -3
- piccolo/columns/defaults/uuid.py +3 -2
- piccolo/columns/m2m.py +28 -35
- piccolo/columns/readable.py +4 -3
- piccolo/columns/reference.py +9 -9
- piccolo/conf/apps.py +53 -54
- piccolo/custom_types.py +28 -6
- piccolo/engine/base.py +14 -14
- piccolo/engine/cockroach.py +5 -4
- piccolo/engine/finder.py +2 -2
- piccolo/engine/postgres.py +20 -19
- piccolo/engine/sqlite.py +23 -22
- piccolo/query/base.py +30 -29
- piccolo/query/functions/__init__.py +12 -0
- piccolo/query/functions/aggregate.py +4 -3
- piccolo/query/functions/array.py +151 -0
- piccolo/query/functions/base.py +3 -3
- piccolo/query/functions/datetime.py +22 -22
- piccolo/query/functions/string.py +4 -4
- piccolo/query/functions/type_conversion.py +30 -15
- piccolo/query/methods/alter.py +47 -46
- piccolo/query/methods/count.py +11 -10
- piccolo/query/methods/create.py +6 -5
- piccolo/query/methods/create_index.py +9 -8
- piccolo/query/methods/delete.py +7 -6
- piccolo/query/methods/drop_index.py +7 -6
- piccolo/query/methods/exists.py +6 -5
- piccolo/query/methods/indexes.py +4 -4
- piccolo/query/methods/insert.py +21 -14
- piccolo/query/methods/objects.py +60 -50
- piccolo/query/methods/raw.py +7 -6
- piccolo/query/methods/refresh.py +8 -7
- piccolo/query/methods/select.py +56 -49
- piccolo/query/methods/table_exists.py +5 -5
- piccolo/query/methods/update.py +8 -7
- piccolo/query/mixins.py +56 -61
- piccolo/query/operators/json.py +11 -11
- piccolo/query/proxy.py +8 -9
- piccolo/querystring.py +14 -15
- piccolo/schema.py +10 -10
- piccolo/table.py +93 -94
- piccolo/table_reflection.py +9 -9
- piccolo/testing/model_builder.py +12 -11
- piccolo/testing/random_builder.py +2 -2
- piccolo/testing/test_case.py +4 -4
- piccolo/utils/dictionary.py +3 -3
- piccolo/utils/encoding.py +5 -5
- piccolo/utils/lazy_loader.py +3 -3
- piccolo/utils/list.py +7 -8
- piccolo/utils/objects.py +4 -6
- piccolo/utils/pydantic.py +21 -24
- piccolo/utils/sql_values.py +3 -3
- piccolo/utils/sync.py +4 -3
- piccolo/utils/warnings.py +1 -2
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/METADATA +1 -1
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/RECORD +122 -121
- tests/apps/fixtures/commands/test_dump_load.py +1 -2
- tests/apps/migrations/auto/integration/test_migrations.py +32 -7
- tests/apps/migrations/auto/test_migration_manager.py +2 -2
- tests/apps/migrations/auto/test_schema_differ.py +22 -23
- tests/apps/migrations/commands/test_forwards_backwards.py +3 -3
- tests/columns/m2m/base.py +2 -2
- tests/columns/test_array.py +176 -10
- tests/columns/test_boolean.py +2 -4
- tests/columns/test_combination.py +29 -1
- tests/columns/test_db_column_name.py +2 -2
- tests/engine/test_extra_nodes.py +2 -2
- tests/engine/test_pool.py +3 -3
- tests/engine/test_transaction.py +4 -4
- tests/query/test_freeze.py +4 -4
- tests/table/instance/test_get_related.py +2 -2
- tests/table/test_alter.py +4 -4
- tests/table/test_indexes.py +1 -2
- tests/table/test_refresh.py +2 -2
- tests/table/test_select.py +58 -0
- tests/table/test_update.py +3 -3
- tests/testing/test_model_builder.py +1 -2
- tests/utils/test_pydantic.py +36 -36
- tests/utils/test_table_reflection.py +1 -2
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/WHEEL +0 -0
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/entry_points.txt +0 -0
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/licenses/LICENSE +0 -0
- {piccolo-1.27.1.dist-info → piccolo-1.28.0.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,5 @@
|
|
1
|
-
import typing as t
|
2
1
|
from dataclasses import dataclass
|
2
|
+
from typing import Any, Optional
|
3
3
|
|
4
4
|
from piccolo.columns.base import Column
|
5
5
|
|
@@ -10,15 +10,15 @@ class RenameTable:
|
|
10
10
|
old_tablename: str
|
11
11
|
new_class_name: str
|
12
12
|
new_tablename: str
|
13
|
-
schema:
|
13
|
+
schema: Optional[str] = None
|
14
14
|
|
15
15
|
|
16
16
|
@dataclass
|
17
17
|
class ChangeTableSchema:
|
18
18
|
class_name: str
|
19
19
|
tablename: str
|
20
|
-
old_schema:
|
21
|
-
new_schema:
|
20
|
+
old_schema: Optional[str]
|
21
|
+
new_schema: Optional[str]
|
22
22
|
|
23
23
|
|
24
24
|
@dataclass
|
@@ -29,7 +29,7 @@ class RenameColumn:
|
|
29
29
|
new_column_name: str
|
30
30
|
old_db_column_name: str
|
31
31
|
new_db_column_name: str
|
32
|
-
schema:
|
32
|
+
schema: Optional[str] = None
|
33
33
|
|
34
34
|
|
35
35
|
@dataclass
|
@@ -38,11 +38,11 @@ class AlterColumn:
|
|
38
38
|
column_name: str
|
39
39
|
db_column_name: str
|
40
40
|
tablename: str
|
41
|
-
params:
|
42
|
-
old_params:
|
43
|
-
column_class:
|
44
|
-
old_column_class:
|
45
|
-
schema:
|
41
|
+
params: dict[str, Any]
|
42
|
+
old_params: dict[str, Any]
|
43
|
+
column_class: Optional[type[Column]] = None
|
44
|
+
old_column_class: Optional[type[Column]] = None
|
45
|
+
schema: Optional[str] = None
|
46
46
|
|
47
47
|
|
48
48
|
@dataclass
|
@@ -51,7 +51,7 @@ class DropColumn:
|
|
51
51
|
column_name: str
|
52
52
|
db_column_name: str
|
53
53
|
tablename: str
|
54
|
-
schema:
|
54
|
+
schema: Optional[str] = None
|
55
55
|
|
56
56
|
|
57
57
|
@dataclass
|
@@ -60,6 +60,6 @@ class AddColumn:
|
|
60
60
|
column_name: str
|
61
61
|
db_column_name: str
|
62
62
|
column_class_name: str
|
63
|
-
column_class:
|
64
|
-
params:
|
65
|
-
schema:
|
63
|
+
column_class: type[Column]
|
64
|
+
params: dict[str, Any]
|
65
|
+
schema: Optional[str] = None
|
@@ -1,9 +1,10 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import inspect
|
4
|
-
|
4
|
+
from collections.abc import Callable
|
5
5
|
from copy import deepcopy
|
6
6
|
from dataclasses import dataclass, field
|
7
|
+
from typing import Any, Optional
|
7
8
|
|
8
9
|
from piccolo.apps.migrations.auto.diffable_table import (
|
9
10
|
DiffableTable,
|
@@ -26,7 +27,7 @@ from piccolo.utils.printing import get_fixed_length_string
|
|
26
27
|
|
27
28
|
@dataclass
|
28
29
|
class RenameTableCollection:
|
29
|
-
rename_tables:
|
30
|
+
rename_tables: list[RenameTable] = field(default_factory=list)
|
30
31
|
|
31
32
|
def append(self, renamed_table: RenameTable):
|
32
33
|
self.rename_tables.append(renamed_table)
|
@@ -48,7 +49,7 @@ class RenameTableCollection:
|
|
48
49
|
return True
|
49
50
|
return False
|
50
51
|
|
51
|
-
def renamed_from(self, new_class_name: str) ->
|
52
|
+
def renamed_from(self, new_class_name: str) -> Optional[str]:
|
52
53
|
"""
|
53
54
|
Returns the old class name, if it exists.
|
54
55
|
"""
|
@@ -60,7 +61,7 @@ class RenameTableCollection:
|
|
60
61
|
|
61
62
|
@dataclass
|
62
63
|
class ChangeTableSchemaCollection:
|
63
|
-
collection:
|
64
|
+
collection: list[ChangeTableSchema] = field(default_factory=list)
|
64
65
|
|
65
66
|
def append(self, change_table_schema: ChangeTableSchema):
|
66
67
|
self.collection.append(change_table_schema)
|
@@ -68,14 +69,14 @@ class ChangeTableSchemaCollection:
|
|
68
69
|
|
69
70
|
@dataclass
|
70
71
|
class RenameColumnCollection:
|
71
|
-
rename_columns:
|
72
|
+
rename_columns: list[RenameColumn] = field(default_factory=list)
|
72
73
|
|
73
74
|
def append(self, rename_column: RenameColumn):
|
74
75
|
self.rename_columns.append(rename_column)
|
75
76
|
|
76
77
|
def for_table_class_name(
|
77
78
|
self, table_class_name: str
|
78
|
-
) ->
|
79
|
+
) -> list[RenameColumn]:
|
79
80
|
return [
|
80
81
|
i
|
81
82
|
for i in self.rename_columns
|
@@ -93,9 +94,9 @@ class RenameColumnCollection:
|
|
93
94
|
|
94
95
|
@dataclass
|
95
96
|
class AlterStatements:
|
96
|
-
statements:
|
97
|
-
extra_imports:
|
98
|
-
extra_definitions:
|
97
|
+
statements: list[str] = field(default_factory=list)
|
98
|
+
extra_imports: list[Import] = field(default_factory=list)
|
99
|
+
extra_definitions: list[Definition] = field(default_factory=list)
|
99
100
|
|
100
101
|
def extend(self, alter_statements: AlterStatements):
|
101
102
|
self.statements.extend(alter_statements.statements)
|
@@ -112,19 +113,19 @@ class SchemaDiffer:
|
|
112
113
|
sure - for example, whether a column was renamed.
|
113
114
|
"""
|
114
115
|
|
115
|
-
schema:
|
116
|
-
schema_snapshot:
|
116
|
+
schema: list[DiffableTable]
|
117
|
+
schema_snapshot: list[DiffableTable]
|
117
118
|
|
118
119
|
# Sometimes the SchemaDiffer requires input from a user - for example,
|
119
120
|
# asking if a table was renamed or not. When running in non-interactive
|
120
121
|
# mode (like in a unittest), we can set a default to be used instead, like
|
121
122
|
# 'y'.
|
122
|
-
auto_input:
|
123
|
+
auto_input: Optional[str] = None
|
123
124
|
|
124
125
|
###########################################################################
|
125
126
|
|
126
127
|
def __post_init__(self) -> None:
|
127
|
-
self.schema_snapshot_map:
|
128
|
+
self.schema_snapshot_map: dict[str, DiffableTable] = {
|
128
129
|
i.class_name: i for i in self.schema_snapshot
|
129
130
|
}
|
130
131
|
self.table_schema_changes_collection = (
|
@@ -137,11 +138,11 @@ class SchemaDiffer:
|
|
137
138
|
"""
|
138
139
|
Work out whether any of the tables were renamed.
|
139
140
|
"""
|
140
|
-
drop_tables:
|
141
|
+
drop_tables: list[DiffableTable] = list(
|
141
142
|
set(self.schema_snapshot) - set(self.schema)
|
142
143
|
)
|
143
144
|
|
144
|
-
new_tables:
|
145
|
+
new_tables: list[DiffableTable] = list(
|
145
146
|
set(self.schema) - set(self.schema_snapshot)
|
146
147
|
)
|
147
148
|
|
@@ -267,7 +268,7 @@ class SchemaDiffer:
|
|
267
268
|
# We track which dropped columns have already been identified by
|
268
269
|
# the user as renames, so we don't ask them if another column
|
269
270
|
# was also renamed from it.
|
270
|
-
used_drop_column_names:
|
271
|
+
used_drop_column_names: list[str] = []
|
271
272
|
|
272
273
|
for add_column in delta.add_columns:
|
273
274
|
for drop_column in delta.drop_columns:
|
@@ -300,9 +301,9 @@ class SchemaDiffer:
|
|
300
301
|
|
301
302
|
def _stringify_func(
|
302
303
|
self,
|
303
|
-
func:
|
304
|
-
params:
|
305
|
-
prefix:
|
304
|
+
func: Callable,
|
305
|
+
params: dict[str, Any],
|
306
|
+
prefix: Optional[str] = None,
|
306
307
|
) -> AlterStatements:
|
307
308
|
"""
|
308
309
|
Generates a string representing how to call the given function with the
|
@@ -348,7 +349,7 @@ class SchemaDiffer:
|
|
348
349
|
|
349
350
|
@property
|
350
351
|
def create_tables(self) -> AlterStatements:
|
351
|
-
new_tables:
|
352
|
+
new_tables: list[DiffableTable] = list(
|
352
353
|
set(self.schema) - set(self.schema_snapshot)
|
353
354
|
)
|
354
355
|
|
@@ -379,7 +380,7 @@ class SchemaDiffer:
|
|
379
380
|
|
380
381
|
@property
|
381
382
|
def drop_tables(self) -> AlterStatements:
|
382
|
-
drop_tables:
|
383
|
+
drop_tables: list[DiffableTable] = list(
|
383
384
|
set(self.schema_snapshot) - set(self.schema)
|
384
385
|
)
|
385
386
|
|
@@ -442,7 +443,7 @@ class SchemaDiffer:
|
|
442
443
|
|
443
444
|
def _get_snapshot_table(
|
444
445
|
self, table_class_name: str
|
445
|
-
) ->
|
446
|
+
) -> Optional[DiffableTable]:
|
446
447
|
snapshot_table = self.schema_snapshot_map.get(table_class_name, None)
|
447
448
|
if snapshot_table:
|
448
449
|
return snapshot_table
|
@@ -463,9 +464,9 @@ class SchemaDiffer:
|
|
463
464
|
|
464
465
|
@property
|
465
466
|
def alter_columns(self) -> AlterStatements:
|
466
|
-
response:
|
467
|
-
extra_imports:
|
468
|
-
extra_definitions:
|
467
|
+
response: list[str] = []
|
468
|
+
extra_imports: list[Import] = []
|
469
|
+
extra_definitions: list[Definition] = []
|
469
470
|
for table in self.schema:
|
470
471
|
snapshot_table = self._get_snapshot_table(table.class_name)
|
471
472
|
if snapshot_table:
|
@@ -563,9 +564,9 @@ class SchemaDiffer:
|
|
563
564
|
|
564
565
|
@property
|
565
566
|
def add_columns(self) -> AlterStatements:
|
566
|
-
response:
|
567
|
-
extra_imports:
|
568
|
-
extra_definitions:
|
567
|
+
response: list[str] = []
|
568
|
+
extra_imports: list[Import] = []
|
569
|
+
extra_definitions: list[Definition] = []
|
569
570
|
for table in self.schema:
|
570
571
|
snapshot_table = self._get_snapshot_table(table.class_name)
|
571
572
|
if snapshot_table:
|
@@ -632,13 +633,13 @@ class SchemaDiffer:
|
|
632
633
|
|
633
634
|
@property
|
634
635
|
def new_table_columns(self) -> AlterStatements:
|
635
|
-
new_tables:
|
636
|
+
new_tables: list[DiffableTable] = list(
|
636
637
|
set(self.schema) - set(self.schema_snapshot)
|
637
638
|
)
|
638
639
|
|
639
|
-
response:
|
640
|
-
extra_imports:
|
641
|
-
extra_definitions:
|
640
|
+
response: list[str] = []
|
641
|
+
extra_imports: list[Import] = []
|
642
|
+
extra_definitions: list[Definition] = []
|
642
643
|
for table in new_tables:
|
643
644
|
if (
|
644
645
|
table.class_name
|
@@ -681,11 +682,11 @@ class SchemaDiffer:
|
|
681
682
|
|
682
683
|
###########################################################################
|
683
684
|
|
684
|
-
def get_alter_statements(self) ->
|
685
|
+
def get_alter_statements(self) -> list[AlterStatements]:
|
685
686
|
"""
|
686
687
|
Call to execute the necessary alter commands on the database.
|
687
688
|
"""
|
688
|
-
alter_statements:
|
689
|
+
alter_statements: dict[str, AlterStatements] = {
|
689
690
|
"Created tables": self.create_tables,
|
690
691
|
"Dropped tables": self.drop_tables,
|
691
692
|
"Renamed tables": self.rename_tables,
|
@@ -1,6 +1,5 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
import typing as t
|
4
3
|
from dataclasses import dataclass, field
|
5
4
|
|
6
5
|
from piccolo.apps.migrations.auto.diffable_table import DiffableTable
|
@@ -15,7 +14,7 @@ class SchemaSnapshot:
|
|
15
14
|
"""
|
16
15
|
|
17
16
|
# In ascending order of date created.
|
18
|
-
managers:
|
17
|
+
managers: list[MigrationManager] = field(default_factory=list)
|
19
18
|
|
20
19
|
###########################################################################
|
21
20
|
|
@@ -28,8 +27,8 @@ class SchemaSnapshot:
|
|
28
27
|
|
29
28
|
###########################################################################
|
30
29
|
|
31
|
-
def get_snapshot(self) ->
|
32
|
-
tables:
|
30
|
+
def get_snapshot(self) -> list[DiffableTable]:
|
31
|
+
tables: list[DiffableTable] = []
|
33
32
|
|
34
33
|
# Make sure the managers are sorted correctly:
|
35
34
|
sorted_managers = sorted(self.managers, key=lambda x: x.migration_id)
|
@@ -5,12 +5,13 @@ import builtins
|
|
5
5
|
import datetime
|
6
6
|
import decimal
|
7
7
|
import inspect
|
8
|
-
import typing as t
|
9
8
|
import uuid
|
10
9
|
import warnings
|
10
|
+
from collections.abc import Callable, Iterable
|
11
11
|
from copy import deepcopy
|
12
12
|
from dataclasses import dataclass, field
|
13
13
|
from enum import Enum
|
14
|
+
from typing import Any, Optional
|
14
15
|
|
15
16
|
from piccolo.columns import Column
|
16
17
|
from piccolo.columns.defaults.base import Default
|
@@ -61,8 +62,8 @@ class UniqueGlobalNamesMeta(type):
|
|
61
62
|
|
62
63
|
@staticmethod
|
63
64
|
def get_unique_class_attribute_values(
|
64
|
-
class_attributes:
|
65
|
-
) ->
|
65
|
+
class_attributes: dict[str, Any],
|
66
|
+
) -> set[Any]:
|
66
67
|
"""
|
67
68
|
Return class attribute values.
|
68
69
|
|
@@ -87,9 +88,9 @@ class UniqueGlobalNamesMeta(type):
|
|
87
88
|
|
88
89
|
@staticmethod
|
89
90
|
def merge_class_attributes(
|
90
|
-
class_attributes1:
|
91
|
-
class_attributes2:
|
92
|
-
) ->
|
91
|
+
class_attributes1: dict[str, Any],
|
92
|
+
class_attributes2: dict[str, Any],
|
93
|
+
) -> dict[str, Any]:
|
93
94
|
"""
|
94
95
|
Merges two class attribute dictionaries.
|
95
96
|
|
@@ -104,12 +105,12 @@ class UniqueGlobalNamesMeta(type):
|
|
104
105
|
return dict(**class_attributes1, **class_attributes2)
|
105
106
|
|
106
107
|
@staticmethod
|
107
|
-
def get_column_class_attributes() ->
|
108
|
+
def get_column_class_attributes() -> dict[str, str]:
|
108
109
|
"""Automatically generates global names for each column type."""
|
109
110
|
|
110
111
|
import piccolo.columns.column_types
|
111
112
|
|
112
|
-
class_attributes:
|
113
|
+
class_attributes: dict[str, str] = {}
|
113
114
|
for module_global in piccolo.columns.column_types.__dict__.values():
|
114
115
|
try:
|
115
116
|
if module_global is not Column and issubclass(
|
@@ -150,7 +151,7 @@ class UniqueGlobalNames(metaclass=UniqueGlobalNamesMeta):
|
|
150
151
|
EXTERNAL_UUID = f"{EXTERNAL_MODULE_UUID}.{uuid.UUID.__name__}"
|
151
152
|
|
152
153
|
# This attribute is set in metaclass
|
153
|
-
unique_names:
|
154
|
+
unique_names: set[str]
|
154
155
|
|
155
156
|
@classmethod
|
156
157
|
def warn_if_is_conflicting_name(
|
@@ -172,7 +173,7 @@ class UniqueGlobalNames(metaclass=UniqueGlobalNamesMeta):
|
|
172
173
|
|
173
174
|
@staticmethod
|
174
175
|
def warn_if_are_conflicting_objects(
|
175
|
-
objects:
|
176
|
+
objects: Iterable[CanConflictWithGlobalNames],
|
176
177
|
) -> None:
|
177
178
|
"""
|
178
179
|
Call each object's ``raise_if_is_conflicting_with_global_name`` method.
|
@@ -192,8 +193,8 @@ class UniqueGlobalNameConflictWarning(UserWarning):
|
|
192
193
|
@dataclass
|
193
194
|
class Import(CanConflictWithGlobalNames):
|
194
195
|
module: str
|
195
|
-
target:
|
196
|
-
expect_conflict_with_global_name:
|
196
|
+
target: Optional[str] = None
|
197
|
+
expect_conflict_with_global_name: Optional[str] = None
|
197
198
|
|
198
199
|
def __post_init__(self) -> None:
|
199
200
|
if (
|
@@ -256,9 +257,9 @@ class Definition(CanConflictWithGlobalNames, abc.ABC):
|
|
256
257
|
|
257
258
|
@dataclass
|
258
259
|
class SerialisedParams:
|
259
|
-
params:
|
260
|
-
extra_imports:
|
261
|
-
extra_definitions:
|
260
|
+
params: dict[str, Any]
|
261
|
+
extra_imports: list[Import]
|
262
|
+
extra_definitions: list[Definition] = field(default_factory=list)
|
262
263
|
|
263
264
|
|
264
265
|
###############################################################################
|
@@ -273,7 +274,7 @@ def check_equality(self, other):
|
|
273
274
|
|
274
275
|
@dataclass
|
275
276
|
class SerialisedBuiltin:
|
276
|
-
builtin:
|
277
|
+
builtin: Any
|
277
278
|
|
278
279
|
def __hash__(self):
|
279
280
|
return hash(self.builtin.__name__)
|
@@ -335,7 +336,7 @@ class SerialisedEnumInstance:
|
|
335
336
|
|
336
337
|
@dataclass
|
337
338
|
class SerialisedTableType(Definition):
|
338
|
-
table_type:
|
339
|
+
table_type: type[Table]
|
339
340
|
|
340
341
|
def __hash__(self):
|
341
342
|
return hash(
|
@@ -361,7 +362,7 @@ class SerialisedTableType(Definition):
|
|
361
362
|
|
362
363
|
# When creating a ForeignKey, the user can specify a column other than
|
363
364
|
# the primary key to reference.
|
364
|
-
serialised_target_columns:
|
365
|
+
serialised_target_columns: set[SerialisedColumnInstance] = set()
|
365
366
|
|
366
367
|
for fk_column in self.table_type._meta._foreign_key_references:
|
367
368
|
target_column = fk_column._foreign_key_meta.target_column
|
@@ -426,7 +427,7 @@ class SerialisedTableType(Definition):
|
|
426
427
|
|
427
428
|
@dataclass
|
428
429
|
class SerialisedEnumType:
|
429
|
-
enum_type:
|
430
|
+
enum_type: type[Enum]
|
430
431
|
|
431
432
|
def __hash__(self):
|
432
433
|
return hash(self.__repr__())
|
@@ -442,7 +443,7 @@ class SerialisedEnumType:
|
|
442
443
|
|
443
444
|
@dataclass
|
444
445
|
class SerialisedCallable:
|
445
|
-
callable_:
|
446
|
+
callable_: Callable
|
446
447
|
|
447
448
|
def __hash__(self):
|
448
449
|
return hash(self.callable_.__name__)
|
@@ -487,14 +488,14 @@ class SerialisedDecimal:
|
|
487
488
|
###############################################################################
|
488
489
|
|
489
490
|
|
490
|
-
def serialise_params(params:
|
491
|
+
def serialise_params(params: dict[str, Any]) -> SerialisedParams:
|
491
492
|
"""
|
492
493
|
When writing column params to a migration file, we need to serialise some
|
493
494
|
of the values.
|
494
495
|
"""
|
495
496
|
params = deepcopy(params)
|
496
|
-
extra_imports:
|
497
|
-
extra_definitions:
|
497
|
+
extra_imports: list[Import] = []
|
498
|
+
extra_definitions: list[Definition] = []
|
498
499
|
|
499
500
|
for key, value in params.items():
|
500
501
|
# Builtins, such as str, list and dict.
|
@@ -725,7 +726,7 @@ def serialise_params(params: t.Dict[str, t.Any]) -> SerialisedParams:
|
|
725
726
|
)
|
726
727
|
|
727
728
|
|
728
|
-
def deserialise_params(params:
|
729
|
+
def deserialise_params(params: dict[str, Any]) -> dict[str, Any]:
|
729
730
|
"""
|
730
731
|
When reading column params from a migration file, we need to convert
|
731
732
|
them from their serialised form.
|
@@ -737,6 +738,8 @@ def deserialise_params(params: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
|
|
737
738
|
if isinstance(value, str) and not isinstance(value, Enum):
|
738
739
|
if value != "self":
|
739
740
|
params[key] = deserialise_legacy_params(name=key, value=value)
|
741
|
+
elif isinstance(value, SerialisedColumnInstance):
|
742
|
+
params[key] = value.instance
|
740
743
|
elif isinstance(value, SerialisedClassInstance):
|
741
744
|
params[key] = value.instance
|
742
745
|
elif isinstance(value, SerialisedUUID):
|
@@ -1,14 +1,14 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import datetime
|
4
|
-
|
4
|
+
from typing import Any
|
5
5
|
|
6
6
|
from piccolo.columns.column_types import OnDelete, OnUpdate
|
7
7
|
from piccolo.columns.defaults.timestamp import TimestampNow
|
8
8
|
from piccolo.table import create_table_class
|
9
9
|
|
10
10
|
|
11
|
-
def deserialise_legacy_params(name: str, value: str) ->
|
11
|
+
def deserialise_legacy_params(name: str, value: str) -> Any:
|
12
12
|
"""
|
13
13
|
Earlier versions of Piccolo serialised parameters differently. This is
|
14
14
|
here purely for backwards compatibility.
|
@@ -2,7 +2,6 @@ from __future__ import annotations
|
|
2
2
|
|
3
3
|
import os
|
4
4
|
import sys
|
5
|
-
import typing as t
|
6
5
|
|
7
6
|
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
8
7
|
from piccolo.apps.migrations.commands.base import (
|
@@ -31,7 +30,7 @@ class BackwardsMigrationManager(BaseMigrationManager):
|
|
31
30
|
super().__init__()
|
32
31
|
|
33
32
|
async def run_migrations_backwards(self, app_config: AppConfig):
|
34
|
-
migration_modules:
|
33
|
+
migration_modules: dict[str, MigrationModule] = (
|
35
34
|
self.get_migration_modules(
|
36
35
|
app_config.resolved_migrations_folder_path
|
37
36
|
)
|
@@ -3,8 +3,8 @@ from __future__ import annotations
|
|
3
3
|
import importlib
|
4
4
|
import os
|
5
5
|
import sys
|
6
|
-
import typing as t
|
7
6
|
from dataclasses import dataclass
|
7
|
+
from typing import Optional, cast
|
8
8
|
|
9
9
|
from piccolo.apps.migrations.auto.diffable_table import DiffableTable
|
10
10
|
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
@@ -16,7 +16,7 @@ from piccolo.conf.apps import AppConfig, Finder, MigrationModule
|
|
16
16
|
@dataclass
|
17
17
|
class MigrationResult:
|
18
18
|
success: bool
|
19
|
-
message:
|
19
|
+
message: Optional[str] = None
|
20
20
|
|
21
21
|
|
22
22
|
class BaseMigrationManager(Finder):
|
@@ -32,7 +32,7 @@ class BaseMigrationManager(Finder):
|
|
32
32
|
|
33
33
|
def get_migration_modules(
|
34
34
|
self, folder_path: str
|
35
|
-
) ->
|
35
|
+
) -> dict[str, MigrationModule]:
|
36
36
|
"""
|
37
37
|
Imports the migration modules in the given folder path, and returns
|
38
38
|
a mapping of migration ID to the corresponding migration module.
|
@@ -50,8 +50,8 @@ class BaseMigrationManager(Finder):
|
|
50
50
|
if ((i not in excluded) and i.endswith(".py"))
|
51
51
|
]
|
52
52
|
|
53
|
-
modules:
|
54
|
-
|
53
|
+
modules: list[MigrationModule] = [
|
54
|
+
cast(MigrationModule, importlib.import_module(name))
|
55
55
|
for name in migration_names
|
56
56
|
]
|
57
57
|
for m in modules:
|
@@ -62,8 +62,8 @@ class BaseMigrationManager(Finder):
|
|
62
62
|
return migration_modules
|
63
63
|
|
64
64
|
def get_migration_ids(
|
65
|
-
self, migration_module_dict:
|
66
|
-
) ->
|
65
|
+
self, migration_module_dict: dict[str, MigrationModule]
|
66
|
+
) -> list[str]:
|
67
67
|
"""
|
68
68
|
Returns a list of migration IDs, from the Python migration files.
|
69
69
|
"""
|
@@ -72,9 +72,9 @@ class BaseMigrationManager(Finder):
|
|
72
72
|
async def get_migration_managers(
|
73
73
|
self,
|
74
74
|
app_config: AppConfig,
|
75
|
-
max_migration_id:
|
75
|
+
max_migration_id: Optional[str] = None,
|
76
76
|
offset: int = 0,
|
77
|
-
) ->
|
77
|
+
) -> list[MigrationManager]:
|
78
78
|
"""
|
79
79
|
Call the forwards coroutine in each migration module. Each one should
|
80
80
|
return a `MigrationManger`. Combine all of the results, and return in
|
@@ -84,11 +84,11 @@ class BaseMigrationManager(Finder):
|
|
84
84
|
If set, only MigrationManagers up to and including the given
|
85
85
|
migration ID will be returned.
|
86
86
|
"""
|
87
|
-
migration_managers:
|
87
|
+
migration_managers: list[MigrationManager] = []
|
88
88
|
|
89
89
|
migrations_folder = app_config.resolved_migrations_folder_path
|
90
90
|
|
91
|
-
migration_modules:
|
91
|
+
migration_modules: dict[str, MigrationModule] = (
|
92
92
|
self.get_migration_modules(migrations_folder)
|
93
93
|
)
|
94
94
|
|
@@ -118,7 +118,7 @@ class BaseMigrationManager(Finder):
|
|
118
118
|
self,
|
119
119
|
app_name: str,
|
120
120
|
table_class_name: str,
|
121
|
-
max_migration_id:
|
121
|
+
max_migration_id: Optional[str] = None,
|
122
122
|
offset: int = 0,
|
123
123
|
) -> DiffableTable:
|
124
124
|
"""
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import dataclasses
|
2
|
-
import typing as t
|
3
2
|
|
4
3
|
from piccolo.apps.migrations.commands.base import BaseMigrationManager
|
5
4
|
from piccolo.apps.migrations.tables import Migration
|
@@ -19,11 +18,11 @@ class CheckMigrationManager(BaseMigrationManager):
|
|
19
18
|
self.app_name = app_name
|
20
19
|
super().__init__()
|
21
20
|
|
22
|
-
async def get_migration_statuses(self) ->
|
21
|
+
async def get_migration_statuses(self) -> list[MigrationStatus]:
|
23
22
|
# Make sure the migration table exists, otherwise we'll get an error.
|
24
23
|
await self.create_migration_table()
|
25
24
|
|
26
|
-
migration_statuses:
|
25
|
+
migration_statuses: list[MigrationStatus] = []
|
27
26
|
|
28
27
|
app_modules = self.get_app_modules()
|
29
28
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
|
3
|
+
from typing import cast
|
4
4
|
|
5
5
|
from piccolo.apps.migrations.commands.base import BaseMigrationManager
|
6
6
|
from piccolo.apps.migrations.tables import Migration
|
@@ -12,7 +12,7 @@ class CleanMigrationManager(BaseMigrationManager):
|
|
12
12
|
self.auto_agree = auto_agree
|
13
13
|
super().__init__()
|
14
14
|
|
15
|
-
def get_migration_ids_to_remove(self) ->
|
15
|
+
def get_migration_ids_to_remove(self) -> list[str]:
|
16
16
|
"""
|
17
17
|
Returns a list of migration ID strings, which are rows in the table,
|
18
18
|
but don't have a corresponding migration module on disk.
|
@@ -37,7 +37,7 @@ class CleanMigrationManager(BaseMigrationManager):
|
|
37
37
|
if len(migration_ids) > 0:
|
38
38
|
query = query.where(Migration.name.not_in(migration_ids))
|
39
39
|
|
40
|
-
return
|
40
|
+
return cast(list[str], query.run_sync())
|
41
41
|
|
42
42
|
async def run(self):
|
43
43
|
print("Checking the migration table ...")
|
@@ -1,7 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
3
|
import sys
|
4
|
-
import typing as t
|
5
4
|
|
6
5
|
from piccolo.apps.migrations.auto.migration_manager import MigrationManager
|
7
6
|
from piccolo.apps.migrations.commands.base import (
|
@@ -32,7 +31,7 @@ class ForwardsMigrationManager(BaseMigrationManager):
|
|
32
31
|
app_name=app_config.app_name
|
33
32
|
)
|
34
33
|
|
35
|
-
migration_modules:
|
34
|
+
migration_modules: dict[str, MigrationModule] = (
|
36
35
|
self.get_migration_modules(
|
37
36
|
app_config.resolved_migrations_folder_path
|
38
37
|
)
|