sqlmesh.utils.migration
1from sqlglot.dialects.dialect import DialectType 2 3# Sizes based on a composite key/index of two text fields with 4 bytes per characters. 4MAX_TEXT_INDEX_LENGTH = { 5 "mysql": "250", # 250 characters per column, <= 767 byte index size limit 6 "tsql": "450", # 450 bytes per column, <= 900 byte index size limit 7} 8 9 10def index_text_type(dialect: DialectType) -> str: 11 """ 12 MySQL and MSSQL cannot create indexes or primary keys on TEXT fields; they 13 require that the fields have a VARCHAR type of fixed length. 14 15 This helper abstracts away the type of such fields. 16 """ 17 18 return ( 19 f"VARCHAR({MAX_TEXT_INDEX_LENGTH[str(dialect)]})" 20 if dialect in MAX_TEXT_INDEX_LENGTH 21 else "TEXT" 22 ) 23 24 25def blob_text_type(dialect: DialectType) -> str: 26 return "LONGTEXT" if dialect == "mysql" else "TEXT"
def
index_text_type( dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType]) -> str:
11def index_text_type(dialect: DialectType) -> str: 12 """ 13 MySQL and MSSQL cannot create indexes or primary keys on TEXT fields; they 14 require that the fields have a VARCHAR type of fixed length. 15 16 This helper abstracts away the type of such fields. 17 """ 18 19 return ( 20 f"VARCHAR({MAX_TEXT_INDEX_LENGTH[str(dialect)]})" 21 if dialect in MAX_TEXT_INDEX_LENGTH 22 else "TEXT" 23 )
MySQL and MSSQL cannot create indexes or primary keys on TEXT fields; they require that the fields have a VARCHAR type of fixed length.
This helper abstracts away the type of such fields.
def
blob_text_type( dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType]) -> str: