11import uuid
22from django .db import models
3+ from pgvector .django import VectorField
34
45
5- class DatabaseConnection (models .Model ):
6- id = models .UUIDField (primary_key = True , default = uuid .uuid4 , editable = False )
7- name = models .CharField (max_length = 255 , unique = True )
8- host = models .CharField (max_length = 255 )
9- port = models .IntegerField (default = 5432 )
10- database = models .CharField (max_length = 255 )
11- username = models .CharField (max_length = 255 )
12- password = models .CharField (max_length = 255 )
13- created_at = models .DateTimeField (auto_now_add = True )
14- updated_at = models .DateTimeField (auto_now = True )
15- is_active = models .BooleanField (default = True )
16-
17- class Meta :
18- db_table = 'database_connections'
19- ordering = ['-created_at' ]
20-
21- def __str__ (self ):
22- return self .name
236
24- def get_connection_string (self ):
25- return f"postgresql://{ self .username } :{ self .password } @{ self .host } :{ self .port } /{ self .database } "
26-
27-
28- class SchemaDocument (models .Model ):
29- id = models .UUIDField (primary_key = True , default = uuid .uuid4 , editable = False )
30- connection = models .ForeignKey (DatabaseConnection , on_delete = models .CASCADE , related_name = 'documents' )
31- name = models .CharField (max_length = 255 )
32- content = models .TextField ()
33- embeddings = models .TextField (blank = True , null = True )
34- uploaded_at = models .DateTimeField (auto_now_add = True )
35-
36- class Meta :
37- db_table = 'schema_documents'
38- ordering = ['-uploaded_at' ]
39-
40- def __str__ (self ):
41- return self .name
427
438
449class QueryHistory (models .Model ):
4510 id = models .UUIDField (primary_key = True , default = uuid .uuid4 , editable = False )
46- connection = models .ForeignKey (DatabaseConnection , on_delete = models .CASCADE , related_name = 'queries' )
4711 natural_language = models .TextField ()
4812 generated_sql = models .TextField ()
4913 executed_sql = models .TextField (blank = True , null = True )
@@ -56,4 +20,4 @@ class Meta:
5620 ordering = ['-created_at' ]
5721
5822 def __str__ (self ):
59- return f"{ self .natural_language [:50 ]} ... - { self .created_at } "
23+ return f"{ self .natural_language [:50 ]} ... - { self .created_at } "
0 commit comments