
    LKi%              
          S SK r S SKJr  S SKJrJr  S SKJr  S SKrS SK	r	S SK
JrJr  S SKJr  S SKJrJr  S SKJrJrJr   " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\R@                  " S5      r!S\"S\"S\S\4S  jr#S!\\   S"\\   S\\   4S# jr$ S)S\S$\"S%\"S\\   4S& jjr%S'\S%\"S\4S( jr&g)*    N)Sequence)	TypedDictNotRequired)Traversable)SqlDBCursor)abstractmethod)SystemSettings)OpenTelemetryClientOpenTelemetryGranularitytrace_methodc                   N    \ rS rSr% \\   \S'   \\S'   \\S'   \\S'   \\S'   Sr	g)	MigrationFile   pathdirfilenameversionscope N)
__name__
__module____qualname____firstlineno__r   r   __annotations__strint__static_attributes__r       X/var/www/html/dynamic-report/venv/lib/python3.13/site-packages/chromadb/db/migrations.pyr   r      s!    
k
""	HMLJr    r   c                   *    \ rS rSr% \\S'   \\S'   Srg)	Migration   hashsqlr   N)r   r   r   r   r   r   r   r   r    r!   r#   r#      s    
I	Hr    r#   c                   ,   ^  \ rS rSrSU 4S jjrSrU =r$ )UninitializedMigrationsError   c                 $   > [         TU ]  S5        g )Nz$Migrations have not been initializedsuper__init__)self	__class__s    r!   r-   %UninitializedMigrationsError.__init__   s    ?@r    r   returnN)r   r   r   r   r-   r   __classcell__r/   s   @r!   r(   r(      s    A Ar    r(   c                   4   ^  \ rS rSrS\S\4U 4S jjrSrU =r$ )UnappliedMigrationsError#   r   r   c                 H   > Xl         X l        [        TU ]  SU SU 35        g )NzUnapplied migrations in z, starting with version )r   r   r,   r-   )r.   r   r   r/   s      r!   r-   !UnappliedMigrationsError.__init__$   s+    &se+CG9M	
r    r   r   	r   r   r   r   r   r   r-   r   r3   r4   s   @r!   r6   r6   #   s    
C 
# 
 
r    r6   c                   8   ^  \ rS rSrS\S\S\4U 4S jjrSrU =r$ )InconsistentVersionError,   r   
db_versionsource_versionc                 F   > [         TU ]  SU S3SU SU S3-   S-   5        g )Nz#Inconsistent migration versions in :zdb version was z, source version was .zH Has the migration sequence been modified since being applied to the DB?r+   )r.   r   r?   r@   r/   s       r!   r-   !InconsistentVersionError.__init__-   s@    1#a8
|+@@PPQRSXY	
r    r   r;   r4   s   @r!   r=   r=   ,   s"    
C 
S 
# 
 
r    r=   c                   8   ^  \ rS rSrS\S\S\4U 4S jjrSrU =r$ )InconsistentHashError5   r   db_hashsource_hashc                 F   > [         TU ]  SU S3SU SU S3-   S-   5        g )NzInconsistent hashes in rB   zdb hash was z, source has was rC   z? Was the migration file modified after being applied to the DB?r+   )r.   r   rH   rI   r/   s       r!   r-   InconsistentHashError.__init__6   s>    %dV1-WI%6{m1EFOP	
r    r   r   r   r   r   r   r-   r   r3   r4   s   @r!   rF   rF   5   s"    
S 
3 
S 
 
r    rF   c                   0   ^  \ rS rSrS\4U 4S jjrSrU =r$ )InvalidHashError>   algc                 *   > [         TU ]  SU 35        g )Nz"Invalid hash algorithm specified: r+   )r.   rP   r/   s     r!   r-   InvalidHashError.__init__?   s    =cUCDr    r   rL   r4   s   @r!   rN   rN   >   s    EC E Er    rN   c                       \ rS rSrSrg)InvalidMigrationFilenameC   r   N)r   r   r   r   r   r   r    r!   rT   rT   C   s    r    rT   c                   h  ^  \ rS rSr% Sr\\S'   S\SS4U 4S jjr\	\
S\4S j5       5       r\
S\\   4S	 j5       r\
SS
 j5       r\
