dmart 0.1.6__tar.gz → 0.1.9__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 (172) hide show
  1. {dmart-0.1.6/dmart.egg-info → dmart-0.1.9}/PKG-INFO +1 -1
  2. dmart-0.1.9/alembic/scripts/calculate_checksums.py +77 -0
  3. dmart-0.1.9/alembic/scripts/migration_f7a4949eed19.py +28 -0
  4. dmart-0.1.9/alembic/versions/0f3d2b1a7c21_add_authz_materialized_views.py +87 -0
  5. dmart-0.1.9/alembic/versions/10d2041b94d4_last_checksum_history.py +62 -0
  6. dmart-0.1.9/alembic/versions/1cf4e1ee3cb8_ext_permission_with_filter_fields_values.py +33 -0
  7. dmart-0.1.9/alembic/versions/26bfe19b49d4_rm_failedloginattempts.py +42 -0
  8. dmart-0.1.9/alembic/versions/3c8bca2219cc_add_otp_table.py +38 -0
  9. dmart-0.1.9/alembic/versions/6675fd9dfe42_remove_unique_from_sessions_table.py +36 -0
  10. dmart-0.1.9/alembic/versions/71bc1df82e6a_adding_user_last_login_at.py +43 -0
  11. dmart-0.1.9/alembic/versions/74288ccbd3b5_initial.py +264 -0
  12. dmart-0.1.9/alembic/versions/7520a89a8467_rm_activesession_table.py +39 -0
  13. dmart-0.1.9/alembic/versions/848b623755a4_make_created_nd_updated_at_required.py +138 -0
  14. dmart-0.1.9/alembic/versions/8640dcbebf85_add_notes_to_users.py +32 -0
  15. dmart-0.1.9/alembic/versions/91c94250232a_adding_fk_on_owner_shortname.py +104 -0
  16. dmart-0.1.9/alembic/versions/98ecd6f56f9a_ext_meta_with_owner_group_shortname.py +66 -0
  17. dmart-0.1.9/alembic/versions/9aae9138c4ef_indexing_created_at_updated_at.py +80 -0
  18. dmart-0.1.9/alembic/versions/b53f916b3f6d_json_to_jsonb.py +492 -0
  19. dmart-0.1.9/alembic/versions/eb5f1ec65156_adding_user_locked_to_device.py +36 -0
  20. dmart-0.1.9/alembic/versions/f7a4949eed19_adding_query_policies_to_meta.py +60 -0
  21. dmart-0.1.9/api/user/model/errors.py +14 -0
  22. dmart-0.1.9/api/user/model/requests.py +165 -0
  23. dmart-0.1.9/api/user/model/responses.py +11 -0
  24. {dmart-0.1.6 → dmart-0.1.9/dmart.egg-info}/PKG-INFO +1 -1
  25. {dmart-0.1.6 → dmart-0.1.9}/dmart.egg-info/SOURCES.txt +43 -0
  26. dmart-0.1.9/plugins/__init__.py +0 -0
  27. dmart-0.1.9/plugins/action_log/__init__.py +0 -0
  28. dmart-0.1.9/plugins/action_log/plugin.py +121 -0
  29. dmart-0.1.9/plugins/admin_notification_sender/__init__.py +0 -0
  30. dmart-0.1.9/plugins/admin_notification_sender/plugin.py +124 -0
  31. dmart-0.1.9/plugins/ldap_manager/__init__.py +0 -0
  32. dmart-0.1.9/plugins/ldap_manager/plugin.py +100 -0
  33. dmart-0.1.9/plugins/local_notification/__init__.py +0 -0
  34. dmart-0.1.9/plugins/local_notification/plugin.py +123 -0
  35. dmart-0.1.9/plugins/realtime_updates_notifier/__init__.py +0 -0
  36. dmart-0.1.9/plugins/realtime_updates_notifier/plugin.py +58 -0
  37. dmart-0.1.9/plugins/redis_db_update/__init__.py +0 -0
  38. dmart-0.1.9/plugins/redis_db_update/plugin.py +188 -0
  39. dmart-0.1.9/plugins/resource_folders_creation/__init__.py +0 -0
  40. dmart-0.1.9/plugins/resource_folders_creation/plugin.py +81 -0
  41. dmart-0.1.9/plugins/system_notification_sender/__init__.py +0 -0
  42. dmart-0.1.9/plugins/system_notification_sender/plugin.py +188 -0
  43. dmart-0.1.9/plugins/update_access_controls/__init__.py +0 -0
  44. dmart-0.1.9/plugins/update_access_controls/plugin.py +9 -0
  45. dmart-0.1.9/pytests/__init__.py +0 -0
  46. {dmart-0.1.6 → dmart-0.1.9}/schema_modulate.py +1 -1
  47. {dmart-0.1.6 → dmart-0.1.9}/setup.py +1 -1
  48. dmart-0.1.9/utils/__init__.py +0 -0
  49. {dmart-0.1.6 → dmart-0.1.9}/.ruff.toml +0 -0
  50. {dmart-0.1.6 → dmart-0.1.9}/MANIFEST.in +0 -0
  51. {dmart-0.1.6 → dmart-0.1.9}/alembic/__init__.py +0 -0
  52. {dmart-0.1.6 → dmart-0.1.9}/alembic/env.py +0 -0
  53. {dmart-0.1.6/api → dmart-0.1.9/alembic/scripts}/__init__.py +0 -0
  54. {dmart-0.1.6/api/info → dmart-0.1.9/alembic/versions}/__init__.py +0 -0
  55. {dmart-0.1.6/api/managed → dmart-0.1.9/api}/__init__.py +0 -0
  56. {dmart-0.1.6/api/public → dmart-0.1.9/api/info}/__init__.py +0 -0
  57. {dmart-0.1.6 → dmart-0.1.9}/api/info/router.py +0 -0
  58. {dmart-0.1.6/api/qr → dmart-0.1.9/api/managed}/__init__.py +0 -0
  59. {dmart-0.1.6 → dmart-0.1.9}/api/managed/router.py +0 -0
  60. {dmart-0.1.6 → dmart-0.1.9}/api/managed/utils.py +0 -0
  61. {dmart-0.1.6/api/user → dmart-0.1.9/api/public}/__init__.py +0 -0
  62. {dmart-0.1.6 → dmart-0.1.9}/api/public/router.py +0 -0
  63. {dmart-0.1.6/config → dmart-0.1.9/api/qr}/__init__.py +0 -0
  64. {dmart-0.1.6 → dmart-0.1.9}/api/qr/router.py +0 -0
  65. {dmart-0.1.6/data_adapters → dmart-0.1.9/api/user}/__init__.py +0 -0
  66. {dmart-0.1.6/data_adapters/file → dmart-0.1.9/api/user/model}/__init__.py +0 -0
  67. {dmart-0.1.6 → dmart-0.1.9}/api/user/router.py +0 -0
  68. {dmart-0.1.6 → dmart-0.1.9}/api/user/service.py +0 -0
  69. {dmart-0.1.6 → dmart-0.1.9}/bundler.py +0 -0
  70. {dmart-0.1.6/data_adapters/sql → dmart-0.1.9/config}/__init__.py +0 -0
  71. {dmart-0.1.6 → dmart-0.1.9}/config/channels.json +0 -0
  72. {dmart-0.1.6 → dmart-0.1.9}/config/notification.json +0 -0
  73. {dmart-0.1.6 → dmart-0.1.9}/config.env.sample +0 -0
  74. {dmart-0.1.6 → dmart-0.1.9}/curl.sh +0 -0
  75. {dmart-0.1.6/languages → dmart-0.1.9/data_adapters}/__init__.py +0 -0
  76. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/adapter.py +0 -0
  77. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/base_data_adapter.py +0 -0
  78. {dmart-0.1.6/models → dmart-0.1.9/data_adapters/file}/__init__.py +0 -0
  79. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/adapter.py +0 -0
  80. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/adapter_helpers.py +0 -0
  81. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/archive.py +0 -0
  82. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/create_index.py +0 -0
  83. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/create_users_folders.py +0 -0
  84. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/custom_validations.py +0 -0
  85. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/drop_index.py +0 -0
  86. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/health_check.py +0 -0
  87. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/file/redis_services.py +0 -0
  88. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/helpers.py +0 -0
  89. {dmart-0.1.6/plugins → dmart-0.1.9/data_adapters/sql}/__init__.py +0 -0
  90. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/adapter.py +0 -0
  91. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/adapter_helpers.py +0 -0
  92. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/create_tables.py +0 -0
  93. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/create_users_folders.py +0 -0
  94. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/db_to_json_migration.py +0 -0
  95. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/health_check_sql.py +0 -0
  96. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/json_to_db_migration.py +0 -0
  97. {dmart-0.1.6 → dmart-0.1.9}/data_adapters/sql/update_query_policies.py +0 -0
  98. {dmart-0.1.6 → dmart-0.1.9}/data_generator.py +0 -0
  99. {dmart-0.1.6 → dmart-0.1.9}/dmart.egg-info/dependency_links.txt +0 -0
  100. {dmart-0.1.6 → dmart-0.1.9}/dmart.egg-info/entry_points.txt +0 -0
  101. {dmart-0.1.6 → dmart-0.1.9}/dmart.egg-info/requires.txt +0 -0
  102. {dmart-0.1.6 → dmart-0.1.9}/dmart.egg-info/top_level.txt +0 -0
  103. {dmart-0.1.6 → dmart-0.1.9}/dmart.py +0 -0
  104. {dmart-0.1.6 → dmart-0.1.9}/get_settings.py +0 -0
  105. {dmart-0.1.6 → dmart-0.1.9}/hypercorn_config.toml +0 -0
  106. {dmart-0.1.6 → dmart-0.1.9}/info.json +0 -0
  107. {dmart-0.1.6/pytests → dmart-0.1.9/languages}/__init__.py +0 -0
  108. {dmart-0.1.6 → dmart-0.1.9}/languages/arabic.json +0 -0
  109. {dmart-0.1.6 → dmart-0.1.9}/languages/english.json +0 -0
  110. {dmart-0.1.6 → dmart-0.1.9}/languages/kurdish.json +0 -0
  111. {dmart-0.1.6 → dmart-0.1.9}/languages/loader.py +0 -0
  112. {dmart-0.1.6 → dmart-0.1.9}/login_creds.sh +0 -0
  113. {dmart-0.1.6 → dmart-0.1.9}/login_creds.sh.sample +0 -0
  114. {dmart-0.1.6 → dmart-0.1.9}/main.py +0 -0
  115. {dmart-0.1.6 → dmart-0.1.9}/manifest.sh +0 -0
  116. {dmart-0.1.6 → dmart-0.1.9}/migrate.py +0 -0
  117. {dmart-0.1.6/utils → dmart-0.1.9/models}/__init__.py +0 -0
  118. {dmart-0.1.6 → dmart-0.1.9}/models/api.py +0 -0
  119. {dmart-0.1.6 → dmart-0.1.9}/models/core.py +0 -0
  120. {dmart-0.1.6 → dmart-0.1.9}/models/enums.py +0 -0
  121. {dmart-0.1.6 → dmart-0.1.9}/password_gen.py +0 -0
  122. {dmart-0.1.6 → dmart-0.1.9}/publish.sh +0 -0
  123. {dmart-0.1.6 → dmart-0.1.9}/pylint.sh +0 -0
  124. {dmart-0.1.6 → dmart-0.1.9}/pyrightconfig.json +0 -0
  125. {dmart-0.1.6 → dmart-0.1.9}/pytests/api_user_models_erros_test.py +0 -0
  126. {dmart-0.1.6 → dmart-0.1.9}/pytests/api_user_models_requests_test.py +0 -0
  127. {dmart-0.1.6 → dmart-0.1.9}/pytests/archive_test.py +0 -0
  128. {dmart-0.1.6 → dmart-0.1.9}/pytests/base_test.py +0 -0
  129. {dmart-0.1.6 → dmart-0.1.9}/pytests/get_settings_test.py +0 -0
  130. {dmart-0.1.6 → dmart-0.1.9}/pytests/json_to_db_migration_test.py +0 -0
  131. {dmart-0.1.6 → dmart-0.1.9}/pytests/service_test.py +0 -0
  132. {dmart-0.1.6 → dmart-0.1.9}/pytests/test_info.py +0 -0
  133. {dmart-0.1.6 → dmart-0.1.9}/pytests/test_status.py +0 -0
  134. {dmart-0.1.6 → dmart-0.1.9}/redis_connections.sh +0 -0
  135. {dmart-0.1.6 → dmart-0.1.9}/reload.sh +0 -0
  136. {dmart-0.1.6 → dmart-0.1.9}/requirements/core.txt +0 -0
  137. {dmart-0.1.6 → dmart-0.1.9}/requirements/extra.txt +0 -0
  138. {dmart-0.1.6 → dmart-0.1.9}/requirements/plugins.txt +0 -0
  139. {dmart-0.1.6 → dmart-0.1.9}/requirements/test.txt +0 -0
  140. {dmart-0.1.6 → dmart-0.1.9}/run.sh +0 -0
  141. {dmart-0.1.6 → dmart-0.1.9}/run_notification_campaign.py +0 -0
  142. {dmart-0.1.6 → dmart-0.1.9}/scheduled_notification_handler.py +0 -0
  143. {dmart-0.1.6 → dmart-0.1.9}/schema_migration.py +0 -0
  144. {dmart-0.1.6 → dmart-0.1.9}/set_admin_passwd.py +0 -0
  145. {dmart-0.1.6 → dmart-0.1.9}/setup.cfg +0 -0
  146. {dmart-0.1.6 → dmart-0.1.9}/sync.py +0 -0
  147. {dmart-0.1.6 → dmart-0.1.9}/utils/access_control.py +0 -0
  148. {dmart-0.1.6 → dmart-0.1.9}/utils/async_request.py +0 -0
  149. {dmart-0.1.6 → dmart-0.1.9}/utils/exporter.py +0 -0
  150. {dmart-0.1.6 → dmart-0.1.9}/utils/firebase_notifier.py +0 -0
  151. {dmart-0.1.6 → dmart-0.1.9}/utils/generate_email.py +0 -0
  152. {dmart-0.1.6 → dmart-0.1.9}/utils/helpers.py +0 -0
  153. {dmart-0.1.6 → dmart-0.1.9}/utils/hypercorn_config.py +0 -0
  154. {dmart-0.1.6 → dmart-0.1.9}/utils/internal_error_code.py +0 -0
  155. {dmart-0.1.6 → dmart-0.1.9}/utils/jwt.py +0 -0
  156. {dmart-0.1.6 → dmart-0.1.9}/utils/logger.py +0 -0
  157. {dmart-0.1.6 → dmart-0.1.9}/utils/middleware.py +0 -0
  158. {dmart-0.1.6 → dmart-0.1.9}/utils/notification.py +0 -0
  159. {dmart-0.1.6 → dmart-0.1.9}/utils/password_hashing.py +0 -0
  160. {dmart-0.1.6 → dmart-0.1.9}/utils/plugin_manager.py +0 -0
  161. {dmart-0.1.6 → dmart-0.1.9}/utils/query_policies_helper.py +0 -0
  162. {dmart-0.1.6 → dmart-0.1.9}/utils/regex.py +0 -0
  163. {dmart-0.1.6 → dmart-0.1.9}/utils/repository.py +0 -0
  164. {dmart-0.1.6 → dmart-0.1.9}/utils/router_helper.py +0 -0
  165. {dmart-0.1.6 → dmart-0.1.9}/utils/settings.py +0 -0
  166. {dmart-0.1.6 → dmart-0.1.9}/utils/sms_notifier.py +0 -0
  167. {dmart-0.1.6 → dmart-0.1.9}/utils/social_sso.py +0 -0
  168. {dmart-0.1.6 → dmart-0.1.9}/utils/templates/activation.html.j2 +0 -0
  169. {dmart-0.1.6 → dmart-0.1.9}/utils/templates/reminder.html.j2 +0 -0
  170. {dmart-0.1.6 → dmart-0.1.9}/utils/ticket_sys_utils.py +0 -0
  171. {dmart-0.1.6 → dmart-0.1.9}/utils/web_notifier.py +0 -0
  172. {dmart-0.1.6 → dmart-0.1.9}/websocket.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dmart
