Ë
    Ìi[  ã                   óÞ   — d dl mZmZ d dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZmZmZmZmZ  G d„ de«      Z ed	d	d	¬
«       G d„ dee«      «       Z ed	d	d	¬
«       G d„ dee«      «       Zy)é    )Ú	dataclassÚfield)ÚSetÚ	FrozenSetN)ÚStrEnum)ÚDbtRuntimeError)ÚRelationConfigBaseÚRelationConfigValidationMixinÚRelationConfigValidationRuleÚRelationConfigChangeActionÚRelationConfigChangec                   ó6   — e Zd ZdZdZdZdZdZdZe	d	d„«       Z
y)
ÚPostgresIndexMethodÚbtreeÚhashÚgistÚspgistÚginÚbrinc                 ó   —  | d«      S )Nr   © )Úclss    úm/var/www/html/strategist-ai/venv/lib/python3.12/site-packages/dbt/adapters/postgres/relation_configs/index.pyÚdefaultzPostgresIndexMethod.default   s   € á�7‹|Ðó    N)Úreturnr   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   Úclassmethodr   r   r   r   r   r      s2   „ Ø€EØ€DØ€DØ€FØ
€CØ€Dàòó ñr   r   T)ÚfrozenÚeqÚunsafe_hashc                   óF  ‡ — e Zd ZU dZ eddd¬«      Zeed<    eed¬«      Z	e
e   ed<    edd¬	«      Zeed
<    eej                  «       d¬	«      Zeed<   edee   fd„«       Zedˆ fd„«       Zededefd„«       Zedej2                  defd„«       Zedefd„«       Zˆ xZS )ÚPostgresIndexConfiga2  
    This config fallows the specs found here:
    https://www.postgresql.org/docs/current/sql-createindex.html

    The following parameters are configurable by dbt:
    - name: the name of the index in the database, this isn't predictable since we apply a timestamp
    - unique: checks for duplicate values when the index is created and on data updates
    - method: the index method to be used
    - column_names: the columns in the index

    Applicable defaults for non-configurable parameters:
    - concurrently: `False`
    - nulls_distinct: `True`
    Ú F)r   r   ÚcompareÚnameT)Údefault_factoryr   Úcolumn_names)r   r   ÚuniqueÚmethodr   c                 óH   — t        | j                  d ut        d«      ¬«      hS )Nz;Indexes require at least one column, but none were provided©Úvalidation_checkÚvalidation_error)r   r*   r   ©Úselfs    r   Úvalidation_rulesz$PostgresIndexConfig.validation_rules3   s/   € ô )Ø!%×!2Ñ!2¸$Ð!>Ü!0ØQó"ôð
ð 	
r   c           	      óÞ   •— |j                  d«      t        d„ |j                  dt        «       «      D «       «      |j                  d«      |j                  d«      dœ}t        ‰| �  |«      }|S )Nr(   c              3   ó<   K  — | ]  }|j                  «       –— Œ y ­w)N)Úlower)Ú.0Úcolumns     r   ú	<genexpr>z0PostgresIndexConfig.from_dict.<locals>.<genexpr>C   s   è ø€ ò &Ø#)�—‘—ñ&ùs   ‚r*   r+   r,   ©r(   r*   r+   r,   )ÚgetÚ	frozensetÚsetÚsuperÚ	from_dict)r   Úconfig_dictÚkwargs_dictÚindexÚ	__class__s       €r   r?   zPostgresIndexConfig.from_dict>   sj   ø€ ð  —O‘O FÓ+Ü%ñ &Ø-8¯_©_¸^ÌSËUÓ-Sô&ó ð "—o‘o hÓ/Ø!—o‘o hÓ/ñ
ˆô (-¡wÑ'8¸Ó'EˆØˆr   Úmodel_node_entryc                 ó�   — t        |j                  dt        «       «      «      |j                  d«      |j                  d«      dœ}|S )NÚcolumnsr+   Útype)r*   r+   r,   )r=   r;   )r   rD   r@   s      r   Úparse_model_nodez$PostgresIndexConfig.parse_model_nodeL   sG   € ô  Ð 0× 4Ñ 4°YÄÃÓ FÓGØ&×*Ñ*¨8Ó4Ø&×*Ñ*¨6Ó2ñ
ˆð
 Ðr   Úrelation_results_entryc                 ó¾   — |j                  d«      t        |j                  dd«      j                  d«      «      |j                  d«      |j                  d«      dœ}|S )Nr(   r*   r&   ú,r+   r,   r:   )r;   r=   Úsplit)r   rI   r@   s      r   Úparse_relation_resultsz*PostgresIndexConfig.parse_relation_resultsU   s_   € ð +×.Ñ.¨vÓ6ÜÐ 6× :Ñ :¸>È2Ó N× TÑ TÐUXÓ YÓZØ,×0Ñ0°Ó:Ø,×0Ñ0°Ó:ñ	
