alphadb-postgres 1.0.0b54__tar.gz → 1.0.0b57__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.
Files changed (124) hide show
  1. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/PKG-INFO +2 -2
  2. alphadb_postgres-1.0.0b57/alphadb/assets/config_table.mysql.json +55 -0
  3. alphadb_postgres-1.0.0b57/alphadb/assets/config_table.postgres.json +55 -0
  4. alphadb_postgres-1.0.0b57/alphadb/src/core/config_table.rs +171 -0
  5. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/method_types.rs +2 -6
  6. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/mod.rs +1 -0
  7. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/update_queries.rs +27 -5
  8. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/globals.rs +4 -0
  9. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/json.rs +21 -0
  10. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/init.rs +10 -16
  11. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/status.rs +6 -21
  12. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/update.rs +10 -3
  13. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/update_queries.rs +7 -10
  14. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/column/definecolumn.rs +7 -10
  15. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/table/config.rs +1 -1
  16. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/utils/mod.rs +0 -1
  17. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/init.rs +23 -18
  18. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/status.rs +12 -20
  19. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/update.rs +9 -3
  20. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/update_queries.rs +7 -10
  21. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/column/altercolumn.rs +20 -19
  22. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/column/definecolumn.rs +7 -10
  23. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/utils/mod.rs +0 -1
  24. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/packages/mysql/pyproject.toml +1 -1
  25. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/packages/postgres/pyproject.toml +2 -2
  26. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/pyproject.toml +2 -2
  27. alphadb_postgres-1.0.0b54/alphadb/src/engine/mysql_impl/utils/check.rs +0 -56
  28. alphadb_postgres-1.0.0b54/alphadb/src/engine/postgres_impl/utils/check.rs +0 -56
  29. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/LICENSE +0 -0
  30. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/README.md +0 -0
  31. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/Cargo.lock +0 -0
  32. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/Cargo.toml +0 -0
  33. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/LICENSE +0 -0
  34. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/README.md +0 -0
  35. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/rustfmt.toml +0 -0
  36. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/engine.rs +0 -0
  37. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/engine_config.rs +0 -0
  38. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/build.rs +0 -0
  39. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/column/definecolumn.rs +0 -0
  40. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/column/mod.rs +0 -0
  41. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/default_data.rs +0 -0
  42. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/mod.rs +0 -0
  43. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/primary_key.rs +0 -0
  44. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/query/table.rs +0 -0
  45. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/runtime_config.rs +0 -0
  46. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/condition.rs +0 -0
  47. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/column.rs +0 -0
  48. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/default_data.rs +0 -0
  49. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/mod.rs +0 -0
  50. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/primary_key.rs +0 -0
  51. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/table.rs +0 -0
  52. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/consolidate/version_source.rs +0 -0
  53. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/error_messages.rs +0 -0
  54. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/errors.rs +0 -0
  55. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/mod.rs +0 -0
  56. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/types.rs +0 -0
  57. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/version_number.rs +0 -0
  58. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/utils/version_source.rs +0 -0
  59. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/compatibility.rs +0 -0
  60. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/foreign_key.rs +0 -0
  61. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/index.rs +0 -0
  62. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/issue.rs +0 -0
  63. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/json.rs +0 -0
  64. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/mod.rs +0 -0
  65. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/verification/primary_key.rs +0 -0
  66. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/core/version_source_verification.rs +0 -0
  67. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mod.rs +0 -0
  68. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/config.rs +0 -0
  69. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/connect.rs +0 -0
  70. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/mod.rs +0 -0
  71. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/methods/vacate.rs +0 -0
  72. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/mod.rs +0 -0
  73. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/column/mod.rs +0 -0
  74. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/constraint/check.rs +0 -0
  75. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/constraint/foreign_key.rs +0 -0
  76. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/constraint/mod.rs +0 -0
  77. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/default_data.rs +0 -0
  78. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/index/index.rs +0 -0
  79. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/index/mod.rs +0 -0
  80. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/mod.rs +0 -0
  81. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/query/table/mod.rs +0 -0
  82. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/utils/connection.rs +0 -0
  83. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/utils/errors.rs +0 -0
  84. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/verification/compatibility.rs +0 -0
  85. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/verification/config.rs +0 -0
  86. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/mysql_impl/verification/mod.rs +0 -0
  87. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/config.rs +0 -0
  88. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/connect.rs +0 -0
  89. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/mod.rs +0 -0
  90. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/methods/vacate.rs +0 -0
  91. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/mod.rs +0 -0
  92. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/column/mod.rs +0 -0
  93. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/constraint/check.rs +0 -0
  94. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/constraint/foreign_key.rs +0 -0
  95. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/constraint/mod.rs +0 -0
  96. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/default_data.rs +0 -0
  97. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/extension.rs +0 -0
  98. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/index/index.rs +0 -0
  99. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/index/mod.rs +0 -0
  100. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/mod.rs +0 -0
  101. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/table/config.rs +0 -0
  102. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/query/table/mod.rs +0 -0
  103. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/utils/connection.rs +0 -0
  104. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/utils/errors.rs +0 -0
  105. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/verification/compatibility.rs +0 -0
  106. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/verification/config.rs +0 -0
  107. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/engine/postgres_impl/verification/mod.rs +0 -0
  108. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/lib.rs +0 -0
  109. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/prelude.rs +0 -0
  110. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/verification.rs +0 -0
  111. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/version_source/combine.rs +0 -0
  112. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/version_source/mod.rs +0 -0
  113. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/alphadb/src/version_source/parse.rs +0 -0
  114. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/Cargo.lock +0 -0
  115. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/Cargo.toml +0 -0
  116. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/LICENSE +0 -0
  117. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/README.md +0 -0
  118. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/alphadb.pyi +0 -0
  119. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/packages/mysql/README.md +0 -0
  120. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/packages/postgres/LICENSE +0 -0
  121. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/packages/postgres/README.md +0 -0
  122. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/requirements.txt +0 -0
  123. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/src/lib.rs +0 -0
  124. {alphadb_postgres-1.0.0b54 → alphadb_postgres-1.0.0b57}/py/tests/test_alphadb.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: alphadb-postgres
