scruby 2.3.4__py3-none-any.whl → 2.4.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.
scruby/__init__.py CHANGED
@@ -32,6 +32,7 @@ __all__ = (
32
32
  "ScrubyModel",
33
33
  "ScrubyConfig",
34
34
  "ReturnType",
35
+ "Utils",
35
36
  )
36
37
 
37
38
 
@@ -39,3 +40,4 @@ from scruby.config import ScrubyConfig
39
40
  from scruby.db import Scruby
40
41
  from scruby.mixins.find import ReturnType
41
42
  from scruby.model import ScrubyModel
43
+ from scruby.utils import Utils
scruby/db.py CHANGED
@@ -21,6 +21,7 @@ from scruby import mixins
21
21
  from scruby.cache import DocCache
22
22
  from scruby.config import ScrubyConfig
23
23
  from scruby.meta import Meta
24
+ from scruby.migration import Migration
24
25
  from scruby.model import ScrubyModel
25
26
 
26
27
 
@@ -208,4 +209,5 @@ class Scruby(
208
209
  ScrubyConfig.plugins = plugins
209
210
  ScrubyConfig.init_params()
210
211
  ScrubyConfig.check_hash_reduce_left()
212
+ Migration.run(db_root, subclasses)
211
213
  DocCache.load_cache(subclasses)
scruby/migration.py ADDED
@@ -0,0 +1,33 @@
1
+ """Migration."""
2
+
3
+ from __future__ import annotations
4
+
5
+ __all__ = ("Migration",)
6
+
7
+ from pathlib import Path
8
+ from shutil import rmtree
9
+ from typing import Any
10
+
11
+ from scruby.utils import Utils
12
+
13
+
14
+ class Migration:
15
+ """Migration."""
16
+
17
+ @classmethod
18
+ def run(cls, db_root: Path | str, subclasses: list[Any]) -> None:
19
+ """Run migration."""
20
+ # Delete collections whose models have been deleted
21
+ cls.delete_orphan_collections(db_root, subclasses)
22
+
23
+ @staticmethod
24
+ def delete_orphan_collections(db_root: Path | str, subclasses: list[Any]) -> None:
25
+ """Delete collections whose models have been deleted."""
26
+ model_collection_list: list[str] = [subclass.__name__ for subclass in subclasses]
27
+ db_collection_list: list[str] | None = Utils.db_collection_list(db_root)
28
+
29
+ if db_collection_list is not None:
30
+ for collection_name in db_collection_list:
31
+ if collection_name not in model_collection_list:
32
+ target_directory = Path(db_root, collection_name)
33
+ rmtree(target_directory)
@@ -47,10 +47,10 @@ class Collection:
47
47
  Returns:
48
48
  None.
49
49
  """
50
- # Clear collection on file system
50
+ # Delete collection on file system
51
51
  target_directory = f"{ScrubyConfig.db_root}/{collection_name}"
52
52
  rmtree(target_directory)
53
- # Create metadata for collection
53
+ # Create collection and metadata
54
54
  Metadata.create(collection_name)
55
55
 
56
56
  # Clear collection in cache
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: scruby
3
- Version: 2.3.4
3
+ Version: 2.4.0
4
4
  Summary: Asynchronous library for building and managing a hybrid database, by scheme of key-value.
5
5
  Project-URL: Bug Tracker, https://github.com/kebasyaty/scruby/issues
6
6
  Project-URL: Changelog, https://github.com/kebasyaty/scruby/blob/v2/CHANGELOG.md
@@ -41,9 +41,9 @@ Description-Content-Type: text/markdown
41
41
  <p align="center">
42
42
  <a href="https://github.com/kebasyaty/scruby">
43
43
  <img
44
- height="80"
44
+ width="100%"
45
45
  alt="Logo"
46
- src="https://raw.githubusercontent.com/kebasyaty/scruby/v2/assets/logo.svg">
46
+ src="https://raw.githubusercontent.com/kebasyaty/scruby/v2/assets/logo.jpg">
47
47
  </a>
48
48
  </p>
49
49
  <p>
@@ -94,7 +94,7 @@ Description-Content-Type: text/markdown
94
94
  <br>
95
95
  6 = 256 branches in collection -> Docs: ~256000+, RAM: ~4G+, CPU: ~2+ (for small projects).
96
96
  <br>
97
- 5 = 4096 branches in collection -> Docs: ~4096000+, RAM: ~6G+, CPU: ~3+ (for large projects).
97
+ 5 = 4096 branches in collection -> Docs: ~4096000+, RAM: ~6G+, CPU: ~4+ (for large projects).
98
98
  <br>
99
99
  0 = 4294967296 branches in collection -> Docs: ~4,294967296×10¹²+, RAM: ~2G+, CPU: ~2+ (access only by keys).
100
100
  <br>
@@ -1,23 +1,24 @@
1
- scruby/__init__.py,sha256=YIR8zFx0GmS8ha96-MU9yCgKeYNIh1K8idlQckfg21E,1324
1
+ scruby/__init__.py,sha256=deNLNpHBxrXFFRtIp6JakcyeaOuedFN1MiPTsXKLAis,1368
2
2
  scruby/aggregation.py,sha256=NBFxQqyRqUG2KIuD9fbl4uzSHJWTaskjiZ1YNBa-Zbo,3575
3
3
  scruby/cache.py,sha256=j_uRBF72p7kzUK6GMHIIqb8nM2RneCod45dbbI1KTjQ,4018
4
4
  scruby/config.py,sha256=oyBEOzmKy9vka23ZDvP8Jqu-HMYn8HCmJ0j2TfOs-0w,5127
5
- scruby/db.py,sha256=oulRx20bezbv2IwcsDq6TgsXo_zQz8ZE6ohmWg4kv2k,7107
5
+ scruby/db.py,sha256=ZhPoW0O1SYPhTqFTKc0GOQZjn6Lii3HOUHcfRPlP_eM,7189
6
6
  scruby/errors.py,sha256=lTWiHzyO5Es9Nkf7quODJjONGn6ifcL95qlpA4epQQM,1386
7
7
  scruby/meta.py,sha256=dfr8q3TWhVcEl-lZuH5yd9rbO9vAPBhXBO3VYCNcOWo,1283
8
+ scruby/migration.py,sha256=SkbiSrSIqspQZTEXvg-yqWz5CLBvtnuwfl8G7flOS0Q,1083
8
9
  scruby/model.py,sha256=1infUd1G-zxj5Z93mNOp1Wi2anD6TKDgu5Y0KEVcH2k,292
9
10
  scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
11
  scruby/utils.py,sha256=l-UNz_DEuYEx6vS8ExgFGzbueQ6RwencClZQUr3VReo,2437
11
12
  scruby/mixins/__init__.py,sha256=nT79e80zXliuTGhR9CFosI2-3PQUCKwXbR7wPiFwgrU,669
12
- scruby/mixins/collection.py,sha256=3Gn9zIT-WnSCBd-IgpE9tobRlW675YX__qaWoUOWIJM,1758
13
+ scruby/mixins/collection.py,sha256=lnwViHrJFrammQhJFGX_zicdr008-6GNcRI09JpXR-c,1759
13
14
  scruby/mixins/count.py,sha256=CGpyOpsG25uC5utI2ByNxq2iTbJocj6w5tXrC1_cP40,2561
14
15
  scruby/mixins/custom_task.py,sha256=DIry4gBlTdaqZqymar-RrHSdhEiC2tn2pl9jmbk56zw,1547
15
16
  scruby/mixins/delete.py,sha256=InKVIud_ZYx9-CchUz_IygQDXMynNi4jQ0HKYeHC_R8,4328
16
17
  scruby/mixins/find.py,sha256=oEZRE6RqIBdwvNr8iSYyod8hI6ibi_egJP0pyXmJiss,9169
17
18
  scruby/mixins/keys.py,sha256=MvBy_8fQGROaQATK2qse2V8wR-xodPQG0KKZ2PK_t9U,10790
18
19
  scruby/mixins/update.py,sha256=TyxvxB-gNijlfzTmhwrq0ydvu0C3R-RihW5h5tJ96bM,4964
19
- scruby-2.3.4.dist-info/METADATA,sha256=UYSkl9-u4XeNU933XiERMxDocG_kLz5XomhhlYv3u4A,13430
20
- scruby-2.3.4.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
21
- scruby-2.3.4.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
22
- scruby-2.3.4.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
23
- scruby-2.3.4.dist-info/RECORD,,
20
+ scruby-2.4.0.dist-info/METADATA,sha256=p0EangsFZxQS9z8t3rOiDHYK6Umik7p4abH5z9UlW64,13431
21
+ scruby-2.4.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
22
+ scruby-2.4.0.dist-info/licenses/GPL-3.0-LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
23
+ scruby-2.4.0.dist-info/licenses/MIT-LICENSE,sha256=mS0Wz0yGNB63gEcWEnuIb_lldDYV0sjRaO-o_GL6CWE,1074
24
+ scruby-2.4.0.dist-info/RECORD,,
File without changes