ˆð Ðr   c                 ót   — t        | j                  «      | j                  | j                  j                  dœ}|S )zX
        Returns: a dictionary that can be passed into `get_create_index_sql()`
        )rF   r+   rG   )Úlistr*   r+   r,   Úvalue)r2   Únode_configs     r   Úas_node_configz"PostgresIndexConfig.as_node_config_   s5   € ô ˜D×-Ñ-Ó.Ø—k‘kØ—K‘K×%Ñ%ñ
ˆð
 Ðr   )r   r%   )r   r   r   Ú__doc__r   r(   ÚstrÚ__annotations__r<   r*   r   r+   Úboolr   r   r,   Úpropertyr   r   r3   r    r?   ÚdictrH   ÚagateÚRowrM   rR   Ú__classcell__)rC   s   @r   r%   r%      sö   ø… ññ ˜b u°eÔ<€Dˆ#Ó<Ù#(¸ÈÔ#N€L�)˜C‘.ÓNÙ ¨TÔ2€FˆDÓ2Ù"'Ð0C×0KÑ0KÓ0MÐTXÔ"Y€FÐÓYàð
 #Ð&BÑ"Cò 
ó ð
ð ôó ðð ð°ð ¸ò ó ðð ð¸E¿I¹Ið È$ò ó ðð ð	 ò 	ó ô	r   r%   c                   óN   — e Zd ZU dZeed<   edefd„«       Zede	e
   fd„«       Zy)ÚPostgresIndexConfigChangea3  
    Example of an index change:
    {
        "action": "create",
        "context": {
            "name": "",  # we don't know the name since it gets created as a hash at runtime
            "columns": ["column_1", "column_3"],
            "type": "hash",
            "unique": True
        }
    },
    {
        "action": "drop",
        "context": {
            "name": "index_abc",  # we only need this to drop, but we need the rest to compare
            "columns": ["column_1"],
            "type": "btree",
            "unique": True
        }
    }
    Úcontextr   c                  ó   — y)NFr   r1   s    r   Úrequires_full_refreshz/PostgresIndexConfigChange.requires_full_refresh†   s   € àr   c                 óÂ  — t        | j                  t        j                  t        j                  hv t        d«      ¬«      t        | j                  t        j                  k(  xr | j                  j                  d u  t        d«      ¬«      t        | j                  t        j                  k(  xr! | j                  j                  t        «       k(   t        d«      ¬«      hS )NzNInvalid operation, only `drop` and `create` changes are supported for indexes.r.   z<Invalid operation, attempting to drop an index with no name.zBInvalid operations, attempting to create an index with no columns.)
r   Úactionr   ÚcreateÚdropr   r^   r(   r*   r=   r1   s    r   r3   z*PostgresIndexConfigChange.validation_rulesŠ   sÏ   € ô )Ø!%§¡Ü.×5Ñ5Ô7Q×7VÑ7VÐWð"Xä!0Ødó"ôô )à—K‘KÔ#=×#BÑ#BÑBÒ`ÀtÇ|Á|×GXÑGXÐ\`ÐG`ð"ô "1ØRó"ô	ô )à—K‘KÔ#=×#DÑ#DÑDò ;ØŸ™×1Ñ1´S³UÑ:ð"ô "1ØXó"ôð!
ð 	
r   N)r   r   r   rS   r%   rU   rW   rV   r`   r   r   r3   r   r   r   r]   r]   l   sI   … ñð, !Ó àð tò ó ðð ð
 #Ð&BÑ"Cò 
ó ñ
r   r]   )Údataclassesr   r   Útypingr   r   rY   Údbt_common.dataclass_schemar   Údbt_common.exceptionsr   Údbt.adapters.relation_configsr	   r
   r   r   r   r   r%   r]   r   r   r   ú<module>rj      s~   ðß (ß !ã Ý /Ý 1÷õ ô
˜'ô 
ñ �$˜4¨TÔ2ôKÐ,Ð.Kó Kó 3ðKñ\ �$˜4¨TÔ2ô8
Ð 4Ð6Só 8
ó 3ñ8
r   