3
- Version: 1.0.0b54
3
+ Version: 1.0.0b57
4
4
  Classifier: Programming Language :: Rust
5
5
  Classifier: Programming Language :: Python :: Implementation :: CPython
6
6
  Classifier: Programming Language :: Python :: Implementation :: PyPy
@@ -12,7 +12,7 @@ Summary: AlphaDB is a versatile tool for managing PostgreSQL database versions,
12
12
  Keywords: database,rust,extension,postgres database management,postgres version management,database migration tool,database version management
13
13
  Home-Page: https://alphadb.w-kuipers.com
14
14
  License-Expression: GPL-3.0
15
- Requires-Python: >=3.8
15
+ Requires-Python: >=3.10
16
16
  Description-Content-Type: text/markdown
17
17
  Project-URL: Bug Tracker, https://github.com/w-kuipers/alphadb/issues
18
18
  Project-URL: Documentation, https://alphadb.w-kuipers.com
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "AlphaDB Config",
3
+ "engine": "mysql",
4
+ "version": [
5
+ {
6
+ "_id": "1.0.0",
7
+ "createtable": {
8
+ "adb_conf": {
9
+ "primary_key": "db",
10
+ "db": {
11
+ "type": "VARCHAR",
12
+ "length": 100
13
+ },
14
+ "version": {
15
+ "type": "VARCHAR",
16
+ "length": 50
17
+ },
18
+ "template": {
19
+ "type": "VARCHAR",
20
+ "length": 50,
21
+ "null": true
22
+ }
23
+ }
24
+ }
25
+ },
26
+ {
27
+ "_id": "1.0.1",
28
+ "altertable": {
29
+ "adb_conf": {
30
+ "primary_key": ["template", "version"],
31
+ "addcolumn": {
32
+ "applied": {
33
+ "type": "DATETIME",
34
+ "default": "CURRENT_TIMESTAMP"
35
+ }
36
+ },
37
+ "modifycolumn": {
38
+ "template": {
39
+ "type": "VARCHAR",
40
+ "length": 50
41
+ }
42
+ }
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "_id": "1.0.2",
48
+ "altertable": {
49
+ "adb_conf": {
50
+ "dropcolumn": ["db"]
51
+ }
52
+ }
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "AlphaDB Config",
3
+ "engine": "postgres",
4
+ "version": [
5
+ {
6
+ "_id": "1.0.0",
7
+ "createtable": {
8
+ "adb_conf": {
9
+ "primary_key": "db",
10
+ "db": {
11
+ "type": "VARCHAR",
12
+ "length": 100
13
+ },
14
+ "version": {
15
+ "type": "VARCHAR",
16
+ "length": 50
17
+ },
18
+ "template": {
19
+ "type": "VARCHAR",
20
+ "length": 50,
21
+ "null": true
22
+ }
23
+ }
24
+ }
25
+ },
26
+ {
27
+ "_id": "1.0.1",
28
+ "altertable": {
29
+ "adb_conf": {
30
+ "primary_key": ["template", "version"],
31
+ "addcolumn": {
32
+ "applied": {
33
+ "type": "TIMESTAMP",
34
+ "default": "CURRENT_TIMESTAMP"
35
+ }
36
+ },
37
+ "modifycolumn": {
38
+ "template": {
39
+ "type": "VARCHAR",
40
+ "length": 50
41
+ }
42
+ }
43
+ }
44
+ }
45
+ },
46
+ {
47
+ "_id": "1.0.2",
48
+ "altertable": {
49
+ "adb_conf": {
50
+ "dropcolumn": ["db"]
51
+ }
52
+ }
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,171 @@
1
+ // Copyright (C) 2024 Wibo Kuipers
2
+ //
3
+ // This program is free software: you can redistribute it and/or modify
4
+ // it under the terms of the GNU General Public License as published by
5
+ // the Free Software Foundation, either version 3 of the License, or
6
+ // (at your option) any later version.
7
+ //
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU General Public License for more details.
12
+ //
13
+ // You should have received a copy of the GNU General Public License
14
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
+
16
+ //! The config table (`adb_conf`) is defined by its own version source, baked in
17
+ //! from `assets/config_table.<engine>.json`. One file per engine because the
18
+ //! engines share no datetime type. The table is a log of applied versions per
19
+ //! template; the table's own versions are logged under [`CONFIG_TABLE_TEMPLATE_NAME`].
20
+
21
+ use crate::core::method_types::{Query, Status};
22
+ use crate::core::query::table::{alter_table, create_table};
23
+ use crate::core::update_queries::UpdateQueriesConfig;
24
+ use crate::core::utils::errors::AlphaDBError;
25
+ use crate::core::utils::globals::{CONFIG_TABLE_NAME, CONFIG_TABLE_TEMPLATE_NAME};
26
+ use crate::core::utils::json::get_json_string;
27
+ use crate::core::utils::version_number::{parse_version_number, sort_versions};
28
+ use crate::core::utils::version_source::{get_version_array, parse_version_source_string};
29
+ use serde_json::Value;
30
+
31
+ fn invalid_source(message: String) -> AlphaDBError {
32
+ AlphaDBError {
33
+ message,
34
+ error: "invalid-config-table-version-source".to_string(),
35
+ ..Default::default()
36
+ }
37
+ }
38
+
39
+ fn load_version_source(engine: &str) -> Result<Value, AlphaDBError> {
40
+ let source = match engine {
41
+ "mysql" => include_str!("../../assets/config_table.mysql.json"),
42
+ "postgres" => include_str!("../../assets/config_table.postgres.json"),
43
+ _ => return Err(invalid_source(format!("No config table version source exists for engine '{engine}'"))),
44
+ };
45
+
46
+ let mut version_source = parse_version_source_string(source.to_string())?;
47
+
48
+ // The rest of the crate queries by these constants, so the JSON must match them.
49
+ if version_source["name"] != CONFIG_TABLE_TEMPLATE_NAME {
50
+ return Err(invalid_source(format!("The config table version source must be named '{CONFIG_TABLE_TEMPLATE_NAME}'")));
51
+ }
52
+
53
+ let versions = version_source["version"].as_array_mut().ok_or_else(|| invalid_source("The config table version source has no versions".to_string()))?;
54
+
55
+ if !versions.iter().any(|version| version["createtable"][CONFIG_TABLE_NAME].is_object()) {
56
+ return Err(invalid_source(format!("The config table version source does not create the '{CONFIG_TABLE_NAME}' table")));
57
+ }
58
+
59
+ sort_versions(versions)?;
60
+
61
+ Ok(version_source)
62
+ }
63
+
64
+ /// Queries that bring the config table from `current_version` (`None` when it
65
+ /// does not exist yet) to the latest baked-in version, followed by one history
66
+ /// row per version applied.
67
+ pub fn config_table_queries<C>(config: &UpdateQueriesConfig<C>, current_version: Option<&str>) -> Result<Vec<Query>, AlphaDBError> {
68
+ let version_source = load_version_source(config.table_config.name)?;
69
+ let current_version = current_version.map(parse_version_number).transpose()?;
70
+ let mut queries = Vec::new();
71
+ let mut history = Vec::new();
72
+
73
+ for version in get_version_array(&version_source)? {
74
+ let version_number = get_json_string(&version["_id"])?;
75
+ let version_int = parse_version_number(version_number)?;
76
+
77
+ if current_version.is_some_and(|current| version_int <= current) {
78
+ continue;
79
+ }
80
+
81
+ if let Some(tables) = version["createtable"].as_object() {
82
+ for table in tables.keys() {
83
+ queries.push(Query {
84
+ query: create_table(config.table_config, version, table, version_number)?,
85
+ data: None,
86
+ });
87
+ }
88
+ }
89
+
90
+ if let Some(tables) = version["altertable"].as_object() {
91
+ for table in tables.keys() {
92
+ queries.push(Query {
93
+ query: alter_table(config.table_config, &version_source, table, version_number)?,
94
+ data: None,
95
+ });
96
+ }
97
+ }
98
+
99
+ history.push((config.config_insert_query)(version_number, CONFIG_TABLE_TEMPLATE_NAME));
100
+ }
101
+
102
+ // Versions before 1.0.2 still have the not-null `db` column and can't hold rows.
103
+ queries.extend(history);
104
+
105
+ Ok(queries)
106
+ }
107
+
108
+ fn newest(current: Option<String>, candidate: String) -> Result<Option<String>, AlphaDBError> {
109
+ match current {
110
+ Some(current) if parse_version_number(&current)? >= parse_version_number(&candidate)? => Ok(Some(current)),
111
+ _ => Ok(Some(candidate)),
112
+ }
113
+ }
114
+
115
+ /// Derive the status from the config table's `(version, template)` rows; `None`
116
+ /// means the table does not exist. Latest versions are picked by parsed version
117
+ /// number, so `1.0.10` beats `1.0.9`.
118
+ pub fn build_status(db_name: &str, rows: Option<Vec<(String, Option<String>)>>) -> Result<Status, AlphaDBError> {
119
+ let Some(rows) = rows else {
120
+ return Ok(Status {
121
+ init: false,
122
+ version: None,
123
+ name: db_name.to_string(),
124
+ template: None,
125
+ config_version: None,
126
+ });
127
+ };
128
+
129
+ let mut config_version = None;
130
+ let mut version = None;
131
+ let mut template = None;
132
+
133
+ for (row_version, row_template) in rows {
134
+ // Only pre-log tables hold null templates; the history check below reports those.
135
+ let Some(row_template) = row_template else { continue };
136
+
137
+ if row_template == CONFIG_TABLE_TEMPLATE_NAME {
138
+ config_version = newest(config_version, row_version)?;
139
+ continue;
140
+ }
141
+
142
+ match &template {
143
+ Some(template) if *template != row_template => {
144
+ return Err(AlphaDBError {
145
+ message: format!("The config table holds versions for multiple templates ('{template}' and '{row_template}')"),
146
+ error: "multiple-templates".to_string(),
147
+ ..Default::default()
148
+ })
149
+ }
150
+ _ => template = Some(row_template),
151
+ }
152
+
153
+ version = newest(version, row_version)?;
154
+ }
155
+
156
+ if config_version.is_none() {
157
+ return Err(AlphaDBError {
158
+ message: "The config table holds no version history for itself. Vacate the database and run init again.".to_string(),
159
+ error: "no-config-table-history".to_string(),
160
+ ..Default::default()
161
+ });
162
+ }
163
+
164
+ Ok(Status {
165
+ init: true,
166
+ version: Some(version.unwrap_or_else(|| "0.0.0".to_string())),
167
+ name: db_name.to_string(),
168
+ template,
169
+ config_version,
170
+ })
171
+ }
@@ -20,18 +20,14 @@ pub enum Init {
20
20
  Success,
21
21
  }
22
22
 
23
- #[derive(Debug)]
24
- pub struct Check {
25
- pub check: bool,
26
- pub version: Option<String>,
27
- }
28
-
29
23
  #[derive(Debug)]
30
24
  pub struct Status {
31
25
  pub init: bool,
32
26
  pub version: Option<String>,
33
27
  pub name: String,
34
28
  pub template: Option<String>,
29
+ /// Latest applied version of the config table itself.
30
+ pub config_version: Option<String>,
35
31
  }
36
32
 
37
33
  #[derive(Debug, Clone, PartialEq)]
@@ -2,6 +2,7 @@ pub mod query;
2
2
  pub mod utils;
3
3
  pub mod verification;
4
4
  // pub mod version_source_verification;
5
+ pub mod config_table;
5
6
  pub mod engine;
6
7
  pub mod engine_config;
7
8
  pub mod method_types;
@@ -18,10 +18,12 @@
18
18
  //! mirroring how [`TableQueryConfig`](crate::core::query::table::TableQueryConfig)
19
19
  //! factors the table builders.
20
20
 
21
+ use crate::core::config_table::config_table_queries;
21
22
  use crate::core::method_types::{Query, Status};
22
23
  use crate::core::query::table::{alter_table, create_table, TableQueryConfig};
23
24
  use crate::core::utils::consolidate::default_data::consolidate_default_data;
24
25
  use crate::core::utils::errors::{AlphaDBError, Get};
26
+ use crate::core::utils::globals::CONFIG_TABLE_TEMPLATE_NAME;
25
27
  use crate::core::utils::json::{array_iter, exists_in_object, get_object_keys, object_iter};
26
28
  use crate::core::utils::version_number::{get_latest_version, parse_version_number, sort_versions, validate_version_number};
27
29
  use crate::core::utils::version_source::{get_version_array, parse_version_source_string};
@@ -37,7 +39,7 @@ pub type CreateIndexHook = fn(index: &Value, table_name: &str) -> Result<String,
37
39
  /// engines with globally-named indexes (PostgreSQL) ignore it.
38
40
  pub type DropIndexHook = fn(index_name: &Value, table_name: &str) -> Result<String, AlphaDBError>;
39
41
  pub type DefaultDataHook = fn(table_name: &str, item: &Value) -> Result<Query, AlphaDBError>;
40
- pub type ConfigUpdateQueryHook = fn(latest_version: &str, template_name: &str, db_name: &str) -> Query;
42
+ pub type ConfigInsertQueryHook = fn(version: &str, template_name: &str) -> Query;
41
43
  pub type VersionExtrasHook = fn(version: &Value) -> Result<Vec<Query>, AlphaDBError>;
42
44
 
43
45
  /// Engine-specific behaviour for [`update_queries`]. `C` is the engine connection
@@ -50,7 +52,8 @@ pub struct UpdateQueriesConfig<C> {
50
52
  pub create_index: CreateIndexHook,
51
53
  pub drop_index: DropIndexHook,
52
54
  pub default_data: DefaultDataHook,
53
- pub config_update_query: ConfigUpdateQueryHook,
55
+ /// Logs an applied version of `template_name` in the config table.
56
+ pub config_insert_query: ConfigInsertQueryHook,
54
57
 
55
58
  /// Runs once per version, before that version's tables. `None` if unused.
56
59
  pub version_extras: Option<VersionExtrasHook>,
@@ -75,7 +78,6 @@ pub fn update_queries<C>(
75
78
  target_version: Option<&str>,
76
79
  no_data: bool,
77
80
  ) -> Result<Vec<Query>, AlphaDBError> {
78
- let mut queries: Vec<Query> = Vec::new();
79
81
  let mut version_source = parse_version_source_string(version_source)?;
80
82
 
81
83
  // The version source may not be in order (combine concatenates in the
@@ -127,6 +129,14 @@ pub fn update_queries<C>(
127
129
  }
128
130
  };
129
131
 
132
+ if template_name == CONFIG_TABLE_TEMPLATE_NAME {
133
+ return Err(AlphaDBError {
134
+ message: format!("'{CONFIG_TABLE_TEMPLATE_NAME}' is reserved for the AlphaDB config table and can not be used as a version source name"),
135
+ error: "reserved-template-name".to_string(),
136
+ ..Default::default()
137
+ });
138
+ }
139
+
130
140
  if let Some(template) = status.template {
131
141
  if template != template_name {
132
142
  return Err(AlphaDBError {
@@ -161,6 +171,14 @@ pub fn update_queries<C>(
161
171
  });
162
172
  }
163
173
 
174
+ // The config table migrates itself before the user's versions are applied.
175
+ let config_version = status.config_version.ok_or_else(|| AlphaDBError {
176
+ message: "The config table has no version number".to_string(),
177
+ error: "no-config-version-number".to_string(),
178
+ ..Default::default()
179
+ })?;
180
+ let mut queries = config_table_queries(config, Some(&config_version))?;
181
+
164
182
  for (i, version) in versions.iter().enumerate() {
165
183
  let version_number = version["_id"].as_str().ok_or_else(|| AlphaDBError {
166
184
  message: "Missing a version number".to_string(),
@@ -270,16 +288,20 @@ pub fn update_queries<C>(
270
288
  }
271
289
  }
272
290
 
291
+ // Default data is a seeder: rows already seeded are never touched again, even
292
+ // when a later version edits them by index. Only rows appended since are new.
273
293
  if !no_data {
294
+ let seeded = consolidate_default_data(versions, Some(&database_version))?;
274
295
  let default_data_object = consolidate_default_data(versions, target_version)?;
275
296
  for table in object_iter(&default_data_object)? {
276
- for item in array_iter(&default_data_object[table])? {
297
+ let seeded_count = seeded[table].as_array().map_or(0, Vec::len);
298
+ for item in array_iter(&default_data_object[table])?.iter().skip(seeded_count) {
277
299
  queries.push((config.default_data)(table, item)?);
278
300
  }
279
301
  }
280
302
  }
281
303
 
282
- queries.push((config.config_update_query)(&latest_version, template_name, db_name));
304
+ queries.push((config.config_insert_query)(&latest_version, template_name));
283
305
 
284
306
  Ok(queries)
285
307
  }
@@ -14,3 +14,7 @@
14
14
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
15
 
16
16
  pub const CONFIG_TABLE_NAME: &str = "adb_conf";
17
+
18
+ /// Template name under which the config table logs its own versions. User
19
+ /// version sources may not use it.
20
+ pub const CONFIG_TABLE_TEMPLATE_NAME: &str = "AlphaDB Config";
@@ -181,6 +181,27 @@ pub fn get_json_float(value: &Value) -> Result<f64, AlphaDBError> {
181
181
  }
182
182
  }
183
183
 
184
+ /// Get a precision/scale length such as `10,2` from `10`, `10.2`, `"10,2"` or `"10.2"`.
185
+ ///
186
+ /// A bare JSON number loses trailing zeros in the scale (`20.10` arrives as `20.1`),
187
+ /// use the string form for those.
188
+ pub fn get_json_decimal_length(value: &Value) -> Result<String, AlphaDBError> {
189
+ let length = match value.as_str() {
190
+ Some(v) => v.replace(".", ","),
191
+ None => value.to_string().replace(".", ","),
192
+ };
193
+
194
+ if length.split(',').all(|part| part.parse::<u64>().is_ok()) {
195
+ return Ok(length);
196
+ }
197
+
198
+ Err(AlphaDBError {
199
+ message: format!("The value {} could not be parsed as a decimal length", value),
200
+ error: "invalid-json-number".to_string(),
201
+ ..Default::default()
202
+ })
203
+ }
204
+
184
205
  /// Check if a JSON value is empty
185
206
  ///
186
207
  /// - Null: Always empty
@@ -13,32 +13,26 @@
13
13
  // You should have received a copy of the GNU General Public License
14
14
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
15
 
16
+ use crate::core::config_table::config_table_queries;
16
17
  use crate::core::method_types::Init;
17
- use crate::core::utils::globals::CONFIG_TABLE_NAME;
18
- use crate::engine::mysql_impl::utils::check::check;
18
+ use crate::engine::mysql_impl::methods::update::query_value_to_mysql_value;
19
+ use crate::engine::mysql_impl::methods::{status, MYSQL_UPDATE_QUERIES_CONFIG};
19
20
  use crate::engine::mysql_impl::utils::errors::AlphaDBMysqlError;
20
21
  use mysql::prelude::*;
21
22
  use mysql::*;
22
23
 
23
24
  /// Initialize the database with configuration table
24
25
  pub fn init(db_name: &str, connection: &mut PooledConn) -> Result<Init, AlphaDBMysqlError> {
25
- let checked = check(db_name, connection);
26
-
27
- if checked.is_ok() && checked.unwrap().check {
26
+ if status(db_name, connection)?.init {
28
27
  return Ok(Init::AlreadyInitialized);
29
28
  }
30
29
 
31
- connection.query_drop(format!(
32
- "CREATE TABLE {} (
33
- db VARCHAR(100) NOT NULL,
34
- version VARCHAR(50) NOT NULL,
35
- template VARCHAR(50) NULL,
36
- PRIMARY KEY (db)
37
- )",
38
- CONFIG_TABLE_NAME
39
- ))?;
40
-
41
- connection.exec_drop(format!("INSERT INTO {} (db, version) VALUES (?, ?)", CONFIG_TABLE_NAME), (db_name, "0.0.0"))?;
30
+ for query in config_table_queries(&MYSQL_UPDATE_QUERIES_CONFIG, None)? {
31
+ match query.data {
32
+ Some(data) => connection.exec_drop(query.query, data.iter().map(query_value_to_mysql_value).collect::<Vec<_>>())?,
33
+ None => connection.query_drop(query.query)?,
34
+ }
35
+ }
42
36
 
43
37
  return Ok(Init::Success);
44
38
  }
@@ -13,6 +13,7 @@
13
13
  // You should have received a copy of the GNU General Public License
14
14
  // along with this program. If not, see <https://www.gnu.org/licenses/>.
15
15
 
16
+ use crate::core::config_table::build_status;
16
17
  use crate::core::method_types::Status;
17
18
  use crate::core::utils::globals::CONFIG_TABLE_NAME;
18
19
  use crate::engine::mysql_impl::utils::errors::AlphaDBMysqlError;
@@ -21,31 +22,15 @@ use mysql::*;
21
22
 
22
23
  /// Get database status including initialization state, version, name and template
23
24
  pub fn status(db_name: &str, connection: &mut PooledConn) -> Result<Status, AlphaDBMysqlError> {
24
- let mut init = false;
25
- let mut version: Option<String> = None;
26
- let mut template: Option<String> = None;
27
-
28
25
  let table_check: Option<String> = connection.exec_first(
29
26
  "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND table_name = ?",
30
27
  (db_name, CONFIG_TABLE_NAME),
31
28
  )?;
32
29
 
33
- if table_check.is_some() {
34
- let fetched: Option<Row> = connection.exec_first(format!("SELECT version, template FROM {} where db = ?", CONFIG_TABLE_NAME), (db_name,))?;
35
-
36
- if fetched.is_some() {
37
- let c = from_row::<(String, Option<String>)>(fetched.unwrap());
38
- version = Some(c.0);
39
- template = c.1;
40
- }
41
-
42
- init = true;
43
- }
30
+ let rows: Option<Vec<(String, Option<String>)>> = match table_check {
31
+ Some(_) => Some(connection.query(format!("SELECT version, template FROM {CONFIG_TABLE_NAME}"))?),
32
+ None => None,
33
+ };
44
34
 
45
- Ok(Status {
46
- init,
47
- version,
48
- name: db_name.to_string(),
49
- template,
50
- })
35
+ build_status(db_name, rows).map_err(|e| e.into())
51
36
  }
@@ -22,7 +22,7 @@ use crate::engine::mysql_impl::utils::errors::AlphaDBMysqlError;
22
22
  use mysql::prelude::*;
23
23
  use mysql::*;
24
24
 
25
- fn query_value_to_mysql_value(value: &QueryValue) -> mysql::Value {
25
+ pub(crate) fn query_value_to_mysql_value(value: &QueryValue) -> mysql::Value {
26
26
  match value {
27
27
  QueryValue::String(s) => mysql::Value::from(s.as_str()),
28
28
  QueryValue::Integer(i) => mysql::Value::from(*i),
@@ -43,10 +43,15 @@ pub fn update(
43
43
  ) -> Result<(), AlphaDBMysqlError> {
44
44
  let queries = update_queries(&MYSQL_UPDATE_QUERIES_CONFIG, db_name, connection, version_source, target_version, no_data)?;
45
45
 
46
+ // MySQL commits implicitly on every DDL statement, so this only makes the
47
+ // trailing default-data inserts and the version bump atomic. A drop
48
+ // without commit rolls back.
49
+ let mut tx = connection.start_transaction(TxOpts::default())?;
50
+
46
51
  for query in queries {
47
52
  if let Some(data) = query.data {
48
53
  let mysql_params: Vec<mysql::Value> = data.iter().map(query_value_to_mysql_value).collect();
49
- match connection.exec_drop(query.query, mysql_params) {
54
+ match tx.exec_drop(query.query, mysql_params) {
50
55
  Ok(result) => result,
51
56
  Err(error) => {
52
57
  return Err(AlphaDBError {
@@ -57,7 +62,7 @@ pub fn update(
57
62
  }
58
63
  };
59
64
  } else {
60
- match connection.exec_drop(query.query, ()) {
65
+ match tx.exec_drop(query.query, ()) {
61
66
  Ok(result) => result,
62
67
  Err(error) => {
63
68
  return Err(AlphaDBError {
@@ -70,5 +75,7 @@ pub fn update(
70
75
  }
71
76
  }
72
77
 
78
+ tx.commit()?;
79
+
73
80
  Ok(())
74
81
  }
@@ -31,7 +31,7 @@ pub const MYSQL_UPDATE_QUERIES_CONFIG: UpdateQueriesConfig<PooledConn> = UpdateQ
31
31
  create_index: createindex,
32
32
  drop_index: dropindex,
33
33
  default_data,
34
- config_update_query,
34
+ config_insert_query,
35
35
  version_extras: None,
36
36
  };
37
37
 
@@ -39,20 +39,16 @@ fn status_hook(db_name: &str, connection: &mut PooledConn) -> Result<Status, Alp
39
39
  status(db_name, connection).map_err(|e| e.into())
40
40
  }
41
41
 
42
- fn config_update_query(latest_version: &str, template_name: &str, db_name: &str) -> Query {
42
+ fn config_insert_query(version: &str, template_name: &str) -> Query {
43
43
  Query {
44
- query: format!("UPDATE `{CONFIG_TABLE_NAME}` SET `version`=?, `template`=? WHERE `db` = ?;"),
45
- data: Some(Vec::from([
46
- QueryValue::String(latest_version.to_string()),
47
- QueryValue::String(template_name.to_string()),
48
- QueryValue::String(db_name.to_string()),
49
- ])),
44
+ query: format!("INSERT INTO `{CONFIG_TABLE_NAME}` (`version`, `template`) VALUES (?, ?);"),
45
+ data: Some(Vec::from([QueryValue::String(version.to_string()), QueryValue::String(template_name.to_string())])),
50
46
  }
51
47
  }
52
48
 
53
49
  #[cfg(test)]
54
50
  mod altertable_index_tests {
55
- use super::config_update_query;
51
+ use super::config_insert_query;
56
52
  use crate::core::method_types::Status;
57
53
  use crate::core::update_queries::{update_queries, UpdateQueriesConfig};
58
54
  use crate::core::utils::errors::AlphaDBError;
@@ -68,6 +64,7 @@ mod altertable_index_tests {
68
64
  version: Some("0.0.0".to_string()),
69
65
  name: "test".to_string(),
70
66
  template: None,
67
+ config_version: Some("1.0.2".to_string()),
71
68
  })
72
69
  }
73
70
 
@@ -78,7 +75,7 @@ mod altertable_index_tests {
78
75
  create_index: createindex,
79
76
  drop_index: dropindex,
80
77
  default_data,
81
- config_update_query,
78
+ config_insert_query,
82
79
  version_extras: None,
83
80
  };
84
81