- Notifications
You must be signed in to change notification settings - Fork192
Commitddaa28a
authored
refactor: major database overhaul (#65)
* feat: add BackupModel, PadModel, and UserModel for database schema- Introduced BackupModel to manage backups with relationships to PadModel.- Created PadModel to represent pads with relationships to UserModel and BackupModel.- Added UserModel to handle user data and relationships with PadModel.- Each model includes fields for UUID, timestamps, and relevant data types, utilizing SQLAlchemy for ORM functionality.* feat: introduce base model and refactor existing models for database schema- Added BaseModel to centralize common fields and schema configuration for all models.- Refactored BackupModel, PadModel, and UserModel to inherit from BaseModel, enhancing code reusability.- Updated relationships and added indexing for improved query performance.- Implemented to_dict methods in models for easier data serialization.* feat: implement repository modules for database operations- Added a new repository module for database operations, including UserRepository, PadRepository, and BackupRepository.- Each repository provides methods for creating, retrieving, updating, and deleting records related to users, pads, and backups.- Enhanced modularity and organization of database interactions within the application.* feat: add service modules for user, pad, and backup management- Introduced UserService, PadService, and BackupService to handle business logic related to users, pads, and backups.- Each service includes methods for creating, retrieving, updating, and deleting records, enhancing modularity and organization of the application.- Added an __init__.py file to facilitate service module imports.* feat: implement database module with async support- Added a new database module to manage database connections and session handling using SQLAlchemy with async capabilities.- Introduced init_db function to initialize the database schema and tables.- Created repository and service dependency functions for user, pad, and backup management.- Updated requirements.txt to include psycopg2-binary for PostgreSQL support.* refactor: update SQLAlchemy column types in UserModel- Changed VARCHAR to String for username and email fields in UserModel to align with SQLAlchemy best practices.- This update enhances code consistency and readability within the database model.* refactor: update models to use schema configuration- Refactored BackupModel, PadModel, and UserModel to utilize SCHEMA_NAME for schema configuration, enhancing consistency across models.- Removed the get_schema method from BaseModel to streamline schema handling.- Updated ForeignKey references to align with the new schema approach, improving clarity and maintainability.* refactor: update UUID type usage in BackupModel and PadModel- Replaced custom UUIDType with SQLAlchemy's built-in UUID type for source_id and owner_id fields in BackupModel and PadModel, respectively.- This change enhances code clarity and aligns with SQLAlchemy best practices for UUID handling.* refactor: centralize schema configuration and update database initialization- Introduced SCHEMA_NAME in base_model.py for consistent schema handling across models.- Updated init_db function to use CreateSchema for schema creation, improving clarity and maintainability.- Adjusted imports in models to reflect the new schema configuration, enhancing code organization.* refactor: update UserModel and UserRepository to use UUID for user IDs- Modified UserModel to use SQLAlchemy's UUID type for the primary key, aligning with Keycloak's UUID requirements.- Updated UserRepository's create method to accept a user_id parameter, allowing for explicit user ID assignment during user creation.* feat: enhance user model and repository for additional user attributes- Updated UserModel to include new fields: email_verified, name, given_name, family_name, and roles, allowing for more comprehensive user data management.- Modified UserRepository's create method to accept these new fields, facilitating their inclusion during user creation.- Introduced a new user router to handle user creation and retrieval endpoints, improving API functionality and user management capabilities.* feat: add JWT token handling and user management dependencies- Introduced functions for decoding JWT tokens and retrieving current user information, enhancing authentication flow.- Implemented user creation logic for new users based on token data, improving user management capabilities.- Added an admin role check to enforce access control, ensuring only authorized users can access certain resources.* feat: add TemplatePadModel for managing template pads- Introduced TemplatePadModel to represent the template pads table in the app schema, enhancing the database structure.- Defined columns for name, display_name, and data, ensuring comprehensive data management for template pads.- Added an index on display_name for improved query performance.* feat: add TemplatePad repository, service, and router for template pad management- Introduced TemplatePadRepository for database operations related to template pads, including create, read, update, and delete functionalities.- Added TemplatePadService to encapsulate business logic for template pad management, ensuring data validation and error handling.- Created a new router for template pad endpoints, providing API access for creating, retrieving, updating, and deleting template pads, with admin access control.- Updated existing modules to integrate the new template pad features, enhancing overall application functionality.* feat: add docstrings to user router functions for improved clarity- Added docstrings to the create_user, get_all_users, get_user_info, get_user_count, and get_user functions to clarify their purpose and access restrictions (admin only).- This enhancement improves code documentation and aids in understanding the functionality of user management endpoints.* feat: update requirements for database and file handling- Added python-multipart to requirements.txt to support file uploads in the application.- Ensured psycopg2-binary remains included for PostgreSQL database interactions, maintaining necessary dependencies for backend functionality.* feat: enhance template management and application structure- Added a new function to load templates from JSON files into the database, ensuring templates are created if they do not already exist.- Updated the lifespan of the FastAPI application to include the loading of templates during startup.- Refactored the TemplatePadRepository to update and delete templates using their name instead of ID, improving usability.- Introduced a new router for template pad endpoints, expanding API capabilities for template management.- Added a default template JSON file to provide a starting point for users, enhancing user experience.* feat: refactor authentication and user session management- Introduced UserSession class to unify user session handling, integrating authentication data with user information.- Updated AuthDependency to utilize UserSession, enhancing session validation and user data retrieval.- Replaced SessionData references with UserSession across various routers for consistent user session management.- Added new methods to UserSession for accessing user attributes and caching user data from the database.- Removed deprecated canvas router and introduced a new pad router for managing user pads and backups, improving API structure and functionality.* refactor: streamline user session handling and update API endpoints- Simplified UserSession initialization by decoding the JWT token directly, enhancing security and clarity.- Removed unused to_dict method from UserSession to reduce code complexity.- Updated AuthDependency to eliminate unnecessary user service dependency, streamlining session validation.- Corrected API endpoint in hooks.ts from '/api/user/me' to '/api/users/me' for consistency with routing.- Cleaned up imports in user_router.py to maintain code organization.* refactor: reorganize workspace routing and implement user email uniqueness- Updated import statement in main.py to reflect the new workspace_router file structure.- Modified UserModel to enforce unique email addresses for users, improving data integrity.- Introduced a new workspace_router.py file to manage workspace-related endpoints, replacing the deprecated workspace.py, streamlining the API structure.* refactor: update pad router and API endpoint consistency- Refactored pad router to streamline user pad management, including saving and retrieving canvas data.- Updated user session handling to use user.id instead of user_id for consistency.- Changed API endpoints in frontend hooks to align with new pad routing structure, enhancing clarity and usability.- Removed deprecated default canvas data retrieval function, simplifying the codebase.* refactor: update workspace state management in API and components- Modified WorkspaceState interface to include 'name' and 'id' properties, enhancing workspace identification.- Updated ActionButton and Terminal components to utilize 'name' instead of 'workspace_id' for URL generation, improving consistency across the application.- Ensured all relevant references to workspace identification are aligned with the new state structure, streamlining the codebase.* refactor: remove db.py and reorganize database initialization- Deleted db.py to streamline database management and reduce redundancy.- Updated main.py to directly import init_db from the database module, simplifying the database initialization process.- Introduced auth_router.py to handle authentication routes, enhancing modularity and organization of the codebase.- Ensured dotenv loading is handled in the database module for consistent environment variable access.* refactor: integrate CoderAPI into authentication and workspace management- Added a new dependency function to provide a CoderAPI instance for use in routers.- Updated auth_router to utilize CoderAPI in the callback endpoint, enhancing authentication flow.- Modified workspace_router to incorporate CoderAPI in workspace state retrieval and management functions, improving workspace operations.- Streamlined dependency management across routers for better modularity and code organization.* refactor: migrate CoderAPI configuration to centralized config module- Replaced dotenv loading in CoderAPI with centralized configuration from config.py, enhancing consistency and maintainability.- Updated CoderAPI initialization to use environment variables directly from the config module.- Adjusted error messages to reflect the new configuration approach, improving clarity for required variables.- Streamlined imports across various modules to utilize the new configuration structure, promoting better organization.* refactor: update authentication URL configuration for Keycloak- Replaced direct references to OIDC_CONFIG with environment variables for OIDC_SERVER_URL, OIDC_REALM, OIDC_CLIENT_ID, and OIDC_CLIENT_SECRET, enhancing configuration management.- Improved code clarity and maintainability by centralizing authentication URL generation in the config module.* refactor: enhance JWT token handling and session management- Integrated PyJWKClient for secure JWT verification, improving token validation by using signing keys from JWKS.- Updated UserSession initialization to decode tokens with verification, enhancing security and error handling.- Added a caching mechanism for the JWKS client to optimize performance.- Cleaned up token expiration checks to ensure accurate validation and error reporting.* refactor: enhance Redis connection management and backup functionality- Introduced a Redis connection pool to optimize Redis client management, improving performance and resource utilization.- Updated session management functions to utilize the new Redis connection pool, ensuring efficient access to session data.- Implemented a new method in BackupService to retrieve backups for a user's first pad using a join operation, addressing the N+1 query problem.- Enhanced pad router to create backups conditionally based on time intervals, improving backup efficiency and management.- Streamlined user router to utilize the new Redis client retrieval method, promoting better code organization and maintainability.* refactor: standardize API endpoint paths and enhance datetime handling- Updated API endpoint paths in pad, template pad, and user routers to remove trailing slashes for consistency.- Enhanced datetime handling in BackupService to include timezone information, improving accuracy in backup creation timing.- Adjusted frontend API calls to align with the updated endpoint structure, ensuring seamless integration across the application.* refactor: update CORS middleware configuration- Changed CORS middleware to allow all origins by updating the allow_origins parameter to ["*"], enhancing flexibility for cross-origin requests.* feat: add user synchronization with authentication token data- Implemented a new method in UserService to synchronize user data with information from the authentication token, creating or updating the user as necessary.- Updated the user router to utilize this new synchronization method, enhancing user data management and ensuring consistency between the database and authentication token data.* feat: implement database migration system with Alembic- Added Alembic configuration and migration scripts to facilitate database schema changes.- Implemented a run_migrations function to execute migrations during application startup.- Created migration scripts to transfer data from the old public schema to the new pad_ws schema, ensuring data integrity and consistency.- Updated requirements.txt to include Alembic as a dependency for migration management.1 parente13c2c9 commitddaa28a
File tree
39 files changed
+2504
-571
lines changed- src
- backend
- database
- migrations
- versions
- models
- repository
- service
- routers
- templates
- frontend/src
- api
- pad
- buttons
- containers
39 files changed
+2504
-571
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
13 | 16 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 17 | + | |
22 | 18 | | |
23 | | - | |
| 19 | + | |
24 | 20 | | |
25 | 21 | | |
26 | 22 | | |
| |||
56 | 52 | | |
57 | 53 | | |
58 | 54 | | |
59 | | - | |
| 55 | + | |
60 | 56 | | |
61 | | - | |
| 57 | + | |
62 | 58 | | |
63 | 59 | | |
64 | 60 | | |
| |||
201 | 197 | | |
202 | 198 | | |
203 | 199 | | |
204 | | - | |
| 200 | + | |
205 | 201 | | |
206 | 202 | | |
207 | 203 | | |
| |||
282 | 278 | | |
283 | 279 | | |
284 | 280 | | |
285 | | - | |
| 281 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
| 15 | + | |
12 | 16 | | |
13 | 17 | | |
| 18 | + | |
14 | 19 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
29 | 46 | | |
30 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
31 | 52 | | |
32 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
33 | 71 | | |
34 | 72 | | |
35 | 73 | | |
36 | | - | |
| 74 | + | |
| 75 | + | |
37 | 76 | | |
38 | 77 | | |
39 | 78 | | |
40 | 79 | | |
41 | 80 | | |
42 | 81 | | |
43 | | - | |
| 82 | + | |
| 83 | + | |
44 | 84 | | |
45 | 85 | | |
46 | 86 | | |
47 | 87 | | |
48 | 88 | | |
49 | 89 | | |
50 | 90 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 91 | + | |
| 92 | + | |
54 | 93 | | |
55 | 94 | | |
56 | 95 | | |
57 | | - | |
| 96 | + | |
58 | 97 | | |
59 | | - | |
| 98 | + | |
60 | 99 | | |
61 | | - | |
| 100 | + | |
62 | 101 | | |
63 | 102 | | |
64 | 103 | | |
65 | 104 | | |
66 | 105 | | |
67 | 106 | | |
68 | | - | |
| 107 | + | |
69 | 108 | | |
70 | 109 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | 110 | | |
82 | 111 | | |
83 | 112 | | |
84 | 113 | | |
85 | | - | |
86 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
87 | 117 | | |
88 | | - | |
89 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
90 | 125 | | |
91 | | - | |
| 126 | + | |
| 127 | + | |
92 | 128 | | |
93 | 129 | | |
| 130 | + | |
| 131 | + | |
94 | 132 | | |
95 | 133 | | |
96 | 134 | | |
| |||
115 | 153 | | |
116 | 154 | | |
117 | 155 | | |
118 | | - | |
119 | | - | |
| 156 | + | |
| 157 | + | |
120 | 158 | | |
121 | 159 | | |
122 | 160 | | |
| |||
136 | 174 | | |
137 | 175 | | |
138 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments
Comments
(0)