S\4S j5       r\
S\S\\   4S j5       r\
S\S\SS4S j5       rSS jr\" S\R4                  5      SS j5       r\" S\R4                  5      SS j5       rSrU =r$ )MigratableDBG   a}  Simple base class for databases which support basic migrations.

Migrations are SQL files stored as package resources and accessed via
importlib_resources.

All migrations in the same directory are assumed to be dependent on previous
migrations in the same directory, where "previous" is defined on lexographical
ordering of filenames.

Migrations have a ascending numeric version number and a hash of the file contents.
When migrations are applied, the hashes of previous migrations are checked to ensure
that the database is consistent with the source repository. If they are not, an
error is thrown and no migrations will be applied.

Migration files must follow the naming convention:
<version>.<description>.<scope>.sql, where <version> is a 5-digit zero-padded
integer, <description> is a short textual description, and <scope> is a short string
identifying the database implementation.
	_settingssystemr2   Nc                 z   > UR                   U l        UR                  [        5      U l        [
        TU ]  U5        g )N)settingsrY   requirer   _opentelemetry_clientr,   r-   )r.   rZ   r/   s     r!   r-   MigratableDB.__init__^   s-    %+^^4G%H" r    c                      g)zFThe database implementation to use for migrations (e.g, sqlite, pgsql)Nr   r   r    r!   migration_scopeMigratableDB.migration_scopec        	r    c                     g)zQDirectories containing the migration sequences that should be applied to this