3
- Version: 0.1.6
3
+ Version: 0.1.9
4
4
  Requires-Python: >=3.10
5
5
  Requires-Dist: fastapi
6
6
  Requires-Dist: pydantic
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env -S BACKEND_ENV=config.env python3
2
+ import asyncio
3
+ import hashlib
4
+ import json
5
+ from datetime import datetime
6
+ from sqlalchemy import select, update, func
7
+ from data_adapters.sql.adapter import SQLAdapter
8
+ from data_adapters.sql.create_tables import Histories, Users, Entries, Spaces, Roles, Permissions
9
+
10
+ def flatten_dict(d, parent_key='', sep='.'):
11
+ items = []
12
+ for k, v in d.items():
13
+ new_key = parent_key + sep + k if parent_key else k
14
+ if isinstance(v, dict):
15
+ items.extend(flatten_dict(v, new_key, sep=sep).items())
16
+ else:
17
+ items.append((new_key, v))
18
+ return dict(items)
19
+
20
+ async def migrate_checksums():
21
+ db = SQLAdapter()
22
+
23
+ async with db.get_session() as session:
24
+ resource_tables = [Users, Permissions, Roles, Entries, Spaces]
25
+
26
+ for resource_table in resource_tables:
27
+ print(f"Processing table: {resource_table.__tablename__}")
28
+
29
+ # Fetch all records from the current table
30
+ stmt = select(resource_table)
31
+ result = await session.execute(stmt)
32
+ records = result.scalars().all()
33
+
34
+ print(f"Found {len(records)} records in {resource_table.__tablename__}")
35
+
36
+ batch_size = 1000
37
+ for i in range(0, len(records), batch_size):
38
+ batch = records[i:i + batch_size]
39
+ print(f"Processing batch {i // batch_size + 1} ({len(batch)} records) for {resource_table.__tablename__}...")
40
+
41
+ for record in batch:
42
+ try:
43
+ async with session.begin_nested():
44
+ record_dict = record.model_dump()
45
+ flat_record = flatten_dict(record_dict)
46
+
47
+ new_version_json = json.dumps(flat_record, sort_keys=True, default=str)
48
+ new_checksum = hashlib.sha1(new_version_json.encode()).hexdigest()
49
+
50
+ record.last_checksum_history = new_checksum
51
+ session.add(record)
52
+
53
+ history_stmt = select(Histories).where(
54
+ Histories.space_name == record.space_name,
55
+ Histories.subpath == record.subpath,
56
+ Histories.shortname == record.shortname
57
+ ).order_by(Histories.timestamp.desc()).limit(1)
58
+
59
+ history_result = await session.execute(history_stmt)
60
+ latest_history = history_result.scalars().first()
61
+
62
+ if latest_history:
63
+ latest_history.last_checksum_history = new_checksum
64
+ session.add(latest_history)
65
+ else:
66
+ print(f"No history found for {record.space_name}/{record.subpath}/{record.shortname}")
67
+
68
+ except Exception as e:
69
+ print(f"Error processing {record.space_name}/{record.shortname} in {resource_table.__tablename__}: {e}")
70
+
71
+ await session.commit()
72
+ print(f"Batch {i // batch_size + 1} committed for {resource_table.__tablename__}.")
73
+
74
+ print("Migration completed.")
75
+
76
+ if __name__ == "__main__":
77
+ asyncio.run(migrate_checksums())
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env -S BACKEND_ENV=config.env python3
2
+ from sqlmodel import select
3
+
4
+ from data_adapters.sql.adapter import SQLAdapter
5
+ from data_adapters.sql.create_tables import Entries, Permissions, Roles, Spaces, Users
6
+ from utils.query_policies_helper import generate_query_policies
7
+
8
+
9
+ print("[INFO] [dmart.script] Performing post-upgrade data migration (calc-query-policies)")
10
+ with SQLAdapter().get_session() as session:
11
+ for table in [Entries, Permissions, Roles, Spaces, Users]:
12
+ print(f"[INFO] [dmart.script] Processing table: {table}")
13
+ records = session.exec(select(table)).all()
14
+ print(f"[INFO] [dmart.script] Processing {len(records)} records")
15
+ for record in records:
16
+ if not record.query_policies:
17
+ record.query_policies = generate_query_policies(
18
+ space_name=record.space_name,
19
+ subpath=f"{record.subpath}/{record.shortname}" if record.resource_type == 'folder' else record.subpath,
20
+ resource_type=record.resource_type,
21
+ is_active=record.is_active,
22
+ owner_shortname=record.owner_shortname,
23
+ owner_group_shortname= record.owner_group_shortname if hasattr(record, 'owner_group_shortname') else "",
24
+ )
25
+ session.add(record)
26
+ print(".", end="\r")
27
+ session.commit()
28
+ print("[INFO] [dmart.script] Post-upgrade data migration completed")
@@ -0,0 +1,87 @@
1
+ """add authz materialized views and meta table
2
+
3
+ Revision ID: 0f3d2b1a7c21
4
+ Revises: 98ecd6f56f9a
5
+ Create Date: 2025-09-25 07:40:00.000000
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+
13
+ # revision identifiers, used by Alembic.
14
+ revision: str = '0f3d2b1a7c21'
15
+ down_revision: Union[str, None] = '98ecd6f56f9a'
16
+ branch_labels: Union[str, Sequence[str], None] = None
17
+ depends_on: Union[str, Sequence[str], None] = None
18
+
19
+
20
+ def upgrade() -> None:
21
+ # Create meta table to track MV refresh times
22
+ op.execute(
23
+ """
24
+ CREATE TABLE IF NOT EXISTS authz_mv_meta (
25
+ id INT PRIMARY KEY,
26
+ last_source_ts TIMESTAMPTZ,
27
+ refreshed_at TIMESTAMPTZ
28
+ )
29
+ """
30
+ )
31
+ # Seed a single row with id=1 if not exists
32
+ op.execute(
33
+ """
34
+ INSERT INTO authz_mv_meta(id, last_source_ts, refreshed_at)
35
+ VALUES (1, to_timestamp(0), now())
36
+ ON CONFLICT (id) DO NOTHING
37
+ """
38
+ )
39
+
40
+ # Create materialized view for user->roles
41
+ op.execute(
42
+ """
43
+ CREATE MATERIALIZED VIEW IF NOT EXISTS mv_user_roles AS
44
+ SELECT u.shortname AS user_shortname,
45
+ r.shortname AS role_shortname
46
+ FROM users u
47
+ JOIN LATERAL jsonb_array_elements_text(u.roles) AS role_name ON TRUE
48
+ JOIN roles r ON r.shortname = role_name
49
+ """
50
+ )
51
+ op.execute(
52
+ """
53
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_mv_user_roles_unique
54
+ ON mv_user_roles (user_shortname, role_shortname)
55
+ """
56
+ )
57
+
58
+ # Create materialized view for role->permissions
59
+ op.execute(
60
+ """
61
+ CREATE MATERIALIZED VIEW IF NOT EXISTS mv_role_permissions AS
62
+ SELECT r.shortname AS role_shortname,
63
+ p.shortname AS permission_shortname
64
+ FROM roles r
65
+ JOIN LATERAL jsonb_array_elements_text(r.permissions) AS perm_name ON TRUE
66
+ JOIN permissions p ON p.shortname = perm_name
67
+ """
68
+ )
69
+ op.execute(
70
+ """
71
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_mv_role_permissions_unique
72
+ ON mv_role_permissions (role_shortname, permission_shortname)
73
+ """
74
+ )
75
+
76
+
77
+ def downgrade() -> None:
78
+ # Drop unique indexes first
79
+ op.execute("DROP INDEX IF EXISTS idx_mv_role_permissions_unique")
80
+ op.execute("DROP INDEX IF EXISTS idx_mv_user_roles_unique")
81
+
82
+ # Drop materialized views
83
+ op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_role_permissions")
84
+ op.execute("DROP MATERIALIZED VIEW IF EXISTS mv_user_roles")
85
+
86
+ # Drop meta table
87
+ op.execute("DROP TABLE IF EXISTS authz_mv_meta")
@@ -0,0 +1,62 @@
1
+ """last_checksum_history
2
+
3
+ Revision ID: 10d2041b94d4
4
+ Revises: eb5f1ec65156
5
+ Create Date: 2026-01-11 16:56:50.108607
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+ import sqlmodel.sql.sqltypes
14
+
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = '10d2041b94d4'
18
+ down_revision: Union[str, None] = 'eb5f1ec65156'
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = None
21
+
22
+
23
+ def upgrade() -> None:
24
+ # ### commands auto generated by Alembic - please adjust! ###
25
+ with op.batch_alter_table('users', schema=None) as batch_op:
26
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
27
+ with op.batch_alter_table('permissions', schema=None) as batch_op:
28
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
29
+ with op.batch_alter_table('roles', schema=None) as batch_op:
30
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
31
+ with op.batch_alter_table('entries', schema=None) as batch_op:
32
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
33
+ with op.batch_alter_table('spaces', schema=None) as batch_op:
34
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
35
+ with op.batch_alter_table('histories', schema=None) as batch_op:
36
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
37
+ with op.batch_alter_table('attachments', schema=None) as batch_op:
38
+ batch_op.add_column(sa.Column('last_checksum_history', sqlmodel.sql.sqltypes.AutoString(), nullable=True))
39
+
40
+
41
+ # ### end Alembic commands ###
42
+
43
+
44
+ def downgrade() -> None:
45
+ # ### commands auto generated by Alembic - please adjust! ###
46
+ with op.batch_alter_table('users', schema=None) as batch_op:
47
+ batch_op.drop_column('last_checksum_history')
48
+ with op.batch_alter_table('permissions', schema=None) as batch_op:
49
+ batch_op.drop_column('last_checksum_history')
50
+ with op.batch_alter_table('roles', schema=None) as batch_op:
51
+ batch_op.drop_column('last_checksum_history')
52
+ with op.batch_alter_table('entries', schema=None) as batch_op:
53
+ batch_op.drop_column('last_checksum_history')
54
+ with op.batch_alter_table('spaces', schema=None) as batch_op:
55
+ batch_op.drop_column('last_checksum_history')
56
+ with op.batch_alter_table('histories', schema=None) as batch_op:
57
+ batch_op.drop_column('last_checksum_history')
58
+ with op.batch_alter_table('attachments', schema=None) as batch_op:
59
+ batch_op.drop_column('last_checksum_history')
60
+
61
+
62
+ # ### end Alembic commands ###
@@ -0,0 +1,33 @@
1
+ """ext permission with filter_fields_values
2
+
3
+ Revision ID: 1cf4e1ee3cb8
4
+ Revises: 3c8bca2219cc
5
+ Create Date: 2025-09-18 10:37:55.573932
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+ import sqlmodel.sql.sqltypes
14
+ from sqlalchemy.dialects import postgresql
15
+
16
+
17
+ # revision identifiers, used by Alembic.
18
+ revision: str = '1cf4e1ee3cb8'
19
+ down_revision: Union[str, None] = '3c8bca2219cc'
20
+ branch_labels: Union[str, Sequence[str], None] = None
21
+ depends_on: Union[str, Sequence[str], None] = None
22
+
23
+
24
+ def upgrade() -> None:
25
+ with op.batch_alter_table('permissions', schema=None) as batch_op:
26
+ batch_op.add_column(
27
+ sa.Column('filter_fields_values', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
28
+ )
29
+
30
+
31
+ def downgrade() -> None:
32
+ with op.batch_alter_table('permissions', schema=None) as batch_op:
33
+ batch_op.drop_column('filter_fields_values')
@@ -0,0 +1,42 @@
1
+ """rm FailedLoginAttempts
2
+
3
+ Revision ID: 26bfe19b49d4
4
+ Revises: 74288ccbd3b5
5
+ Create Date: 2024-11-25 15:40:46.757073
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ from sqlalchemy.dialects import postgresql
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = '26bfe19b49d4'
16
+ down_revision: Union[str, None] = '74288ccbd3b5'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ # ### commands auto generated by Alembic - please adjust! ###
23
+ op.drop_table('failedloginattempts')
24
+ with op.batch_alter_table('users', schema=None) as batch_op:
25
+ batch_op.add_column(sa.Column('attempt_count', sa.Integer(), nullable=True))
26
+
27
+ # ### end Alembic commands ###
28
+
29
+
30
+ def downgrade() -> None:
31
+ # ### commands auto generated by Alembic - please adjust! ###
32
+ with op.batch_alter_table('users', schema=None) as batch_op:
33
+ batch_op.drop_column('attempt_count')
34
+
35
+ op.create_table('failedloginattempts',
36
+ sa.Column('uuid', sa.UUID(), autoincrement=False, nullable=False),
37
+ sa.Column('shortname', sa.VARCHAR(), autoincrement=False, nullable=False),
38
+ sa.Column('attempt_count', sa.INTEGER(), autoincrement=False, nullable=False),
39
+ sa.Column('timestamp', postgresql.TIMESTAMP(), autoincrement=False, nullable=False),
40
+ sa.PrimaryKeyConstraint('uuid', name='failedloginattempts_pkey')
41
+ )
42
+ # ### end Alembic commands ###
@@ -0,0 +1,38 @@
1
+ """add otp table
2
+
3
+ Revision ID: 3c8bca2219cc
4
+ Revises: 9aae9138c4ef
5
+ Create Date: 2025-04-27 15:28:53.704608
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+ import sqlmodel.sql.sqltypes
14
+ from sqlalchemy.dialects import postgresql
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = '3c8bca2219cc'
18
+ down_revision: Union[str, None] = '9aae9138c4ef'
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = None
21
+
22
+
23
+ def upgrade() -> None:
24
+ # ### commands auto generated by Alembic - please adjust! ###
25
+ op.execute("CREATE EXTENSION IF NOT EXISTS hstore")
26
+ op.create_table('otp',
27
+ sa.Column('key', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
28
+ sa.Column('value', postgresql.HSTORE(text_type=sa.Text()), nullable=False),
29
+ sa.Column('timestamp', sa.DateTime(), nullable=False),
30
+ sa.PrimaryKeyConstraint('key')
31
+ )
32
+ # ### end Alembic commands ###
33
+
34
+
35
+ def downgrade() -> None:
36
+ # ### commands auto generated by Alembic - please adjust! ###
37
+ op.drop_table('otp')
38
+ # ### end Alembic commands ###
@@ -0,0 +1,36 @@
1
+ """remove unique from Sessions table
2
+
3
+ Revision ID: 6675fd9dfe42
4
+ Revises: 7520a89a8467
5
+ Create Date: 2024-12-29 16:26:29.871839
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+ import sqlmodel.sql.sqltypes
14
+
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = '6675fd9dfe42'
18
+ down_revision: Union[str, None] = '7520a89a8467'
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = None
21
+
22
+
23
+ def upgrade() -> None:
24
+ # ### commands auto generated by Alembic - please adjust! ###
25
+ with op.batch_alter_table('sessions', schema=None) as batch_op:
26
+ batch_op.drop_constraint('sessions_shortname_key', type_='unique')
27
+
28
+ # ### end Alembic commands ###
29
+
30
+
31
+ def downgrade() -> None:
32
+ # ### commands auto generated by Alembic - please adjust! ###
33
+ with op.batch_alter_table('sessions', schema=None) as batch_op:
34
+ batch_op.create_unique_constraint('sessions_shortname_key', ['shortname'])
35
+
36
+ # ### end Alembic commands ###
@@ -0,0 +1,43 @@
1
+ """adding user.last_login_at
2
+
3
+ Revision ID: 71bc1df82e6a
4
+ Revises: 0f3d2b1a7c21
5
+ Create Date: 2025-11-16 19:40:40.794367
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ import sqlmodel
13
+ import sqlmodel.sql.sqltypes
14
+ from sqlalchemy.dialects import postgresql
15
+
16
+ # revision identifiers, used by Alembic.
17
+ revision: str = '71bc1df82e6a'
18
+ down_revision: Union[str, None] = '0f3d2b1a7c21'
19
+ branch_labels: Union[str, Sequence[str], None] = None
20
+ depends_on: Union[str, Sequence[str], None] = None
21
+
22
+
23
+ def upgrade() -> None:
24
+ # ### commands auto generated by Alembic - please adjust! ###
25
+ op.drop_table('authz_mv_meta')
26
+ with op.batch_alter_table('users', schema=None) as batch_op:
27
+ batch_op.add_column(sa.Column('last_login', postgresql.JSONB(astext_type=sa.Text()), nullable=True))
28
+
29
+ # ### end Alembic commands ###
30
+
31
+
32
+ def downgrade() -> None:
33
+ # ### commands auto generated by Alembic - please adjust! ###
34
+ with op.batch_alter_table('users', schema=None) as batch_op:
35
+ batch_op.drop_column('last_login')
36
+
37
+ op.create_table('authz_mv_meta',
38
+ sa.Column('id', sa.INTEGER(), autoincrement=False, nullable=False),
39
+ sa.Column('last_source_ts', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
40
+ sa.Column('refreshed_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
41
+ sa.PrimaryKeyConstraint('id', name=op.f('authz_mv_meta_pkey'))
42
+ )
43
+ # ### end Alembic commands ###