DB.Nr   r.   s    r!   migration_dirsMigratableDB.migration_dirsi   rc   r    c                     g)z)Idempotently creates the migrations tableNr   re   s    r!   setup_migrationsMigratableDB.setup_migrationso        	r    c                     g)z*Return true if the migrations table existsNr   re   s    r!   migrations_initialized#MigratableDB.migrations_initializedt   rk   r    r   c                     g)zvReturn a list of all migrations already applied to this database, from the
given source directory, in ascending order.Nr   )r.   r   s     r!   db_migrationsMigratableDB.db_migrationsy   rc   r    cur	migrationc                     g)z(Apply a single migration to the databaseNr   )r.   rr   rs   s      r!   apply_migrationMigratableDB.apply_migration   rk   r    c                     U R                   R                  S5      nUS:X  a  U R                  5         US:X  a  U R                  5         gg)z!Initialize migrations for this DB
migrationsvalidateapplyN)rY   r]   validate_migrationsapply_migrations)r.   migrates     r!   initialize_migrations"MigratableDB.initialize_migrations   sC    ..((6j $$&g!!# r    z MigratableDB.validate_migrationsc                 f   U R                  5       (       d
  [        5       eU R                  5        H~  nU R                  U5      n[	        UU R                  5       U R                  R                  S5      5      n[        X#5      n[        U5      S:  d  Md  US   S   n[        UR                  US9e   g)zhValidate all migrations and throw an exception if there are any unapplied
migrations in the source repo.migrations_hash_algorithmr   r   r:   N)rm   r(   rf   rp   find_migrationsra   rY   r]   verify_migration_sequencelenr6   name)r.   r   rp   source_migrationsunapplied_migrationsr   s         r!   r{    MigratableDB.validate_migrations   s     **,,.00&&(C ..s3M /$$&&&'BC!
 $=$  '(1,.q1)<.388WMM )r    zMigratableDB.apply_migrationsc                 |   U R                  5         U R                  5        H  nU R                  U5      n[        UU R	                  5       U R
                  R                  S5      5      n[        X#5      nU R                  5        nU H  nU R                  XV5        M     SSS5        M     g! , (       d  f       M  = f)z5Validate existing migrations, and apply all new ones.r   N)
ri   rf   rp   r   ra   rY   r]   r   txru   )r.   r   rp   r   r   rr   rs   s          r!   r|   MigratableDB.apply_migrations   s     	&&(C ..s3M /$$&&&'BC!
 $=$  c!5I((8 "6  ) s   B,,
B;	)r^   rY   r1   )r   r   r   r   __doc__r   r   r
   r-   staticmethodr	   r   ra   r   r   rf   ri   boolrm   r#   rp   r   ru   r~   r   r   ALLr{   r|   r   r3   r4   s   @r!   rW   rW   G   s4   ( !v !$ !
 S     5  
       )1D  
 6 i D  $ 46N6R6RSN TN& 13K3O3OP9 Q9r    rW   z(\d+)-(.+)\.(.+)\.sqlr   r   r   r2   c                     [         R                  U5      nUc  [        SU-   5      eUR                  5       u  pEnUU U[	        U5      US.$ )z6Parse a migration filename into a MigrationFile objectzInvalid migration filename: )r   r   r   r   r   )filename_regexmatchrT   groupsr   )r   r   r   r   r   _r   s          r!   _parse_migration_filenamer      sW       *E}&'E'PQQGw< r    rp   r   c                     [        X5       HN  u  p#US   US   :w  a  [        US   US   US   S9eUS   US   :w  d  M3  [        US   S-   US   -   US   US   S9e   U[        U 5      S $ )	a  Given a list of migrations already applied to a database, and a list of
migrations from the source code, validate that the applied migrations are correct
and match the expected migrations.

Throws an exception if any migrations are missing, out of order, or if the source
hash does not match.

Returns a list of all unapplied migrations, or an empty list if all migrations are
applied and the database is up to date.r   r   )r   r?   r@   r%   /r   )r   rH   rI   N)zipr=   rF   r   )rp   r   db_migrationsource_migrations       r!   r   r      s     +.m*O&	"&6y&AA* ''	2/	:  #3F#;;'!%(3.j1II$V,,V4  +P S/122r    r   hash_algc                 Z  ^ U R                  5        Vs/ s HF  nUR                  R                  S5      (       d  M%  [        U R                  UR                  U5      PMH     nn[	        [        U4S jU5      5      n[        US S9nU Vs/ s H  n[        XR5      PM     sn$ s  snf s  snf )zcReturn a list of all migration present in the given directory, in ascending
order. Filter by scope.z.sqlc                    > U S   T:H  $ )Nr   r   )fr   s    r!   <lambda>!find_migrations.<locals>.<lambda>   s    !G*"5r    c                     U S   $ )Nr   r   )r   s    r!   r   r      s    )r    )key)iterdirr   endswithr   listfiltersorted_read_migration_file)r   r   r   tfilesr   s    `    r!   r   r      s     A66??6" 	7!#((AFFA6 
 
 5u=>E545E7<=u! -u== >s   $B#%B#B(filec                 Z   SU ;  d  U S   R                  5       (       d#  [        SU S    SU S    SU S    SU S	    35      eU S   R                  5       nUS
:X  az  [        R                  S:  a2  [
        R                  " UR                  S5      SS9R                  5       O2[
        R                  " UR                  S5      5      R                  5       nOCUS:X  a4  [
        R                  " UR                  S5      5      R                  5       nO	[        US9eUUU S   U S   U S	   U S   S.$ )zRead a migration filer   z No migration file found for dir r   z with filename r   z and scope r   z at version r   md5)   	   zutf-8F)usedforsecuritysha256)rP   )r%   r&   r   r   r   r   )is_fileFileNotFoundError	read_textsysversion_infohashlibr   encode	hexdigestr   rN   )r   r   r&   r%   s       r!   r   r      sN   Tf!5!5!7!7.tE{m?4PZK[J\\ghlmthugv  wC  DH  IR  DS  CT  U
 	
 v,
 
 
"C5 6) KK

7+UCMMOSZZ01;;= 	
 
X	~~cjj12<<>8,, E{$	?g r    )r   )'r   typingr   typing_extensionsr   r   importlib_resources.abcr   rer   chromadb.db.baser   r   abcr	   chromadb.configr
   r    chromadb.telemetry.opentelemetryr   r   r   r   r#   	Exceptionr(   r6   r=   rF   rN   rT   rW   compiler   r   r   r   r   r   r   r    r!   <module>r      sK   
  4 / 	  *  , I  
A9 A

y 

y 

I 
Ey E
	y 	k95 k9` 45	#."3I&3	*3 i3B 38>	> >,/>i>}  	 r    