sqlspec 0.72.0__cp315-cp315-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 6b29784d6b1cafc66758__mypyc.cp315-win_amd64.pyd +0 -0
- sqlspec/__init__.py +381 -0
- sqlspec/__main__.py +14 -0
- sqlspec/__metadata__.py +14 -0
- sqlspec/_typing.py +775 -0
- sqlspec/adapters/__init__.py +3 -0
- sqlspec/adapters/adbc/__init__.py +16 -0
- sqlspec/adapters/adbc/_typing.py +221 -0
- sqlspec/adapters/adbc/adk/__init__.py +11 -0
- sqlspec/adapters/adbc/adk/store.py +4101 -0
- sqlspec/adapters/adbc/config.py +843 -0
- sqlspec/adapters/adbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/core.py +3209 -0
- sqlspec/adapters/adbc/data_dictionary.py +1448 -0
- sqlspec/adapters/adbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/driver.py +1400 -0
- sqlspec/adapters/adbc/events/__init__.py +5 -0
- sqlspec/adapters/adbc/events/store.py +384 -0
- sqlspec/adapters/adbc/litestar/__init__.py +5 -0
- sqlspec/adapters/adbc/litestar/store.py +962 -0
- sqlspec/adapters/adbc/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/pool.py +242 -0
- sqlspec/adapters/adbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/adbc/type_converter.py +117 -0
- sqlspec/adapters/aiomysql/__init__.py +25 -0
- sqlspec/adapters/aiomysql/_typing.py +134 -0
- sqlspec/adapters/aiomysql/adk/__init__.py +5 -0
- sqlspec/adapters/aiomysql/adk/store.py +1542 -0
- sqlspec/adapters/aiomysql/config.py +634 -0
- sqlspec/adapters/aiomysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/core.py +922 -0
- sqlspec/adapters/aiomysql/data_dictionary.py +16 -0
- sqlspec/adapters/aiomysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiomysql/driver.py +494 -0
- sqlspec/adapters/aiomysql/events/__init__.py +5 -0
- sqlspec/adapters/aiomysql/events/store.py +72 -0
- sqlspec/adapters/aiomysql/litestar/__init__.py +5 -0
- sqlspec/adapters/aiomysql/litestar/store.py +345 -0
- sqlspec/adapters/aiosqlite/__init__.py +43 -0
- sqlspec/adapters/aiosqlite/_typing.py +75 -0
- sqlspec/adapters/aiosqlite/adk/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/adk/store.py +1546 -0
- sqlspec/adapters/aiosqlite/config.py +607 -0
- sqlspec/adapters/aiosqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/core.py +1155 -0
- sqlspec/adapters/aiosqlite/data_dictionary.py +343 -0
- sqlspec/adapters/aiosqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/driver.py +559 -0
- sqlspec/adapters/aiosqlite/events/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/events/store.py +54 -0
- sqlspec/adapters/aiosqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/aiosqlite/litestar/store.py +315 -0
- sqlspec/adapters/aiosqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/pool.py +1323 -0
- sqlspec/adapters/aiosqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/aiosqlite/type_converter.py +114 -0
- sqlspec/adapters/arrow_odbc/__init__.py +32 -0
- sqlspec/adapters/arrow_odbc/_typing.py +131 -0
- sqlspec/adapters/arrow_odbc/adk/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/adk/store.py +1671 -0
- sqlspec/adapters/arrow_odbc/config.py +446 -0
- sqlspec/adapters/arrow_odbc/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/core.py +795 -0
- sqlspec/adapters/arrow_odbc/data_dictionary.py +345 -0
- sqlspec/adapters/arrow_odbc/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/driver.py +885 -0
- sqlspec/adapters/arrow_odbc/events/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/events/store.py +114 -0
- sqlspec/adapters/arrow_odbc/litestar/__init__.py +5 -0
- sqlspec/adapters/arrow_odbc/litestar/store.py +682 -0
- sqlspec/adapters/arrow_odbc/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/arrow_odbc/type_converter.py +95 -0
- sqlspec/adapters/asyncmy/__init__.py +27 -0
- sqlspec/adapters/asyncmy/_typing.py +215 -0
- sqlspec/adapters/asyncmy/adk/__init__.py +5 -0
- sqlspec/adapters/asyncmy/adk/store.py +1544 -0
- sqlspec/adapters/asyncmy/config.py +707 -0
- sqlspec/adapters/asyncmy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/core.py +917 -0
- sqlspec/adapters/asyncmy/data_dictionary.py +16 -0
- sqlspec/adapters/asyncmy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncmy/driver.py +529 -0
- sqlspec/adapters/asyncmy/events/__init__.py +5 -0
- sqlspec/adapters/asyncmy/events/store.py +72 -0
- sqlspec/adapters/asyncmy/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncmy/litestar/store.py +348 -0
- sqlspec/adapters/asyncpg/__init__.py +28 -0
- sqlspec/adapters/asyncpg/_typing.py +113 -0
- sqlspec/adapters/asyncpg/adk/__init__.py +5 -0
- sqlspec/adapters/asyncpg/adk/store.py +1145 -0
- sqlspec/adapters/asyncpg/config.py +903 -0
- sqlspec/adapters/asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/core.py +797 -0
- sqlspec/adapters/asyncpg/data_dictionary.py +417 -0
- sqlspec/adapters/asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/driver.py +927 -0
- sqlspec/adapters/asyncpg/events/__init__.py +6 -0
- sqlspec/adapters/asyncpg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/events/_hub.py +279 -0
- sqlspec/adapters/asyncpg/events/backend.py +410 -0
- sqlspec/adapters/asyncpg/events/store.py +57 -0
- sqlspec/adapters/asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/asyncpg/litestar/store.py +278 -0
- sqlspec/adapters/asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/asyncpg/tenant.py +140 -0
- sqlspec/adapters/bigquery/__init__.py +23 -0
- sqlspec/adapters/bigquery/_typing.py +184 -0
- sqlspec/adapters/bigquery/adk/__init__.py +5 -0
- sqlspec/adapters/bigquery/adk/store.py +920 -0
- sqlspec/adapters/bigquery/config.py +631 -0
- sqlspec/adapters/bigquery/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/core.py +1433 -0
- sqlspec/adapters/bigquery/data_dictionary.py +502 -0
- sqlspec/adapters/bigquery/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/bigquery/driver.py +1266 -0
- sqlspec/adapters/bigquery/events/__init__.py +5 -0
- sqlspec/adapters/bigquery/events/store.py +158 -0
- sqlspec/adapters/bigquery/litestar/__init__.py +5 -0
- sqlspec/adapters/bigquery/litestar/store.py +359 -0
- sqlspec/adapters/cockroach_asyncpg/__init__.py +32 -0
- sqlspec/adapters/cockroach_asyncpg/_typing.py +54 -0
- sqlspec/adapters/cockroach_asyncpg/adk/__init__.py +9 -0
- sqlspec/adapters/cockroach_asyncpg/adk/store.py +1096 -0
- sqlspec/adapters/cockroach_asyncpg/config.py +653 -0
- sqlspec/adapters/cockroach_asyncpg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/core.py +835 -0
- sqlspec/adapters/cockroach_asyncpg/data_dictionary.py +371 -0
- sqlspec/adapters/cockroach_asyncpg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/driver.py +438 -0
- sqlspec/adapters/cockroach_asyncpg/events/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/events/store.py +20 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/__init__.py +5 -0
- sqlspec/adapters/cockroach_asyncpg/litestar/store.py +203 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_asyncpg/tenant.py +143 -0
- sqlspec/adapters/cockroach_psycopg/__init__.py +46 -0
- sqlspec/adapters/cockroach_psycopg/_typing.py +271 -0
- sqlspec/adapters/cockroach_psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/cockroach_psycopg/adk/store.py +2274 -0
- sqlspec/adapters/cockroach_psycopg/config.py +1285 -0
- sqlspec/adapters/cockroach_psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/core.py +667 -0
- sqlspec/adapters/cockroach_psycopg/data_dictionary.py +622 -0
- sqlspec/adapters/cockroach_psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/driver.py +864 -0
- sqlspec/adapters/cockroach_psycopg/events/__init__.py +8 -0
- sqlspec/adapters/cockroach_psycopg/events/store.py +34 -0
- sqlspec/adapters/cockroach_psycopg/litestar/__init__.py +9 -0
- sqlspec/adapters/cockroach_psycopg/litestar/store.py +413 -0
- sqlspec/adapters/cockroach_psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/cockroach_psycopg/tenant.py +222 -0
- sqlspec/adapters/db2/__init__.py +34 -0
- sqlspec/adapters/db2/_typing.py +357 -0
- sqlspec/adapters/db2/adk/__init__.py +10 -0
- sqlspec/adapters/db2/adk/store.py +1950 -0
- sqlspec/adapters/db2/config.py +550 -0
- sqlspec/adapters/db2/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/core.py +1021 -0
- sqlspec/adapters/db2/data_dictionary.py +493 -0
- sqlspec/adapters/db2/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/driver.py +898 -0
- sqlspec/adapters/db2/events/__init__.py +5 -0
- sqlspec/adapters/db2/events/store.py +77 -0
- sqlspec/adapters/db2/litestar/__init__.py +5 -0
- sqlspec/adapters/db2/litestar/store.py +519 -0
- sqlspec/adapters/db2/migrations.py +221 -0
- sqlspec/adapters/db2/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/pool.py +876 -0
- sqlspec/adapters/db2/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/db2/tenant.py +292 -0
- sqlspec/adapters/duckdb/__init__.py +30 -0
- sqlspec/adapters/duckdb/_typing.py +182 -0
- sqlspec/adapters/duckdb/adk/__init__.py +10 -0
- sqlspec/adapters/duckdb/adk/store.py +1672 -0
- sqlspec/adapters/duckdb/config.py +506 -0
- sqlspec/adapters/duckdb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/core.py +1299 -0
- sqlspec/adapters/duckdb/data_dictionary.py +553 -0
- sqlspec/adapters/duckdb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/driver.py +1214 -0
- sqlspec/adapters/duckdb/events/__init__.py +5 -0
- sqlspec/adapters/duckdb/events/store.py +38 -0
- sqlspec/adapters/duckdb/litestar/__init__.py +5 -0
- sqlspec/adapters/duckdb/litestar/store.py +313 -0
- sqlspec/adapters/duckdb/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/duckdb/pool.py +1121 -0
- sqlspec/adapters/mssql_python/__init__.py +42 -0
- sqlspec/adapters/mssql_python/_typing.py +135 -0
- sqlspec/adapters/mssql_python/adk/__init__.py +5 -0
- sqlspec/adapters/mssql_python/adk/store.py +1278 -0
- sqlspec/adapters/mssql_python/config.py +455 -0
- sqlspec/adapters/mssql_python/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/core.py +862 -0
- sqlspec/adapters/mssql_python/data_dictionary.py +417 -0
- sqlspec/adapters/mssql_python/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/driver.py +772 -0
- sqlspec/adapters/mssql_python/events/__init__.py +5 -0
- sqlspec/adapters/mssql_python/events/store.py +46 -0
- sqlspec/adapters/mssql_python/litestar/__init__.py +5 -0
- sqlspec/adapters/mssql_python/litestar/store.py +355 -0
- sqlspec/adapters/mssql_python/migrations.py +162 -0
- sqlspec/adapters/mssql_python/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/pool.py +165 -0
- sqlspec/adapters/mssql_python/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/tenant.py +74 -0
- sqlspec/adapters/mssql_python/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mssql_python/type_converter.py +98 -0
- sqlspec/adapters/mysqlconnector/__init__.py +47 -0
- sqlspec/adapters/mysqlconnector/_typing.py +205 -0
- sqlspec/adapters/mysqlconnector/adk/__init__.py +17 -0
- sqlspec/adapters/mysqlconnector/adk/store.py +2503 -0
- sqlspec/adapters/mysqlconnector/config.py +925 -0
- sqlspec/adapters/mysqlconnector/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/core.py +1075 -0
- sqlspec/adapters/mysqlconnector/data_dictionary.py +23 -0
- sqlspec/adapters/mysqlconnector/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/mysqlconnector/driver.py +702 -0
- sqlspec/adapters/mysqlconnector/events/__init__.py +8 -0
- sqlspec/adapters/mysqlconnector/events/store.py +89 -0
- sqlspec/adapters/mysqlconnector/litestar/__init__.py +9 -0
- sqlspec/adapters/mysqlconnector/litestar/store.py +524 -0
- sqlspec/adapters/oracledb/__init__.py +159 -0
- sqlspec/adapters/oracledb/_json_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_json_handlers.py +208 -0
- sqlspec/adapters/oracledb/_param_types.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_param_types.py +65 -0
- sqlspec/adapters/oracledb/_plugins.py +137 -0
- sqlspec/adapters/oracledb/_storage.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_storage.py +138 -0
- sqlspec/adapters/oracledb/_typing.py +468 -0
- sqlspec/adapters/oracledb/_uuid_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_uuid_handlers.py +143 -0
- sqlspec/adapters/oracledb/_vector_handlers.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/_vector_handlers.py +252 -0
- sqlspec/adapters/oracledb/adk/__init__.py +27 -0
- sqlspec/adapters/oracledb/adk/store.py +4031 -0
- sqlspec/adapters/oracledb/config.py +1785 -0
- sqlspec/adapters/oracledb/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/core.py +5416 -0
- sqlspec/adapters/oracledb/data_dictionary.py +1264 -0
- sqlspec/adapters/oracledb/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/driver.py +3273 -0
- sqlspec/adapters/oracledb/events/__init__.py +29 -0
- sqlspec/adapters/oracledb/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/events/_hub.py +394 -0
- sqlspec/adapters/oracledb/events/backend.py +311 -0
- sqlspec/adapters/oracledb/events/store.py +842 -0
- sqlspec/adapters/oracledb/litestar/__init__.py +17 -0
- sqlspec/adapters/oracledb/litestar/store.py +862 -0
- sqlspec/adapters/oracledb/migrations.py +650 -0
- sqlspec/adapters/oracledb/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/tenant.py +990 -0
- sqlspec/adapters/oracledb/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/oracledb/type_converter.py +93 -0
- sqlspec/adapters/psqlpy/__init__.py +21 -0
- sqlspec/adapters/psqlpy/_typing.py +180 -0
- sqlspec/adapters/psqlpy/adk/__init__.py +5 -0
- sqlspec/adapters/psqlpy/adk/store.py +1514 -0
- sqlspec/adapters/psqlpy/config.py +828 -0
- sqlspec/adapters/psqlpy/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/core.py +1040 -0
- sqlspec/adapters/psqlpy/data_dictionary.py +399 -0
- sqlspec/adapters/psqlpy/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/driver.py +631 -0
- sqlspec/adapters/psqlpy/events/__init__.py +12 -0
- sqlspec/adapters/psqlpy/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/events/_hub.py +367 -0
- sqlspec/adapters/psqlpy/events/backend.py +415 -0
- sqlspec/adapters/psqlpy/events/store.py +46 -0
- sqlspec/adapters/psqlpy/litestar/__init__.py +5 -0
- sqlspec/adapters/psqlpy/litestar/store.py +270 -0
- sqlspec/adapters/psqlpy/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/tenant.py +137 -0
- sqlspec/adapters/psqlpy/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psqlpy/type_converter.py +21 -0
- sqlspec/adapters/psycopg/__init__.py +44 -0
- sqlspec/adapters/psycopg/_typing.py +408 -0
- sqlspec/adapters/psycopg/adk/__init__.py +17 -0
- sqlspec/adapters/psycopg/adk/store.py +2761 -0
- sqlspec/adapters/psycopg/config.py +1522 -0
- sqlspec/adapters/psycopg/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/core.py +1001 -0
- sqlspec/adapters/psycopg/data_dictionary.py +701 -0
- sqlspec/adapters/psycopg/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/driver.py +1629 -0
- sqlspec/adapters/psycopg/events/__init__.py +25 -0
- sqlspec/adapters/psycopg/events/_hub.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/events/_hub.py +646 -0
- sqlspec/adapters/psycopg/events/backend.py +739 -0
- sqlspec/adapters/psycopg/events/store.py +82 -0
- sqlspec/adapters/psycopg/litestar/__init__.py +5 -0
- sqlspec/adapters/psycopg/litestar/store.py +595 -0
- sqlspec/adapters/psycopg/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/tenant.py +226 -0
- sqlspec/adapters/psycopg/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/psycopg/type_converter.py +94 -0
- sqlspec/adapters/pymssql/__init__.py +29 -0
- sqlspec/adapters/pymssql/_typing.py +156 -0
- sqlspec/adapters/pymssql/adk/__init__.py +5 -0
- sqlspec/adapters/pymssql/adk/store.py +1270 -0
- sqlspec/adapters/pymssql/config.py +299 -0
- sqlspec/adapters/pymssql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/core.py +527 -0
- sqlspec/adapters/pymssql/data_dictionary.py +417 -0
- sqlspec/adapters/pymssql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/driver.py +527 -0
- sqlspec/adapters/pymssql/events/__init__.py +5 -0
- sqlspec/adapters/pymssql/events/store.py +46 -0
- sqlspec/adapters/pymssql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymssql/litestar/store.py +350 -0
- sqlspec/adapters/pymssql/migrations.py +162 -0
- sqlspec/adapters/pymssql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/pool.py +417 -0
- sqlspec/adapters/pymssql/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymssql/tenant.py +73 -0
- sqlspec/adapters/pymysql/__init__.py +27 -0
- sqlspec/adapters/pymysql/_typing.py +105 -0
- sqlspec/adapters/pymysql/adk/__init__.py +5 -0
- sqlspec/adapters/pymysql/adk/store.py +1646 -0
- sqlspec/adapters/pymysql/config.py +545 -0
- sqlspec/adapters/pymysql/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/core.py +909 -0
- sqlspec/adapters/pymysql/data_dictionary.py +16 -0
- sqlspec/adapters/pymysql/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/driver.py +370 -0
- sqlspec/adapters/pymysql/events/__init__.py +5 -0
- sqlspec/adapters/pymysql/events/store.py +42 -0
- sqlspec/adapters/pymysql/litestar/__init__.py +5 -0
- sqlspec/adapters/pymysql/litestar/store.py +299 -0
- sqlspec/adapters/pymysql/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/pymysql/pool.py +480 -0
- sqlspec/adapters/snowflake/__init__.py +36 -0
- sqlspec/adapters/snowflake/_typing.py +62 -0
- sqlspec/adapters/snowflake/adk/__init__.py +5 -0
- sqlspec/adapters/snowflake/adk/store.py +778 -0
- sqlspec/adapters/snowflake/config.py +333 -0
- sqlspec/adapters/snowflake/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/core.py +683 -0
- sqlspec/adapters/snowflake/data_dictionary.py +355 -0
- sqlspec/adapters/snowflake/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/driver.py +872 -0
- sqlspec/adapters/snowflake/events/__init__.py +5 -0
- sqlspec/adapters/snowflake/events/store.py +28 -0
- sqlspec/adapters/snowflake/litestar/__init__.py +5 -0
- sqlspec/adapters/snowflake/litestar/store.py +162 -0
- sqlspec/adapters/snowflake/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/migrations.py +76 -0
- sqlspec/adapters/snowflake/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/pool.py +385 -0
- sqlspec/adapters/snowflake/tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/tenant.py +200 -0
- sqlspec/adapters/snowflake/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/snowflake/type_converter.py +33 -0
- sqlspec/adapters/spanner/__init__.py +57 -0
- sqlspec/adapters/spanner/_typing.py +300 -0
- sqlspec/adapters/spanner/adk/__init__.py +22 -0
- sqlspec/adapters/spanner/adk/artifact_store.py +693 -0
- sqlspec/adapters/spanner/adk/store.py +3053 -0
- sqlspec/adapters/spanner/config.py +1578 -0
- sqlspec/adapters/spanner/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/core.py +1244 -0
- sqlspec/adapters/spanner/data_dictionary.py +706 -0
- sqlspec/adapters/spanner/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/driver.py +1673 -0
- sqlspec/adapters/spanner/events/__init__.py +5 -0
- sqlspec/adapters/spanner/events/store.py +357 -0
- sqlspec/adapters/spanner/litestar/__init__.py +5 -0
- sqlspec/adapters/spanner/litestar/store.py +570 -0
- sqlspec/adapters/spanner/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/spanner/type_converter.py +466 -0
- sqlspec/adapters/sqlanywhere/__init__.py +40 -0
- sqlspec/adapters/sqlanywhere/_typing.py +139 -0
- sqlspec/adapters/sqlanywhere/adk/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/adk/store.py +1136 -0
- sqlspec/adapters/sqlanywhere/config.py +359 -0
- sqlspec/adapters/sqlanywhere/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/core.py +583 -0
- sqlspec/adapters/sqlanywhere/data_dictionary.py +282 -0
- sqlspec/adapters/sqlanywhere/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/driver.py +480 -0
- sqlspec/adapters/sqlanywhere/events/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/events/store.py +28 -0
- sqlspec/adapters/sqlanywhere/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlanywhere/litestar/store.py +237 -0
- sqlspec/adapters/sqlanywhere/migrations.py +178 -0
- sqlspec/adapters/sqlanywhere/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlanywhere/pool.py +397 -0
- sqlspec/adapters/sqlite/__init__.py +32 -0
- sqlspec/adapters/sqlite/_typing.py +91 -0
- sqlspec/adapters/sqlite/adk/__init__.py +5 -0
- sqlspec/adapters/sqlite/adk/store.py +1628 -0
- sqlspec/adapters/sqlite/config.py +520 -0
- sqlspec/adapters/sqlite/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/core.py +1035 -0
- sqlspec/adapters/sqlite/data_dictionary.py +327 -0
- sqlspec/adapters/sqlite/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/driver.py +432 -0
- sqlspec/adapters/sqlite/events/__init__.py +5 -0
- sqlspec/adapters/sqlite/events/store.py +54 -0
- sqlspec/adapters/sqlite/litestar/__init__.py +5 -0
- sqlspec/adapters/sqlite/litestar/store.py +367 -0
- sqlspec/adapters/sqlite/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/pool.py +935 -0
- sqlspec/adapters/sqlite/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sqlite/type_converter.py +114 -0
- sqlspec/adapters/sybase/__init__.py +37 -0
- sqlspec/adapters/sybase/_typing.py +150 -0
- sqlspec/adapters/sybase/adk/__init__.py +5 -0
- sqlspec/adapters/sybase/adk/store.py +1370 -0
- sqlspec/adapters/sybase/config.py +276 -0
- sqlspec/adapters/sybase/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/core.py +578 -0
- sqlspec/adapters/sybase/data_dictionary.py +358 -0
- sqlspec/adapters/sybase/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/driver.py +497 -0
- sqlspec/adapters/sybase/events/__init__.py +5 -0
- sqlspec/adapters/sybase/events/store.py +88 -0
- sqlspec/adapters/sybase/litestar/__init__.py +5 -0
- sqlspec/adapters/sybase/litestar/store.py +328 -0
- sqlspec/adapters/sybase/migrations.py +178 -0
- sqlspec/adapters/sybase/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/sybase/pool.py +435 -0
- sqlspec/adapters/teradata/__init__.py +59 -0
- sqlspec/adapters/teradata/_typing.py +145 -0
- sqlspec/adapters/teradata/adk/__init__.py +5 -0
- sqlspec/adapters/teradata/adk/store.py +1300 -0
- sqlspec/adapters/teradata/config.py +324 -0
- sqlspec/adapters/teradata/core.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/core.py +437 -0
- sqlspec/adapters/teradata/data_dictionary.py +316 -0
- sqlspec/adapters/teradata/driver.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/driver.py +721 -0
- sqlspec/adapters/teradata/events/__init__.py +5 -0
- sqlspec/adapters/teradata/events/store.py +64 -0
- sqlspec/adapters/teradata/litestar/__init__.py +5 -0
- sqlspec/adapters/teradata/litestar/store.py +264 -0
- sqlspec/adapters/teradata/migrations.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/migrations.py +80 -0
- sqlspec/adapters/teradata/pool.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/pool.py +377 -0
- sqlspec/adapters/teradata/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/adapters/teradata/type_converter.py +95 -0
- sqlspec/base.cp315-win_amd64.pyd +0 -0
- sqlspec/base.py +1275 -0
- sqlspec/builder/__init__.py +330 -0
- sqlspec/builder/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_base.py +1752 -0
- sqlspec/builder/_column.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_column.py +508 -0
- sqlspec/builder/_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_ddl.py +4503 -0
- sqlspec/builder/_delete.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_delete.py +75 -0
- sqlspec/builder/_dml.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_dml.py +639 -0
- sqlspec/builder/_explain.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_explain.py +650 -0
- sqlspec/builder/_expression_wrappers.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_expression_wrappers.py +77 -0
- sqlspec/builder/_factory.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_factory.py +1834 -0
- sqlspec/builder/_generation.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_generation.py +55 -0
- sqlspec/builder/_insert.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_insert.py +308 -0
- sqlspec/builder/_join.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_join.py +501 -0
- sqlspec/builder/_locking.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_locking.py +77 -0
- sqlspec/builder/_merge.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_merge.py +1047 -0
- sqlspec/builder/_parsing_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_parsing_utils.py +1197 -0
- sqlspec/builder/_select.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_select.py +1514 -0
- sqlspec/builder/_temporal.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_temporal.py +183 -0
- sqlspec/builder/_update.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_update.py +139 -0
- sqlspec/builder/_values.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_values.py +271 -0
- sqlspec/builder/_vector_distance.cp315-win_amd64.pyd +0 -0
- sqlspec/builder/_vector_distance.py +763 -0
- sqlspec/cli.py +1656 -0
- sqlspec/config.py +3402 -0
- sqlspec/core/__init__.py +542 -0
- sqlspec/core/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_cursor.py +564 -0
- sqlspec/core/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_operators.py +167 -0
- sqlspec/core/_ordering.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_ordering.py +151 -0
- sqlspec/core/_pagination.py +66 -0
- sqlspec/core/_pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pipeline.py +343 -0
- sqlspec/core/_pool.cp315-win_amd64.pyd +0 -0
- sqlspec/core/_pool.py +72 -0
- sqlspec/core/cache.cp315-win_amd64.pyd +0 -0
- sqlspec/core/cache.py +1503 -0
- sqlspec/core/capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/core/capabilities.py +67 -0
- sqlspec/core/compiler.cp315-win_amd64.pyd +0 -0
- sqlspec/core/compiler.py +1667 -0
- sqlspec/core/config_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/core/config_runtime.py +219 -0
- sqlspec/core/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/core/correlation.py +135 -0
- sqlspec/core/explain.cp315-win_amd64.pyd +0 -0
- sqlspec/core/explain.py +284 -0
- sqlspec/core/filters.cp315-win_amd64.pyd +0 -0
- sqlspec/core/filters.py +1442 -0
- sqlspec/core/hashing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/hashing.py +394 -0
- sqlspec/core/metrics.cp315-win_amd64.pyd +0 -0
- sqlspec/core/metrics.py +86 -0
- sqlspec/core/parameters/__init__.py +174 -0
- sqlspec/core/parameters/_alignment.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_alignment.py +321 -0
- sqlspec/core/parameters/_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_converter.py +956 -0
- sqlspec/core/parameters/_declared.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_declared.py +154 -0
- sqlspec/core/parameters/_processor.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_processor.py +1646 -0
- sqlspec/core/parameters/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_registry.py +207 -0
- sqlspec/core/parameters/_transformers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_transformers.py +318 -0
- sqlspec/core/parameters/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_types.py +658 -0
- sqlspec/core/parameters/_validator.cp315-win_amd64.pyd +0 -0
- sqlspec/core/parameters/_validator.py +699 -0
- sqlspec/core/query_modifiers.cp315-win_amd64.pyd +0 -0
- sqlspec/core/query_modifiers.py +559 -0
- sqlspec/core/result/__init__.py +67 -0
- sqlspec/core/result/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/result/_base.py +1772 -0
- sqlspec/core/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/core/routing.py +270 -0
- sqlspec/core/splitter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/splitter.py +1126 -0
- sqlspec/core/sqlcommenter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/sqlcommenter.py +509 -0
- sqlspec/core/stack.cp315-win_amd64.pyd +0 -0
- sqlspec/core/stack.py +167 -0
- sqlspec/core/statement.cp315-win_amd64.pyd +0 -0
- sqlspec/core/statement.py +2253 -0
- sqlspec/core/tenant/__init__.py +64 -0
- sqlspec/core/tenant/base.cp315-win_amd64.pyd +0 -0
- sqlspec/core/tenant/base.py +123 -0
- sqlspec/core/type_converter.cp315-win_amd64.pyd +0 -0
- sqlspec/core/type_converter.py +147 -0
- sqlspec/data_dictionary/__init__.py +237 -0
- sqlspec/data_dictionary/_capabilities.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_capabilities.py +142 -0
- sqlspec/data_dictionary/_dependencies.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_dependencies.py +602 -0
- sqlspec/data_dictionary/_index_ddl.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_index_ddl.py +562 -0
- sqlspec/data_dictionary/_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_loader.py +344 -0
- sqlspec/data_dictionary/_registry.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_registry.py +152 -0
- sqlspec/data_dictionary/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/_types.py +1852 -0
- sqlspec/data_dictionary/dialects/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/bigquery/__init__.py +15 -0
- sqlspec/data_dictionary/dialects/bigquery/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/bigquery/config.py +128 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/columns.sql +63 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/constraints.sql +37 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/datasets.sql +14 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/ddl.sql +51 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/dependencies.sql +22 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/foreign_keys.sql +34 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/indexes.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/routines.sql +50 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/system.sql +59 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/tables.sql +111 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/bigquery/sql/views.sql +31 -0
- sqlspec/data_dictionary/dialects/cockroachdb/__init__.py +17 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/cockroachdb/config.py +95 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/columns.sql +163 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/comments.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/crdb_internal.sql +11 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/ddl.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/dependencies.sql +20 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/foreign_keys.sql +62 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/indexes.sql +32 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/objects.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/tables.sql +15 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/cockroachdb/sql/views.sql +11 -0
- sqlspec/data_dictionary/dialects/db2/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/db2/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/db2/config.py +172 -0
- sqlspec/data_dictionary/dialects/db2/sql/columns.sql +98 -0
- sqlspec/data_dictionary/dialects/db2/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/db2/sql/foreign_keys.sql +43 -0
- sqlspec/data_dictionary/dialects/db2/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/db2/sql/objects.sql +53 -0
- sqlspec/data_dictionary/dialects/db2/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/db2/sql/tables.sql +77 -0
- sqlspec/data_dictionary/dialects/db2/sql/version.sql +8 -0
- sqlspec/data_dictionary/dialects/db2/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/duckdb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/duckdb/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/duckdb/config.py +66 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/columns.sql +150 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/constraints.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/databases.sql +11 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/ddl.sql +221 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/dependencies.sql +50 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/extensions.sql +14 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/foreign_keys.sql +46 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/functions.sql +18 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/indexes.sql +34 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/objects.sql +30 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/sequences.sql +19 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/system.sql +21 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/tables.sql +59 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/types.sql +12 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/duckdb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mariadb/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/ddl.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/objects.sql +50 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/privileges.sql +24 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/system.sql +12 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mariadb/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/mssql/__init__.py +51 -0
- sqlspec/data_dictionary/dialects/mssql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mssql/config.py +558 -0
- sqlspec/data_dictionary/dialects/mssql/sql/columns.sql +120 -0
- sqlspec/data_dictionary/dialects/mssql/sql/constraints.sql +106 -0
- sqlspec/data_dictionary/dialects/mssql/sql/ddl.sql +89 -0
- sqlspec/data_dictionary/dialects/mssql/sql/dependencies.sql +17 -0
- sqlspec/data_dictionary/dialects/mssql/sql/extended_properties.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/foreign_keys.sql +40 -0
- sqlspec/data_dictionary/dialects/mssql/sql/indexes.sql +86 -0
- sqlspec/data_dictionary/dialects/mssql/sql/modules.sql +19 -0
- sqlspec/data_dictionary/dialects/mssql/sql/objects.sql +16 -0
- sqlspec/data_dictionary/dialects/mssql/sql/permissions.sql +31 -0
- sqlspec/data_dictionary/dialects/mssql/sql/routines.sql +39 -0
- sqlspec/data_dictionary/dialects/mssql/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/mssql/sql/sequences.sql +18 -0
- sqlspec/data_dictionary/dialects/mssql/sql/storage.sql +22 -0
- sqlspec/data_dictionary/dialects/mssql/sql/system.sql +38 -0
- sqlspec/data_dictionary/dialects/mssql/sql/tables.sql +97 -0
- sqlspec/data_dictionary/dialects/mssql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mssql/sql/version.sql +7 -0
- sqlspec/data_dictionary/dialects/mssql/sql/views.sql +18 -0
- sqlspec/data_dictionary/dialects/mysql/__init__.py +34 -0
- sqlspec/data_dictionary/dialects/mysql/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/mysql/config.py +363 -0
- sqlspec/data_dictionary/dialects/mysql/dictionary.py +650 -0
- sqlspec/data_dictionary/dialects/mysql/sql/columns.sql +45 -0
- sqlspec/data_dictionary/dialects/mysql/sql/components.sql +8 -0
- sqlspec/data_dictionary/dialects/mysql/sql/constraints.sql +30 -0
- sqlspec/data_dictionary/dialects/mysql/sql/ddl.sql +23 -0
- sqlspec/data_dictionary/dialects/mysql/sql/events.sql +29 -0
- sqlspec/data_dictionary/dialects/mysql/sql/foreign_keys.sql +42 -0
- sqlspec/data_dictionary/dialects/mysql/sql/indexes.sql +33 -0
- sqlspec/data_dictionary/dialects/mysql/sql/objects.sql +38 -0
- sqlspec/data_dictionary/dialects/mysql/sql/partitions.sql +27 -0
- sqlspec/data_dictionary/dialects/mysql/sql/plugins.sql +16 -0
- sqlspec/data_dictionary/dialects/mysql/sql/privileges.sql +26 -0
- sqlspec/data_dictionary/dialects/mysql/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/schemas.sql +10 -0
- sqlspec/data_dictionary/dialects/mysql/sql/system.sql +25 -0
- sqlspec/data_dictionary/dialects/mysql/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/mysql/sql/triggers.sql +21 -0
- sqlspec/data_dictionary/dialects/mysql/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/mysql/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/oracle/__init__.py +39 -0
- sqlspec/data_dictionary/dialects/oracle/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/oracle/config.py +266 -0
- sqlspec/data_dictionary/dialects/oracle/sql/arguments.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/columns.sql +103 -0
- sqlspec/data_dictionary/dialects/oracle/sql/comments.sql +22 -0
- sqlspec/data_dictionary/dialects/oracle/sql/constraints.sql +49 -0
- sqlspec/data_dictionary/dialects/oracle/sql/ddl.sql +4 -0
- sqlspec/data_dictionary/dialects/oracle/sql/dependencies.sql +16 -0
- sqlspec/data_dictionary/dialects/oracle/sql/foreign_keys.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/grants.sql +34 -0
- sqlspec/data_dictionary/dialects/oracle/sql/indexes.sql +87 -0
- sqlspec/data_dictionary/dialects/oracle/sql/lob_storage.sql +28 -0
- sqlspec/data_dictionary/dialects/oracle/sql/materialized_views.sql +27 -0
- sqlspec/data_dictionary/dialects/oracle/sql/objects.sql +26 -0
- sqlspec/data_dictionary/dialects/oracle/sql/partitions.sql +44 -0
- sqlspec/data_dictionary/dialects/oracle/sql/routines.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/sequences.sql +21 -0
- sqlspec/data_dictionary/dialects/oracle/sql/source.sql +13 -0
- sqlspec/data_dictionary/dialects/oracle/sql/system.sql +37 -0
- sqlspec/data_dictionary/dialects/oracle/sql/tables.sql +48 -0
- sqlspec/data_dictionary/dialects/oracle/sql/triggers.sql +29 -0
- sqlspec/data_dictionary/dialects/oracle/sql/version.sql +25 -0
- sqlspec/data_dictionary/dialects/oracle/sql/views.sql +49 -0
- sqlspec/data_dictionary/dialects/postgres/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/postgres/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/postgres/config.py +119 -0
- sqlspec/data_dictionary/dialects/postgres/sql/columns.sql +130 -0
- sqlspec/data_dictionary/dialects/postgres/sql/comments.sql +27 -0
- sqlspec/data_dictionary/dialects/postgres/sql/constraints.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/ddl.sql +55 -0
- sqlspec/data_dictionary/dialects/postgres/sql/dependencies.sql +42 -0
- sqlspec/data_dictionary/dialects/postgres/sql/extensions.sql +11 -0
- sqlspec/data_dictionary/dialects/postgres/sql/foreign_keys.sql +72 -0
- sqlspec/data_dictionary/dialects/postgres/sql/indexes.sql +84 -0
- sqlspec/data_dictionary/dialects/postgres/sql/materialized_views.sql +17 -0
- sqlspec/data_dictionary/dialects/postgres/sql/objects.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/partitions.sql +19 -0
- sqlspec/data_dictionary/dialects/postgres/sql/privileges.sql +29 -0
- sqlspec/data_dictionary/dialects/postgres/sql/routines.sql +25 -0
- sqlspec/data_dictionary/dialects/postgres/sql/schemas.sql +13 -0
- sqlspec/data_dictionary/dialects/postgres/sql/sequences.sql +32 -0
- sqlspec/data_dictionary/dialects/postgres/sql/system.sql +53 -0
- sqlspec/data_dictionary/dialects/postgres/sql/tables.sql +67 -0
- sqlspec/data_dictionary/dialects/postgres/sql/triggers.sql +20 -0
- sqlspec/data_dictionary/dialects/postgres/sql/types.sql +21 -0
- sqlspec/data_dictionary/dialects/postgres/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/postgres/sql/views.sql +17 -0
- sqlspec/data_dictionary/dialects/snowflake/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/snowflake/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/snowflake/config.py +321 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/columns.sql +48 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/constraints.sql +64 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/ddl.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/foreign_keys.sql +7 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/objects.sql +34 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/routines.sql +79 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/schemas.sql +19 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/sequences.sql +45 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/tables.sql +29 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/snowflake/sql/views.sql +37 -0
- sqlspec/data_dictionary/dialects/spanner/__init__.py +5 -0
- sqlspec/data_dictionary/dialects/spanner/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/spanner/config.py +67 -0
- sqlspec/data_dictionary/dialects/spanner/sql/columns.sql +58 -0
- sqlspec/data_dictionary/dialects/spanner/sql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/columns.sql +46 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/database.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/indexes.sql +66 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/placements.sql +8 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/privileges.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/property_graphs.sql +11 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/routines.sql +33 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/tables.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/googlesql/views.sql +13 -0
- sqlspec/data_dictionary/dialects/spanner/sql/indexes.sql +30 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/change_streams.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/columns.sql +34 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/constraints.sql +63 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/foreign_keys.sql +91 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/indexes.sql +52 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/objects.sql +10 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/sequences.sql +14 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/system.sql +28 -0
- sqlspec/data_dictionary/dialects/spanner/sql/postgresql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/spanner/sql/tables.sql +9 -0
- sqlspec/data_dictionary/dialects/spanner/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/config.py +191 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/columns.sql +97 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/constraints.sql +43 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/indexes.sql +39 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/objects.sql +18 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/schemas.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/tables.sql +86 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlanywhere/sql/views.sql +15 -0
- sqlspec/data_dictionary/dialects/sqlite/__init__.py +19 -0
- sqlspec/data_dictionary/dialects/sqlite/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sqlite/config.py +412 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/columns.sql +59 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/compile_options.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/constraints.sql +67 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/ddl.sql +37 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/foreign_keys.sql +45 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/functions.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/indexes.sql +76 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/modules.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/objects.sql +13 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/schemas.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/system.sql +7 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/tables.sql +64 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/triggers.sql +10 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sqlite/sql/views.sql +10 -0
- sqlspec/data_dictionary/dialects/sybase/__init__.py +31 -0
- sqlspec/data_dictionary/dialects/sybase/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/sybase/config.py +187 -0
- sqlspec/data_dictionary/dialects/sybase/sql/columns.sql +137 -0
- sqlspec/data_dictionary/dialects/sybase/sql/constraints.sql +85 -0
- sqlspec/data_dictionary/dialects/sybase/sql/foreign_keys.sql +81 -0
- sqlspec/data_dictionary/dialects/sybase/sql/indexes.sql +51 -0
- sqlspec/data_dictionary/dialects/sybase/sql/objects.sql +21 -0
- sqlspec/data_dictionary/dialects/sybase/sql/schemas.sql +16 -0
- sqlspec/data_dictionary/dialects/sybase/sql/tables.sql +46 -0
- sqlspec/data_dictionary/dialects/sybase/sql/version.sql +3 -0
- sqlspec/data_dictionary/dialects/sybase/sql/views.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/__init__.py +33 -0
- sqlspec/data_dictionary/dialects/teradata/config.cp315-win_amd64.pyd +0 -0
- sqlspec/data_dictionary/dialects/teradata/config.py +228 -0
- sqlspec/data_dictionary/dialects/teradata/sql/columns.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/constraints.sql +19 -0
- sqlspec/data_dictionary/dialects/teradata/sql/foreign_keys.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/indexes.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/objects.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/schemas.sql +9 -0
- sqlspec/data_dictionary/dialects/teradata/sql/tables.sql +22 -0
- sqlspec/data_dictionary/dialects/teradata/sql/version.sql +4 -0
- sqlspec/data_dictionary/dialects/teradata/sql/views.sql +4 -0
- sqlspec/dialects/__init__.py +44 -0
- sqlspec/dialects/db2/__init__.py +111 -0
- sqlspec/dialects/db2/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_generators.py +376 -0
- sqlspec/dialects/db2/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_parsers.py +657 -0
- sqlspec/dialects/db2/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/db2/_transforms.py +175 -0
- sqlspec/dialects/postgres/__init__.py +10 -0
- sqlspec/dialects/postgres/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_generators.py +81 -0
- sqlspec/dialects/postgres/_operators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/postgres/_operators.py +95 -0
- sqlspec/dialects/postgres/_paradedb.py +44 -0
- sqlspec/dialects/postgres/_pg_textsearch.py +38 -0
- sqlspec/dialects/postgres/_pgvector.py +36 -0
- sqlspec/dialects/spanner/__init__.py +69 -0
- sqlspec/dialects/spanner/_expressions.py +247 -0
- sqlspec/dialects/spanner/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_generators.py +961 -0
- sqlspec/dialects/spanner/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/spanner/_parsers.py +871 -0
- sqlspec/dialects/spanner/_spangres.py +43 -0
- sqlspec/dialects/spanner/_spanner.py +57 -0
- sqlspec/dialects/sybase/__init__.py +115 -0
- sqlspec/dialects/sybase/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_generators.py +379 -0
- sqlspec/dialects/sybase/_parsers.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_parsers.py +225 -0
- sqlspec/dialects/sybase/_transforms.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/sybase/_transforms.py +68 -0
- sqlspec/dialects/teradata/__init__.py +42 -0
- sqlspec/dialects/teradata/_generators.cp315-win_amd64.pyd +0 -0
- sqlspec/dialects/teradata/_generators.py +203 -0
- sqlspec/driver/__init__.py +151 -0
- sqlspec/driver/_async.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_async.py +3244 -0
- sqlspec/driver/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_common.py +4765 -0
- sqlspec/driver/_deferred.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_deferred.py +232 -0
- sqlspec/driver/_exception_handler.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_exception_handler.py +224 -0
- sqlspec/driver/_routing.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_routing.py +2891 -0
- sqlspec/driver/_session.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_session.py +180 -0
- sqlspec/driver/_sql_helpers.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sql_helpers.py +140 -0
- sqlspec/driver/_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_stream.py +392 -0
- sqlspec/driver/_sync.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_sync.py +3107 -0
- sqlspec/driver/_tenant.cp315-win_amd64.pyd +0 -0
- sqlspec/driver/_tenant.py +326 -0
- sqlspec/exceptions.cp315-win_amd64.pyd +0 -0
- sqlspec/exceptions.py +568 -0
- sqlspec/extensions/__init__.py +3 -0
- sqlspec/extensions/adk/__init__.py +136 -0
- sqlspec/extensions/adk/_config_utils.py +306 -0
- sqlspec/extensions/adk/_table_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_table_utils.py +126 -0
- sqlspec/extensions/adk/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/_types.py +59 -0
- sqlspec/extensions/adk/artifact/__init__.py +18 -0
- sqlspec/extensions/adk/artifact/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/artifact/_types.py +41 -0
- sqlspec/extensions/adk/artifact/service.py +657 -0
- sqlspec/extensions/adk/artifact/store.py +444 -0
- sqlspec/extensions/adk/converters.py +230 -0
- sqlspec/extensions/adk/maintenance.py +262 -0
- sqlspec/extensions/adk/memory/__init__.py +36 -0
- sqlspec/extensions/adk/memory/_types.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/adk/memory/_types.py +48 -0
- sqlspec/extensions/adk/memory/converters.py +271 -0
- sqlspec/extensions/adk/memory/service.py +474 -0
- sqlspec/extensions/adk/memory/store.py +586 -0
- sqlspec/extensions/adk/migrations/0001_create_adk_tables.py +181 -0
- sqlspec/extensions/adk/migrations/0002_create_mssql_python_memory.py +51 -0
- sqlspec/extensions/adk/migrations/__init__.py +3 -0
- sqlspec/extensions/adk/migrations/reconcile.py +282 -0
- sqlspec/extensions/adk/service.py +463 -0
- sqlspec/extensions/adk/store.py +1239 -0
- sqlspec/extensions/events/__init__.py +132 -0
- sqlspec/extensions/events/_buffer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_buffer.py +38 -0
- sqlspec/extensions/events/_channel.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_channel.py +1144 -0
- sqlspec/extensions/events/_hints.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_hints.py +38 -0
- sqlspec/extensions/events/_models.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_models.py +22 -0
- sqlspec/extensions/events/_names.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_names.py +27 -0
- sqlspec/extensions/events/_payload.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_payload.py +139 -0
- sqlspec/extensions/events/_protocols.py +154 -0
- sqlspec/extensions/events/_queue.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/_queue.py +1147 -0
- sqlspec/extensions/events/_store.py +318 -0
- sqlspec/extensions/events/migrations/0001_create_event_queue.py +106 -0
- sqlspec/extensions/events/migrations/__init__.py +3 -0
- sqlspec/extensions/events/migrations/reconcile.py +145 -0
- sqlspec/extensions/events/primitives.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/events/primitives.py +91 -0
- sqlspec/extensions/fastapi/__init__.py +26 -0
- sqlspec/extensions/fastapi/extension.py +360 -0
- sqlspec/extensions/fastapi/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/fastapi/providers.py +1091 -0
- sqlspec/extensions/flask/__init__.py +20 -0
- sqlspec/extensions/flask/_portal.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_portal.py +212 -0
- sqlspec/extensions/flask/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_state.py +135 -0
- sqlspec/extensions/flask/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/flask/_utils.py +171 -0
- sqlspec/extensions/flask/extension.py +1234 -0
- sqlspec/extensions/litestar/__init__.py +52 -0
- sqlspec/extensions/litestar/_tenant_resolution.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_tenant_resolution.py +314 -0
- sqlspec/extensions/litestar/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/_utils.py +222 -0
- sqlspec/extensions/litestar/channels.py +249 -0
- sqlspec/extensions/litestar/cli.py +100 -0
- sqlspec/extensions/litestar/config.py +5 -0
- sqlspec/extensions/litestar/handlers.py +796 -0
- sqlspec/extensions/litestar/migrations/0001_create_session_table.py +138 -0
- sqlspec/extensions/litestar/migrations/__init__.py +3 -0
- sqlspec/extensions/litestar/migrations/reconcile.py +132 -0
- sqlspec/extensions/litestar/plugin.py +2172 -0
- sqlspec/extensions/litestar/providers.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/litestar/providers.py +1239 -0
- sqlspec/extensions/litestar/store.py +613 -0
- sqlspec/extensions/litestar/tenant.py +292 -0
- sqlspec/extensions/otel/__init__.py +58 -0
- sqlspec/extensions/prometheus/__init__.py +5 -0
- sqlspec/extensions/prometheus/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/prometheus/_observer.py +152 -0
- sqlspec/extensions/sanic/__init__.py +28 -0
- sqlspec/extensions/sanic/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_state.py +102 -0
- sqlspec/extensions/sanic/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/sanic/_utils.py +234 -0
- sqlspec/extensions/sanic/extension.py +1467 -0
- sqlspec/extensions/starlette/__init__.py +31 -0
- sqlspec/extensions/starlette/_state.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_state.py +103 -0
- sqlspec/extensions/starlette/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/extensions/starlette/_utils.py +267 -0
- sqlspec/extensions/starlette/extension.py +691 -0
- sqlspec/extensions/starlette/middleware.py +845 -0
- sqlspec/loader.cp315-win_amd64.pyd +0 -0
- sqlspec/loader.py +1733 -0
- sqlspec/migrations/__init__.py +104 -0
- sqlspec/migrations/_backup.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/_backup.py +36 -0
- sqlspec/migrations/base.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/base.py +1688 -0
- sqlspec/migrations/commands.py +4002 -0
- sqlspec/migrations/context.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/context.py +158 -0
- sqlspec/migrations/fix.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/fix.py +193 -0
- sqlspec/migrations/loaders.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/loaders.py +835 -0
- sqlspec/migrations/runner.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/runner.py +2144 -0
- sqlspec/migrations/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/schema.py +1266 -0
- sqlspec/migrations/squash.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/squash.py +2452 -0
- sqlspec/migrations/templates.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/templates.py +310 -0
- sqlspec/migrations/tracker.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/tracker.py +1529 -0
- sqlspec/migrations/utils.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/utils.py +534 -0
- sqlspec/migrations/validation.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/validation.py +355 -0
- sqlspec/migrations/version.cp315-win_amd64.pyd +0 -0
- sqlspec/migrations/version.py +455 -0
- sqlspec/observability/__init__.py +122 -0
- sqlspec/observability/_common.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_common.py +307 -0
- sqlspec/observability/_config.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_config.py +362 -0
- sqlspec/observability/_diagnostics.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_diagnostics.py +75 -0
- sqlspec/observability/_dispatcher.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_dispatcher.py +320 -0
- sqlspec/observability/_formatters/__init__.py +13 -0
- sqlspec/observability/_formatters/_aws.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_aws.py +90 -0
- sqlspec/observability/_formatters/_azure.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_azure.py +84 -0
- sqlspec/observability/_formatters/_base.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_base.py +40 -0
- sqlspec/observability/_formatters/_gcp.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatters/_gcp.py +119 -0
- sqlspec/observability/_formatting.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_formatting.py +76 -0
- sqlspec/observability/_observer.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_observer.py +445 -0
- sqlspec/observability/_runtime.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_runtime.py +740 -0
- sqlspec/observability/_sampling.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_sampling.py +169 -0
- sqlspec/observability/_spans.cp315-win_amd64.pyd +0 -0
- sqlspec/observability/_spans.py +212 -0
- sqlspec/protocols.py +1235 -0
- sqlspec/py.typed +0 -0
- sqlspec/service/__init__.py +5 -0
- sqlspec/service/_base.py +1051 -0
- sqlspec/service/_core.cp315-win_amd64.pyd +0 -0
- sqlspec/service/_core.py +625 -0
- sqlspec/storage/__init__.py +111 -0
- sqlspec/storage/_arrow_payload.py +802 -0
- sqlspec/storage/_arrow_stream.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_arrow_stream.py +134 -0
- sqlspec/storage/_ingest.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_ingest.py +810 -0
- sqlspec/storage/_paths.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_paths.py +313 -0
- sqlspec/storage/_staging_sql.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_staging_sql.py +695 -0
- sqlspec/storage/_utils.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/_utils.py +174 -0
- sqlspec/storage/backends/__init__.py +43 -0
- sqlspec/storage/backends/base.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/base.py +399 -0
- sqlspec/storage/backends/fsspec.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/fsspec.py +1390 -0
- sqlspec/storage/backends/local.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/local.py +968 -0
- sqlspec/storage/backends/obstore.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/backends/obstore.py +1974 -0
- sqlspec/storage/errors.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/errors.py +127 -0
- sqlspec/storage/pipeline.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/pipeline.py +1270 -0
- sqlspec/storage/registry.cp315-win_amd64.pyd +0 -0
- sqlspec/storage/registry.py +318 -0
- sqlspec/typing.py +261 -0
- sqlspec/utils/__init__.py +9 -0
- sqlspec/utils/adapters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/adapters.py +186 -0
- sqlspec/utils/arrow_helpers.py +2157 -0
- sqlspec/utils/config_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/config_tools.py +712 -0
- sqlspec/utils/correlation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/correlation.py +137 -0
- sqlspec/utils/deprecation.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/deprecation.py +222 -0
- sqlspec/utils/dispatch.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/dispatch.py +104 -0
- sqlspec/utils/env.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/env.py +437 -0
- sqlspec/utils/fixtures.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/fixtures.py +2470 -0
- sqlspec/utils/logging.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/logging.py +267 -0
- sqlspec/utils/module_loader.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/module_loader.py +399 -0
- sqlspec/utils/portal.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/portal.py +411 -0
- sqlspec/utils/routing.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/routing.py +645 -0
- sqlspec/utils/schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/schema.py +1050 -0
- sqlspec/utils/serializers/__init__.py +69 -0
- sqlspec/utils/serializers/_json.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_json.py +525 -0
- sqlspec/utils/serializers/_numpy.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_numpy.py +65 -0
- sqlspec/utils/serializers/_schema.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/serializers/_schema.py +340 -0
- sqlspec/utils/sync_tools.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/sync_tools.py +502 -0
- sqlspec/utils/tenant/__init__.py +71 -0
- sqlspec/utils/tenant/_context.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_context.py +550 -0
- sqlspec/utils/tenant/_cursor.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_cursor.py +43 -0
- sqlspec/utils/tenant/_mssql.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_mssql.py +189 -0
- sqlspec/utils/tenant/_postgres.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/tenant/_postgres.py +142 -0
- sqlspec/utils/text.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/text.py +317 -0
- sqlspec/utils/type_converters.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_converters.py +220 -0
- sqlspec/utils/type_guards.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/type_guards.py +1505 -0
- sqlspec/utils/uuids.cp315-win_amd64.pyd +0 -0
- sqlspec/utils/uuids.py +263 -0
- sqlspec-0.72.0.dist-info/METADATA +228 -0
- sqlspec-0.72.0.dist-info/RECORD +1144 -0
- sqlspec-0.72.0.dist-info/WHEEL +4 -0
- sqlspec-0.72.0.dist-info/entry_points.txt +13 -0
- sqlspec-0.72.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,1688 @@
|
|
|
1
|
+
"""Base classes for SQLSpec migrations."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import importlib
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
from abc import abstractmethod
|
|
8
|
+
from collections.abc import Mapping, Sequence
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Final, Generic, NotRequired, TypeVar, cast
|
|
11
|
+
|
|
12
|
+
from mypy_extensions import mypyc_attr
|
|
13
|
+
from sqlglot import exp
|
|
14
|
+
from typing_extensions import TypedDict
|
|
15
|
+
|
|
16
|
+
from sqlspec.builder._column import Column
|
|
17
|
+
from sqlspec.builder._ddl import CreateTable, _parse_ddl_identifier, _parse_ddl_table
|
|
18
|
+
from sqlspec.builder._delete import Delete
|
|
19
|
+
from sqlspec.builder._insert import Insert
|
|
20
|
+
from sqlspec.builder._select import Select
|
|
21
|
+
from sqlspec.builder._update import Update
|
|
22
|
+
from sqlspec.exceptions import MigrationError, SQLSpecError, SquashValidationError, with_cause
|
|
23
|
+
from sqlspec.migrations.runner import BaseMigrationRunner, extract_replaces_versions
|
|
24
|
+
from sqlspec.migrations.schema import SchemaTarget
|
|
25
|
+
from sqlspec.migrations.templates import MigrationTemplateSettings, build_template_settings
|
|
26
|
+
from sqlspec.migrations.utils import (
|
|
27
|
+
resolve_default_schema,
|
|
28
|
+
resolve_extension_migration_mode,
|
|
29
|
+
resolve_extension_migrations_path,
|
|
30
|
+
resolve_tracker_schema,
|
|
31
|
+
)
|
|
32
|
+
from sqlspec.migrations.version import parse_version
|
|
33
|
+
from sqlspec.observability._common import resolve_db_system
|
|
34
|
+
from sqlspec.utils.logging import get_logger, log_with_context
|
|
35
|
+
from sqlspec.utils.module_loader import module_to_os_path
|
|
36
|
+
from sqlspec.utils.text import split_qualified_identifier
|
|
37
|
+
|
|
38
|
+
if TYPE_CHECKING:
|
|
39
|
+
from collections.abc import Awaitable
|
|
40
|
+
from collections.abc import Set as AbstractSet
|
|
41
|
+
|
|
42
|
+
from sqlspec.config import DatabaseConfigProtocol
|
|
43
|
+
from sqlspec.observability._runtime import ObservabilityRuntime
|
|
44
|
+
|
|
45
|
+
__all__ = (
|
|
46
|
+
"AppliedMigrationRecord",
|
|
47
|
+
"BaseMigrationCommands",
|
|
48
|
+
"BaseMigrationTracker",
|
|
49
|
+
"ExtensionReconcilerDescriptor",
|
|
50
|
+
"LoadedMigrationMetadata",
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
DriverT = TypeVar("DriverT")
|
|
54
|
+
ConfigT = TypeVar("ConfigT", bound="DatabaseConfigProtocol[Any, Any, Any]")
|
|
55
|
+
|
|
56
|
+
logger = get_logger("sqlspec.migrations.base")
|
|
57
|
+
_MAX_LOCK_NAME_LENGTH: Final[int] = 64
|
|
58
|
+
_LOCK_NAME_HASH_BYTES: Final[int] = 6
|
|
59
|
+
_LOCK_NAME_PREFIX_LENGTH: Final[int] = _MAX_LOCK_NAME_LENGTH - 1 - (_LOCK_NAME_HASH_BYTES * 2)
|
|
60
|
+
_BRIDGE_DRIVER_CLASS_NAMES: Final[frozenset[str]] = frozenset({"AdbcDriver", "ArrowOdbcDriver"})
|
|
61
|
+
_DRIVER_BASE_CLASS_NAMES: Final[frozenset[str]] = frozenset({"SyncDriverAdapterBase", "AsyncDriverAdapterBase"})
|
|
62
|
+
_LEASE_LOCK_DIALECTS: Final[frozenset[str]] = frozenset({
|
|
63
|
+
"oracle",
|
|
64
|
+
"duckdb",
|
|
65
|
+
"spanner",
|
|
66
|
+
"db2",
|
|
67
|
+
"sybase",
|
|
68
|
+
"ase",
|
|
69
|
+
"sqlanywhere",
|
|
70
|
+
"teradata",
|
|
71
|
+
"vantage",
|
|
72
|
+
})
|
|
73
|
+
_UNSUPPORTED_LOCK_DIALECTS: Final[frozenset[str]] = frozenset({"bigquery", "snowflake"})
|
|
74
|
+
_DEFAULT_LOCK_LEASE_SECONDS: Final[int] = 900
|
|
75
|
+
_LEASE_POLL_INTERVAL_SECONDS: Final[float] = 0.25
|
|
76
|
+
_PG_RELATION_GUARD_SQL: Final[str] = (
|
|
77
|
+
"SELECT "
|
|
78
|
+
"c.relkind::text AS relkind, "
|
|
79
|
+
"(COUNT(t.tgrelid) > 0) AS has_user_triggers, "
|
|
80
|
+
"EXISTS (SELECT 1 FROM pg_catalog.pg_rewrite rw WHERE rw.ev_class = c.oid AND rw.rulename <> '_RETURN') "
|
|
81
|
+
"AS has_rules, "
|
|
82
|
+
"pg_catalog.row_security_active(c.oid) AS has_row_security, "
|
|
83
|
+
"(c.relowner = (SELECT r.oid FROM pg_catalog.pg_roles r WHERE r.rolname = current_user) "
|
|
84
|
+
"OR EXISTS (SELECT 1 FROM pg_catalog.pg_roles r WHERE r.oid = c.relowner AND r.rolsuper) "
|
|
85
|
+
"OR (NOT COALESCE((SELECT r.rolsuper FROM pg_catalog.pg_roles r WHERE r.rolname = current_user), false) "
|
|
86
|
+
"AND pg_catalog.pg_has_role(current_user, c.relowner, 'MEMBER'))) "
|
|
87
|
+
"AS owned_by_current_role "
|
|
88
|
+
"FROM pg_catalog.pg_class c "
|
|
89
|
+
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
|
90
|
+
"LEFT JOIN pg_catalog.pg_trigger t ON t.tgrelid = c.oid AND NOT t.tgisinternal "
|
|
91
|
+
"WHERE n.nspname = :schema_name AND c.relname = :table_name "
|
|
92
|
+
"GROUP BY c.oid, c.relkind, c.relowner"
|
|
93
|
+
)
|
|
94
|
+
_PG_RLS_SCHEMA_CHECK_SQL: Final[str] = (
|
|
95
|
+
"SELECT n.nspname::text AS schema_name, c.relname::text AS table_name "
|
|
96
|
+
"FROM pg_catalog.pg_class c "
|
|
97
|
+
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
|
98
|
+
"LEFT JOIN pg_catalog.pg_policy p ON p.polrelid = c.oid "
|
|
99
|
+
"WHERE n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
100
|
+
"AND c.relkind IN ('r', 'p') "
|
|
101
|
+
"GROUP BY n.nspname, c.relname, c.relrowsecurity "
|
|
102
|
+
"HAVING c.relrowsecurity OR COUNT(p.polrelid) > 0"
|
|
103
|
+
)
|
|
104
|
+
_PG_SCHEMA_OMISSIONS_SQL: Final[str] = (
|
|
105
|
+
"SELECT 'grant' AS object_kind, n.nspname::text AS schema_name, c.relname::text AS object_name "
|
|
106
|
+
"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
|
107
|
+
"WHERE (c.relacl IS NOT NULL "
|
|
108
|
+
"OR EXISTS (SELECT 1 FROM pg_catalog.pg_attribute a "
|
|
109
|
+
"WHERE a.attrelid = c.oid AND a.attnum > 0 AND NOT a.attisdropped AND a.attacl IS NOT NULL)) "
|
|
110
|
+
"AND c.relkind IN ('r', 'p', 'v', 'm') "
|
|
111
|
+
"AND n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
112
|
+
"UNION ALL "
|
|
113
|
+
"SELECT 'materialized_view', n.nspname::text, c.relname::text "
|
|
114
|
+
"FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
|
115
|
+
"WHERE c.relkind = 'm' AND n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
116
|
+
"UNION ALL "
|
|
117
|
+
"SELECT 'function', n.nspname::text, p.proname::text "
|
|
118
|
+
"FROM pg_catalog.pg_proc p JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace "
|
|
119
|
+
"WHERE n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
120
|
+
"AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d "
|
|
121
|
+
"WHERE d.objid = p.oid AND d.classid = 'pg_catalog.pg_proc'::regclass AND d.deptype = 'e') "
|
|
122
|
+
"UNION ALL "
|
|
123
|
+
"SELECT 'trigger', n.nspname::text, c.relname::text || '.' || t.tgname::text "
|
|
124
|
+
"FROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid "
|
|
125
|
+
"JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace "
|
|
126
|
+
"WHERE NOT t.tgisinternal AND n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
127
|
+
"UNION ALL "
|
|
128
|
+
"SELECT 'domain', n.nspname::text, ty.typname::text "
|
|
129
|
+
"FROM pg_catalog.pg_type ty JOIN pg_catalog.pg_namespace n ON n.oid = ty.typnamespace "
|
|
130
|
+
"WHERE ty.typtype = 'd' AND n.nspname = COALESCE(CAST(:schema_name AS text), current_schema()) "
|
|
131
|
+
"AND NOT EXISTS (SELECT 1 FROM pg_catalog.pg_depend d "
|
|
132
|
+
"WHERE d.objid = ty.oid AND d.classid = 'pg_catalog.pg_type'::regclass AND d.deptype = 'e')"
|
|
133
|
+
)
|
|
134
|
+
_ORACLE_VPD_POLICY_SQL: Final[str] = (
|
|
135
|
+
"SELECT object_owner AS schema_name, object_name AS table_name, policy_name "
|
|
136
|
+
"FROM all_policies "
|
|
137
|
+
"WHERE object_owner = COALESCE(:schema_name, SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA'))"
|
|
138
|
+
)
|
|
139
|
+
_MSSQL_SECURITY_POLICY_SQL: Final[str] = (
|
|
140
|
+
"SELECT OBJECT_SCHEMA_NAME(p.target_object_id) AS schema_name, "
|
|
141
|
+
"OBJECT_NAME(p.target_object_id) AS table_name, sp.name AS policy_name "
|
|
142
|
+
"FROM sys.security_policies sp "
|
|
143
|
+
"JOIN sys.security_predicates p ON p.object_id = sp.object_id "
|
|
144
|
+
"WHERE sp.is_enabled = 1"
|
|
145
|
+
)
|
|
146
|
+
_MAX_OMITTED_NAMES: Final[int] = 50
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class LoadedMigrationMetadata(TypedDict):
|
|
150
|
+
"""Metadata for a migration loaded from a file.
|
|
151
|
+
|
|
152
|
+
Keyed on ``version`` (file-derived). The ``has_upgrade``, ``has_downgrade``,
|
|
153
|
+
and ``loader`` keys are added by ``load_migration`` after the base metadata
|
|
154
|
+
is built by ``_load_metadata``.
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
version: "str | None"
|
|
158
|
+
"""Sequential or timestamp migration version parsed from the filename or header."""
|
|
159
|
+
description: str
|
|
160
|
+
"""Human-readable migration summary read from the file metadata or filename."""
|
|
161
|
+
file_path: "Path"
|
|
162
|
+
"""Filesystem path to the ``.sql`` or ``.py`` migration script."""
|
|
163
|
+
checksum: str
|
|
164
|
+
"""Hexadecimal digest of the normalized migration source content."""
|
|
165
|
+
content: str
|
|
166
|
+
"""Raw UTF-8 source text of the migration file."""
|
|
167
|
+
transactional: "bool | None"
|
|
168
|
+
"""Explicit per-migration transaction override, or ``None`` to use adapter defaults."""
|
|
169
|
+
schema: NotRequired["str | None"]
|
|
170
|
+
"""Optional session schema directive parsed from ``-- schema: <name>``."""
|
|
171
|
+
replaces: NotRequired[list[str]]
|
|
172
|
+
"""Prior migration version identifiers superseded by this squashed revision."""
|
|
173
|
+
has_upgrade: NotRequired[bool]
|
|
174
|
+
"""Whether the migration defines an executable upgrade step."""
|
|
175
|
+
has_downgrade: NotRequired[bool]
|
|
176
|
+
"""Whether the migration defines a reversible downgrade step."""
|
|
177
|
+
loader: NotRequired[Any]
|
|
178
|
+
"""Migration loader instance responsible for executing this script."""
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
class AppliedMigrationRecord(TypedDict):
|
|
182
|
+
"""Row from the migration tracking table.
|
|
183
|
+
|
|
184
|
+
Keyed on ``version_num`` (database column), unlike file-loaded metadata
|
|
185
|
+
which keys on ``version``.
|
|
186
|
+
"""
|
|
187
|
+
|
|
188
|
+
version_num: str
|
|
189
|
+
"""Applied migration version identifier stored in ``ddl_migrations``."""
|
|
190
|
+
version_type: str
|
|
191
|
+
"""Persisted migration version format (``sequential`` or ``timestamp``)."""
|
|
192
|
+
execution_sequence: int
|
|
193
|
+
"""Monotonic ordinal recording the order in which migrations were applied."""
|
|
194
|
+
description: str
|
|
195
|
+
"""Migration description persisted when the version was applied."""
|
|
196
|
+
applied_at: Any
|
|
197
|
+
"""Timestamp recording when the migration completed."""
|
|
198
|
+
execution_time_ms: int
|
|
199
|
+
"""Wall-clock execution duration of the upgrade step in milliseconds."""
|
|
200
|
+
checksum: str
|
|
201
|
+
"""Content digest recorded at apply time for drift detection."""
|
|
202
|
+
applied_by: "str | None"
|
|
203
|
+
"""Database user or OS/git actor recorded when applying the migration."""
|
|
204
|
+
replaces: "str | None"
|
|
205
|
+
"""Comma-separated prior version identifiers superseded by a squashed migration."""
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
209
|
+
class BaseMigrationTracker(Generic[DriverT]):
|
|
210
|
+
"""Base class for migration version tracking."""
|
|
211
|
+
|
|
212
|
+
_POSTGRES_LOCK_DIALECTS: "ClassVar[frozenset[str]]" = frozenset({
|
|
213
|
+
"postgres",
|
|
214
|
+
"postgresql",
|
|
215
|
+
"pgvector",
|
|
216
|
+
"paradedb",
|
|
217
|
+
"pg_textsearch",
|
|
218
|
+
})
|
|
219
|
+
_MYSQL_LOCK_DIALECTS: "ClassVar[frozenset[str]]" = frozenset({"mysql", "mariadb"})
|
|
220
|
+
_MSSQL_LOCK_DIALECTS: "ClassVar[frozenset[str]]" = frozenset({"mssql", "tsql"})
|
|
221
|
+
_SEQUENCED_INSERT_DIALECTS: "ClassVar[frozenset[str]]" = frozenset({
|
|
222
|
+
*_POSTGRES_LOCK_DIALECTS,
|
|
223
|
+
*_MYSQL_LOCK_DIALECTS,
|
|
224
|
+
"sqlite",
|
|
225
|
+
"duckdb",
|
|
226
|
+
})
|
|
227
|
+
_MSSQL_ACQUIRE_LOCK_SQL: "ClassVar[str]" = (
|
|
228
|
+
"DECLARE @sqlspec_res INT; "
|
|
229
|
+
"EXEC @sqlspec_res = sp_getapplock :lock_name, 'Exclusive', 'Session', :timeout_ms; "
|
|
230
|
+
"IF @sqlspec_res < 0 THROW 51000, 'Migration lock acquisition failed', 1; "
|
|
231
|
+
"SELECT @sqlspec_res"
|
|
232
|
+
)
|
|
233
|
+
_MSSQL_RELEASE_LOCK_SQL: "ClassVar[str]" = "EXEC sp_releaseapplock :lock_name, 'Session'"
|
|
234
|
+
|
|
235
|
+
def __init__(
|
|
236
|
+
self,
|
|
237
|
+
version_table_name: str = "ddl_migrations",
|
|
238
|
+
version_table_schema: str | None = None,
|
|
239
|
+
lock_lease_seconds: int = _DEFAULT_LOCK_LEASE_SECONDS,
|
|
240
|
+
) -> None:
|
|
241
|
+
"""Initialize the migration tracker.
|
|
242
|
+
|
|
243
|
+
``version_table_name`` may include a ``"schema.table"`` prefix for adapters
|
|
244
|
+
that historically embedded the schema in the table name. When both that
|
|
245
|
+
prefix and ``version_table_schema`` are supplied and agree, the prefix is
|
|
246
|
+
stripped so the qualified table is not double-prefixed.
|
|
247
|
+
|
|
248
|
+
Args:
|
|
249
|
+
version_table_name: Name of the table to track migrations.
|
|
250
|
+
version_table_schema: Optional schema that stores the tracking table.
|
|
251
|
+
lock_lease_seconds: Lease length for backends that lock through a lease row.
|
|
252
|
+
|
|
253
|
+
Raises:
|
|
254
|
+
MigrationError: If ``lock_lease_seconds`` is below 1 or the schemas conflict.
|
|
255
|
+
"""
|
|
256
|
+
if lock_lease_seconds < 1:
|
|
257
|
+
msg = f"lock_lease_seconds must be at least 1, got {lock_lease_seconds}"
|
|
258
|
+
raise MigrationError(msg)
|
|
259
|
+
self.lock_lease_seconds = lock_lease_seconds
|
|
260
|
+
parsed_table = _parse_ddl_table(version_table_name)
|
|
261
|
+
table_identifier = (
|
|
262
|
+
parsed_table.this
|
|
263
|
+
if isinstance(parsed_table.this, exp.Identifier)
|
|
264
|
+
else _parse_ddl_identifier(version_table_name)
|
|
265
|
+
)
|
|
266
|
+
embedded_db = parsed_table.args.get("db")
|
|
267
|
+
embedded_schema_identifier = embedded_db if isinstance(embedded_db, exp.Identifier) else None
|
|
268
|
+
|
|
269
|
+
clean_schema = version_table_schema.strip() if isinstance(version_table_schema, str) else ""
|
|
270
|
+
explicit_schema_identifier = _parse_ddl_identifier(clean_schema) if clean_schema else None
|
|
271
|
+
if explicit_schema_identifier is not None:
|
|
272
|
+
schemas_conflict = False
|
|
273
|
+
if embedded_schema_identifier is not None:
|
|
274
|
+
if embedded_schema_identifier.quoted or explicit_schema_identifier.quoted:
|
|
275
|
+
schemas_conflict = explicit_schema_identifier.name != embedded_schema_identifier.name
|
|
276
|
+
else:
|
|
277
|
+
schemas_conflict = (
|
|
278
|
+
explicit_schema_identifier.name.lower() != embedded_schema_identifier.name.lower()
|
|
279
|
+
)
|
|
280
|
+
if schemas_conflict and embedded_schema_identifier is not None:
|
|
281
|
+
msg = (
|
|
282
|
+
f"Conflicting migration version table schemas: '{embedded_schema_identifier.name}' in "
|
|
283
|
+
f"version_table_name '{version_table_name}' vs explicit version_table_schema "
|
|
284
|
+
f"'{explicit_schema_identifier.name}'"
|
|
285
|
+
)
|
|
286
|
+
raise MigrationError(msg)
|
|
287
|
+
if (
|
|
288
|
+
embedded_schema_identifier is not None
|
|
289
|
+
and explicit_schema_identifier.name == embedded_schema_identifier.name
|
|
290
|
+
and embedded_schema_identifier.quoted
|
|
291
|
+
and not explicit_schema_identifier.quoted
|
|
292
|
+
):
|
|
293
|
+
resolved_schema_identifier: exp.Identifier | None = embedded_schema_identifier
|
|
294
|
+
else:
|
|
295
|
+
resolved_schema_identifier = explicit_schema_identifier
|
|
296
|
+
else:
|
|
297
|
+
resolved_schema_identifier = embedded_schema_identifier
|
|
298
|
+
|
|
299
|
+
self.version_table_name = table_identifier.name
|
|
300
|
+
self._version_table_sql = table_identifier.sql(copy=False)
|
|
301
|
+
self._version_table_quoted = bool(table_identifier.quoted)
|
|
302
|
+
self.version_table_schema = resolved_schema_identifier.name if resolved_schema_identifier is not None else None
|
|
303
|
+
self.version_table = self._qualify_version_table(
|
|
304
|
+
table_identifier.sql(copy=False),
|
|
305
|
+
resolved_schema_identifier.sql(copy=False) if resolved_schema_identifier is not None else None,
|
|
306
|
+
)
|
|
307
|
+
self._version_table_schema_quoted = bool(
|
|
308
|
+
resolved_schema_identifier is not None and resolved_schema_identifier.quoted
|
|
309
|
+
)
|
|
310
|
+
self._configured_version_table = self.version_table
|
|
311
|
+
self._configured_version_table_schema = self.version_table_schema
|
|
312
|
+
self._configured_version_table_schema_quoted = self._version_table_schema_quoted
|
|
313
|
+
self._output_policy = {"use_logger": False, "echo": True, "summary_only": False}
|
|
314
|
+
self._sqlite_lock_owners: set[int] = set()
|
|
315
|
+
self._lease_owners: dict[int, tuple[str, str]] = {}
|
|
316
|
+
self._unsupported_lock_warned = False
|
|
317
|
+
|
|
318
|
+
def _pin_version_table_schema(self, schema_name: str) -> None:
|
|
319
|
+
"""Bind the tracking table to an explicit schema.
|
|
320
|
+
|
|
321
|
+
Args:
|
|
322
|
+
schema_name: Schema that stores the tracking table.
|
|
323
|
+
"""
|
|
324
|
+
schema_identifier = exp.to_identifier(schema_name, quoted=True if schema_name != schema_name.lower() else None)
|
|
325
|
+
self.version_table_schema = schema_name
|
|
326
|
+
self._version_table_schema_quoted = bool(schema_identifier.quoted)
|
|
327
|
+
self.version_table = self._qualify_version_table(self._version_table_sql, schema_identifier.sql(copy=False))
|
|
328
|
+
|
|
329
|
+
def _reset_version_table_schema(self) -> None:
|
|
330
|
+
"""Restore the tracking table name and schema captured at construction."""
|
|
331
|
+
self.version_table = self._configured_version_table
|
|
332
|
+
self.version_table_schema = self._configured_version_table_schema
|
|
333
|
+
self._version_table_schema_quoted = self._configured_version_table_schema_quoted
|
|
334
|
+
|
|
335
|
+
def _pg_relation_guard_parameters(self) -> "dict[str, str]":
|
|
336
|
+
"""Return the bind parameters of the PostgreSQL tracking relation guard.
|
|
337
|
+
|
|
338
|
+
Unquoted identifiers are folded to lowercase, matching how PostgreSQL stores them in the catalog.
|
|
339
|
+
"""
|
|
340
|
+
schema_name = self.version_table_schema or ""
|
|
341
|
+
if not self._version_table_schema_quoted:
|
|
342
|
+
schema_name = schema_name.lower()
|
|
343
|
+
table_name = self.version_table_name
|
|
344
|
+
if not self._version_table_quoted:
|
|
345
|
+
table_name = table_name.lower()
|
|
346
|
+
return {"schema_name": schema_name, "table_name": table_name}
|
|
347
|
+
|
|
348
|
+
def set_output_policy(self, *, use_logger: bool, echo: bool, summary_only: bool) -> None:
|
|
349
|
+
"""Set output policy for tracker console/logging behavior."""
|
|
350
|
+
self._output_policy = {"use_logger": use_logger, "echo": echo, "summary_only": summary_only}
|
|
351
|
+
|
|
352
|
+
def holds_transaction_scoped_lock(self, driver: Any) -> bool:
|
|
353
|
+
"""Return True while this tracker owns an outer SQLite transaction lock on ``driver``."""
|
|
354
|
+
return id(driver) in self._sqlite_lock_owners
|
|
355
|
+
|
|
356
|
+
@abstractmethod
|
|
357
|
+
def ensure_tracking_table(self, driver: DriverT) -> "Awaitable[None] | None":
|
|
358
|
+
"""Create the migration tracking table if it doesn't exist.
|
|
359
|
+
|
|
360
|
+
Implementations should also check for and add any missing columns
|
|
361
|
+
to support schema migrations from older versions.
|
|
362
|
+
"""
|
|
363
|
+
...
|
|
364
|
+
|
|
365
|
+
@abstractmethod
|
|
366
|
+
def get_current_version(self, driver: DriverT) -> "str | Awaitable[str | None] | None":
|
|
367
|
+
"""Get the latest applied migration version."""
|
|
368
|
+
...
|
|
369
|
+
|
|
370
|
+
@abstractmethod
|
|
371
|
+
def get_applied_migrations(
|
|
372
|
+
self, driver: DriverT
|
|
373
|
+
) -> "list[AppliedMigrationRecord] | Awaitable[list[AppliedMigrationRecord]]":
|
|
374
|
+
"""Get all applied migrations in order."""
|
|
375
|
+
...
|
|
376
|
+
|
|
377
|
+
@abstractmethod
|
|
378
|
+
def record_migration(
|
|
379
|
+
self,
|
|
380
|
+
driver: DriverT,
|
|
381
|
+
version: str,
|
|
382
|
+
description: str,
|
|
383
|
+
execution_time_ms: int,
|
|
384
|
+
checksum: str,
|
|
385
|
+
*,
|
|
386
|
+
commit: bool = True,
|
|
387
|
+
) -> "Awaitable[None] | None":
|
|
388
|
+
"""Record a successfully applied migration."""
|
|
389
|
+
...
|
|
390
|
+
|
|
391
|
+
@abstractmethod
|
|
392
|
+
def remove_migration(self, driver: DriverT, version: str, *, commit: bool = True) -> "Awaitable[None] | None":
|
|
393
|
+
"""Remove a migration record."""
|
|
394
|
+
...
|
|
395
|
+
|
|
396
|
+
def catalog_schema_name(self) -> "str | None":
|
|
397
|
+
"""Return the tracking table's schema in the form data dictionary getters accept.
|
|
398
|
+
|
|
399
|
+
Returns:
|
|
400
|
+
Schema name for metadata lookups, or None when the table is unqualified.
|
|
401
|
+
"""
|
|
402
|
+
return self.version_table_schema
|
|
403
|
+
|
|
404
|
+
@staticmethod
|
|
405
|
+
def _split_version_table(version_table_name: str) -> "tuple[str, str | None]":
|
|
406
|
+
"""Split a ``schema.table`` value into unquoted ``(table, schema)`` names."""
|
|
407
|
+
parsed_table = _parse_ddl_table(version_table_name)
|
|
408
|
+
table_identifier = (
|
|
409
|
+
parsed_table.this
|
|
410
|
+
if isinstance(parsed_table.this, exp.Identifier)
|
|
411
|
+
else _parse_ddl_identifier(version_table_name)
|
|
412
|
+
)
|
|
413
|
+
embedded_db = parsed_table.args.get("db")
|
|
414
|
+
schema_name = embedded_db.name if isinstance(embedded_db, exp.Identifier) else None
|
|
415
|
+
return table_identifier.name, schema_name or None
|
|
416
|
+
|
|
417
|
+
def _qualify_version_table(self, version_table_name: str, version_table_schema: str | None) -> str:
|
|
418
|
+
"""Return the tracker table name, qualified with schema when configured."""
|
|
419
|
+
if version_table_schema:
|
|
420
|
+
return f"{version_table_schema}.{version_table_name}"
|
|
421
|
+
return version_table_name
|
|
422
|
+
|
|
423
|
+
def _tracking_schema_target(self) -> SchemaTarget:
|
|
424
|
+
"""Return the schema target that compares the tracking table's columns with its DDL.
|
|
425
|
+
|
|
426
|
+
Returns:
|
|
427
|
+
Target naming the tracking table for introspection and additive DDL.
|
|
428
|
+
"""
|
|
429
|
+
return SchemaTarget(self.version_table, self._tracking_table_ddl())
|
|
430
|
+
|
|
431
|
+
def _tracking_table_builder(self) -> "CreateTable":
|
|
432
|
+
"""Return a CREATE TABLE builder for the tracker table."""
|
|
433
|
+
return CreateTable(self.version_table)
|
|
434
|
+
|
|
435
|
+
def _should_echo(self) -> bool:
|
|
436
|
+
"""Return True when console output should be emitted."""
|
|
437
|
+
return bool(self._output_policy.get("echo", True)) and not bool(self._output_policy.get("use_logger", False))
|
|
438
|
+
|
|
439
|
+
def _tracking_table_ddl(self) -> "CreateTable":
|
|
440
|
+
"""Get SQL builder for creating the tracking table.
|
|
441
|
+
|
|
442
|
+
Schema includes both legacy and new versioning columns:
|
|
443
|
+
- version_num: Migration version (sequential or timestamp format)
|
|
444
|
+
- version_type: Format indicator ('sequential' or 'timestamp')
|
|
445
|
+
- execution_sequence: Auto-incrementing application order
|
|
446
|
+
- description: Human-readable migration description
|
|
447
|
+
- applied_at: Timestamp when migration was applied
|
|
448
|
+
- execution_time_ms: Migration execution duration
|
|
449
|
+
- checksum: SHA-256 hex digest for content verification
|
|
450
|
+
- applied_by: User who applied the migration
|
|
451
|
+
|
|
452
|
+
Returns:
|
|
453
|
+
SQL builder object for table creation.
|
|
454
|
+
"""
|
|
455
|
+
return (
|
|
456
|
+
self
|
|
457
|
+
._tracking_table_builder()
|
|
458
|
+
.if_not_exists()
|
|
459
|
+
.column("version_num", "VARCHAR(32)", primary_key=True)
|
|
460
|
+
.column("version_type", "VARCHAR(16)")
|
|
461
|
+
.column("execution_sequence", "INTEGER")
|
|
462
|
+
.column("description", "TEXT")
|
|
463
|
+
.column("applied_at", "TIMESTAMP", default="CURRENT_TIMESTAMP", not_null=True)
|
|
464
|
+
.column("execution_time_ms", "INTEGER")
|
|
465
|
+
.column("checksum", "VARCHAR(64)")
|
|
466
|
+
.column("applied_by", "VARCHAR(255)")
|
|
467
|
+
.column("replaces", "TEXT")
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
def _current_version_query(self) -> "Select":
|
|
471
|
+
"""Get SQL builder for retrieving current version.
|
|
472
|
+
|
|
473
|
+
Uses execution_sequence to get the last applied migration,
|
|
474
|
+
which may differ from version_num order due to out-of-order migrations.
|
|
475
|
+
|
|
476
|
+
Returns:
|
|
477
|
+
SQL builder object for version query.
|
|
478
|
+
"""
|
|
479
|
+
return Select("version_num").from_(self.version_table).order_by("execution_sequence DESC").limit(1)
|
|
480
|
+
|
|
481
|
+
def _applied_migrations_query(self) -> "Select":
|
|
482
|
+
"""Get SQL builder for retrieving all applied migrations.
|
|
483
|
+
|
|
484
|
+
Orders by execution_sequence to show migrations in application order,
|
|
485
|
+
which preserves the actual execution history for out-of-order migrations.
|
|
486
|
+
|
|
487
|
+
Returns:
|
|
488
|
+
SQL builder object for migrations query.
|
|
489
|
+
"""
|
|
490
|
+
return Select("*").from_(self.version_table).order_by("execution_sequence")
|
|
491
|
+
|
|
492
|
+
def _next_execution_sequence_query(self) -> "Select":
|
|
493
|
+
"""Get SQL builder for retrieving next execution sequence.
|
|
494
|
+
|
|
495
|
+
Returns:
|
|
496
|
+
SQL builder object for sequence query.
|
|
497
|
+
"""
|
|
498
|
+
return Select("COALESCE(MAX(execution_sequence), 0) + 1 AS next_seq").from_(self.version_table)
|
|
499
|
+
|
|
500
|
+
def _record_migration_statement(
|
|
501
|
+
self,
|
|
502
|
+
version: str,
|
|
503
|
+
version_type: str,
|
|
504
|
+
execution_sequence: int,
|
|
505
|
+
description: str,
|
|
506
|
+
execution_time_ms: int,
|
|
507
|
+
checksum: str,
|
|
508
|
+
applied_by: str,
|
|
509
|
+
) -> "Insert":
|
|
510
|
+
"""Get SQL builder for recording a migration.
|
|
511
|
+
|
|
512
|
+
Args:
|
|
513
|
+
version: Version number of the migration.
|
|
514
|
+
version_type: Version format type ('sequential' or 'timestamp').
|
|
515
|
+
execution_sequence: Auto-incrementing application order.
|
|
516
|
+
description: Description of the migration.
|
|
517
|
+
execution_time_ms: Execution time in milliseconds.
|
|
518
|
+
checksum: SHA-256 checksum hex string of the migration content.
|
|
519
|
+
applied_by: User who applied the migration.
|
|
520
|
+
|
|
521
|
+
Returns:
|
|
522
|
+
SQL builder object for insert.
|
|
523
|
+
"""
|
|
524
|
+
return (
|
|
525
|
+
Insert(self.version_table)
|
|
526
|
+
.columns(
|
|
527
|
+
"version_num",
|
|
528
|
+
"version_type",
|
|
529
|
+
"execution_sequence",
|
|
530
|
+
"description",
|
|
531
|
+
"execution_time_ms",
|
|
532
|
+
"checksum",
|
|
533
|
+
"applied_by",
|
|
534
|
+
)
|
|
535
|
+
.values(version, version_type, execution_sequence, description, execution_time_ms, checksum, applied_by)
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
def _remove_migration_statement(self, version: str) -> "Delete":
|
|
539
|
+
"""Get SQL builder for removing a migration record.
|
|
540
|
+
|
|
541
|
+
Args:
|
|
542
|
+
version: Version number to remove.
|
|
543
|
+
|
|
544
|
+
Returns:
|
|
545
|
+
SQL builder object for delete.
|
|
546
|
+
"""
|
|
547
|
+
return Delete().from_(self.version_table).where(Column("version_num") == version)
|
|
548
|
+
|
|
549
|
+
def _update_version_statement(self, old_version: str, new_version: str, new_version_type: str) -> "Update":
|
|
550
|
+
"""Get SQL builder for updating version record.
|
|
551
|
+
|
|
552
|
+
Updates version_num and version_type while preserving execution_sequence,
|
|
553
|
+
applied_at, and other metadata. Used during fix command to convert
|
|
554
|
+
timestamp versions to sequential format.
|
|
555
|
+
|
|
556
|
+
Args:
|
|
557
|
+
old_version: Current version string.
|
|
558
|
+
new_version: New version string.
|
|
559
|
+
new_version_type: New version type ('sequential' or 'timestamp').
|
|
560
|
+
|
|
561
|
+
Returns:
|
|
562
|
+
SQL builder object for update.
|
|
563
|
+
"""
|
|
564
|
+
return (
|
|
565
|
+
Update(self.version_table)
|
|
566
|
+
.set("version_num", new_version)
|
|
567
|
+
.set("version_type", new_version_type)
|
|
568
|
+
.where(Column("version_num") == old_version)
|
|
569
|
+
)
|
|
570
|
+
|
|
571
|
+
def _update_checksum_statement(self, version: str, checksum: str) -> "Update":
|
|
572
|
+
"""Get SQL builder for replacing the recorded checksum of one version.
|
|
573
|
+
|
|
574
|
+
Args:
|
|
575
|
+
version: Version whose checksum is replaced.
|
|
576
|
+
checksum: New checksum hex string.
|
|
577
|
+
|
|
578
|
+
Returns:
|
|
579
|
+
SQL builder object for update.
|
|
580
|
+
"""
|
|
581
|
+
return Update(self.version_table).set("checksum", checksum).where(Column("version_num") == version)
|
|
582
|
+
|
|
583
|
+
def _delete_versions_statement(self, versions: "list[str]") -> "Delete":
|
|
584
|
+
"""Get SQL builder for deleting multiple version records.
|
|
585
|
+
|
|
586
|
+
Used by squash operations to remove replaced migration records.
|
|
587
|
+
|
|
588
|
+
Args:
|
|
589
|
+
versions: List of version strings to delete.
|
|
590
|
+
|
|
591
|
+
Returns:
|
|
592
|
+
SQL builder object for delete.
|
|
593
|
+
"""
|
|
594
|
+
return Delete().from_(self.version_table).where(Column("version_num").in_(versions))
|
|
595
|
+
|
|
596
|
+
def _check_versions_query(self, versions: "list[str]") -> "Select":
|
|
597
|
+
"""Get SQL builder for checking whether any versions exist.
|
|
598
|
+
|
|
599
|
+
Args:
|
|
600
|
+
versions: List of version strings to check.
|
|
601
|
+
|
|
602
|
+
Returns:
|
|
603
|
+
SQL builder object for version existence query.
|
|
604
|
+
"""
|
|
605
|
+
return Select("version_num").from_(self.version_table).where(Column("version_num").in_(versions))
|
|
606
|
+
|
|
607
|
+
def _record_squashed_migration_statement(
|
|
608
|
+
self,
|
|
609
|
+
version: str,
|
|
610
|
+
version_type: str,
|
|
611
|
+
execution_sequence: int,
|
|
612
|
+
description: str,
|
|
613
|
+
execution_time_ms: int,
|
|
614
|
+
checksum: str,
|
|
615
|
+
applied_by: str,
|
|
616
|
+
replaces: str,
|
|
617
|
+
) -> "Insert":
|
|
618
|
+
"""Get SQL builder for recording a squashed migration.
|
|
619
|
+
|
|
620
|
+
Args:
|
|
621
|
+
version: Version number of the squashed migration.
|
|
622
|
+
version_type: Version format type ('sequential' or 'timestamp').
|
|
623
|
+
execution_sequence: Auto-incrementing application order.
|
|
624
|
+
description: Description of the migration.
|
|
625
|
+
execution_time_ms: Execution time in milliseconds.
|
|
626
|
+
checksum: SHA-256 checksum hex string of the migration content.
|
|
627
|
+
applied_by: User who applied the migration.
|
|
628
|
+
replaces: Comma-separated list of replaced versions.
|
|
629
|
+
|
|
630
|
+
Returns:
|
|
631
|
+
SQL builder object for insert.
|
|
632
|
+
"""
|
|
633
|
+
return (
|
|
634
|
+
Insert(self.version_table)
|
|
635
|
+
.columns(
|
|
636
|
+
"version_num",
|
|
637
|
+
"version_type",
|
|
638
|
+
"execution_sequence",
|
|
639
|
+
"description",
|
|
640
|
+
"execution_time_ms",
|
|
641
|
+
"checksum",
|
|
642
|
+
"applied_by",
|
|
643
|
+
"replaces",
|
|
644
|
+
)
|
|
645
|
+
.values(
|
|
646
|
+
version,
|
|
647
|
+
version_type,
|
|
648
|
+
execution_sequence,
|
|
649
|
+
description,
|
|
650
|
+
execution_time_ms,
|
|
651
|
+
checksum,
|
|
652
|
+
applied_by,
|
|
653
|
+
replaces,
|
|
654
|
+
)
|
|
655
|
+
)
|
|
656
|
+
|
|
657
|
+
def _record_sequenced_migration_statement(
|
|
658
|
+
self,
|
|
659
|
+
version: str,
|
|
660
|
+
version_type: str,
|
|
661
|
+
description: str,
|
|
662
|
+
execution_time_ms: int,
|
|
663
|
+
checksum: str,
|
|
664
|
+
applied_by: str,
|
|
665
|
+
replaces: str | None = None,
|
|
666
|
+
) -> "Insert":
|
|
667
|
+
"""Get SQL builder for atomically inserting a migration record with next sequence."""
|
|
668
|
+
columns: list[str] = [
|
|
669
|
+
"version_num",
|
|
670
|
+
"version_type",
|
|
671
|
+
"execution_sequence",
|
|
672
|
+
"description",
|
|
673
|
+
"execution_time_ms",
|
|
674
|
+
"checksum",
|
|
675
|
+
"applied_by",
|
|
676
|
+
]
|
|
677
|
+
select_query = Select()
|
|
678
|
+
_, version_param = select_query.add_parameter(version, name="version_num")
|
|
679
|
+
_, type_param = select_query.add_parameter(version_type, name="version_type")
|
|
680
|
+
_, desc_param = select_query.add_parameter(description, name="description")
|
|
681
|
+
_, duration_param = select_query.add_parameter(execution_time_ms, name="execution_time_ms")
|
|
682
|
+
_, checksum_param = select_query.add_parameter(checksum, name="checksum")
|
|
683
|
+
_, actor_param = select_query.add_parameter(applied_by, name="applied_by")
|
|
684
|
+
projections: list[exp.Expr] = [
|
|
685
|
+
exp.Placeholder(this=version_param),
|
|
686
|
+
exp.Placeholder(this=type_param),
|
|
687
|
+
exp.column("next_seq", table="seq_src"),
|
|
688
|
+
exp.Placeholder(this=desc_param),
|
|
689
|
+
exp.Placeholder(this=duration_param),
|
|
690
|
+
exp.Placeholder(this=checksum_param),
|
|
691
|
+
exp.Placeholder(this=actor_param),
|
|
692
|
+
]
|
|
693
|
+
if replaces is not None:
|
|
694
|
+
columns.append("replaces")
|
|
695
|
+
_, replaces_param = select_query.add_parameter(replaces, name="replaces")
|
|
696
|
+
projections.append(exp.Placeholder(this=replaces_param))
|
|
697
|
+
next_seq_subquery = Select("COALESCE(MAX(execution_sequence), 0) + 1 AS next_seq").from_(self.version_table)
|
|
698
|
+
select_query = select_query.select(*projections).from_(next_seq_subquery, alias="seq_src")
|
|
699
|
+
return Insert(self.version_table).columns(*columns).from_select(select_query)
|
|
700
|
+
|
|
701
|
+
@property
|
|
702
|
+
def lock_table(self) -> str:
|
|
703
|
+
"""Return the qualified name of the lease lock table."""
|
|
704
|
+
lock_identifier = exp.to_identifier(
|
|
705
|
+
f"{self.version_table_name}_lock", quoted=self._version_table_quoted or None
|
|
706
|
+
)
|
|
707
|
+
schema_sql: str | None = None
|
|
708
|
+
if self.version_table_schema:
|
|
709
|
+
schema_sql = exp.to_identifier(
|
|
710
|
+
self.version_table_schema,
|
|
711
|
+
quoted=True if self.version_table_schema != self.version_table_schema.lower() else None,
|
|
712
|
+
).sql(copy=False)
|
|
713
|
+
return self._qualify_version_table(lock_identifier.sql(copy=False), schema_sql)
|
|
714
|
+
|
|
715
|
+
def _warn_unsupported_lock(self, driver: Any) -> None:
|
|
716
|
+
"""Log once per tracker that the backend cannot serialize migrations."""
|
|
717
|
+
if self._unsupported_lock_warned:
|
|
718
|
+
return
|
|
719
|
+
self._unsupported_lock_warned = True
|
|
720
|
+
log_with_context(
|
|
721
|
+
logger, logging.WARNING, "migration.lock.unsupported", db_system=resolve_db_system(type(driver).__name__)
|
|
722
|
+
)
|
|
723
|
+
|
|
724
|
+
def _lock_table_builder(self) -> "CreateTable":
|
|
725
|
+
"""Return a CREATE TABLE builder for the lease lock table."""
|
|
726
|
+
return CreateTable(self.lock_table)
|
|
727
|
+
|
|
728
|
+
def _lock_schema_target(self) -> SchemaTarget:
|
|
729
|
+
"""Return the schema target that creates the lease lock table.
|
|
730
|
+
|
|
731
|
+
Returns:
|
|
732
|
+
Target describing ``lock_name``, ``owner_token``, and ``expires_at`` (epoch milliseconds).
|
|
733
|
+
"""
|
|
734
|
+
create_table = (
|
|
735
|
+
self
|
|
736
|
+
._lock_table_builder()
|
|
737
|
+
.column("lock_name", "VARCHAR(64)", primary_key=True, not_null=True)
|
|
738
|
+
.column("owner_token", "VARCHAR(64)", not_null=True)
|
|
739
|
+
.column("expires_at", "BIGINT", not_null=True)
|
|
740
|
+
)
|
|
741
|
+
return SchemaTarget(self.lock_table, create_table)
|
|
742
|
+
|
|
743
|
+
def _lease_delete_expired(self, lock_name: str, now_ms: int) -> "Delete":
|
|
744
|
+
"""Get SQL builder deleting an expired lease for ``lock_name``."""
|
|
745
|
+
return (
|
|
746
|
+
Delete().from_(self.lock_table).where(Column("lock_name") == lock_name).where(Column("expires_at") < now_ms)
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
def _lease_insert(self, lock_name: str, owner_token: str, expires_at: int) -> "Insert":
|
|
750
|
+
"""Get SQL builder inserting a lease row."""
|
|
751
|
+
return (
|
|
752
|
+
Insert(self.lock_table)
|
|
753
|
+
.columns("lock_name", "owner_token", "expires_at")
|
|
754
|
+
.values(lock_name, owner_token, expires_at)
|
|
755
|
+
)
|
|
756
|
+
|
|
757
|
+
def _lease_renew(self, lock_name: str, owner_token: str, expires_at: int) -> "Update":
|
|
758
|
+
"""Get SQL builder extending a held lease."""
|
|
759
|
+
return (
|
|
760
|
+
Update(self.lock_table)
|
|
761
|
+
.set("expires_at", expires_at)
|
|
762
|
+
.where(Column("lock_name") == lock_name)
|
|
763
|
+
.where(Column("owner_token") == owner_token)
|
|
764
|
+
)
|
|
765
|
+
|
|
766
|
+
def _lease_release(self, lock_name: str, owner_token: str) -> "Delete":
|
|
767
|
+
"""Get SQL builder releasing a held lease."""
|
|
768
|
+
return (
|
|
769
|
+
Delete()
|
|
770
|
+
.from_(self.lock_table)
|
|
771
|
+
.where(Column("lock_name") == lock_name)
|
|
772
|
+
.where(Column("owner_token") == owner_token)
|
|
773
|
+
)
|
|
774
|
+
|
|
775
|
+
def _lease_owner_query(self, lock_name: str) -> "Select":
|
|
776
|
+
"""Get SQL builder reading the current holder of a lease."""
|
|
777
|
+
return Select("owner_token", "expires_at").from_(self.lock_table).where(Column("lock_name") == lock_name)
|
|
778
|
+
|
|
779
|
+
@staticmethod
|
|
780
|
+
def _lease_holder(result: Any) -> "tuple[str, int] | None":
|
|
781
|
+
"""Return the owner token and expiry of the lease row in ``result``, or None when no row exists."""
|
|
782
|
+
for row in result.get_data():
|
|
783
|
+
values = {str(key).lower(): value for key, value in row.items()}
|
|
784
|
+
return str(values["owner_token"]), int(values["expires_at"])
|
|
785
|
+
return None
|
|
786
|
+
|
|
787
|
+
def _migration_lock_key(self) -> "tuple[str, int]":
|
|
788
|
+
"""Derive the bounded lock name and signed 64-bit integer advisory lock ID."""
|
|
789
|
+
raw_key = f"sqlspec_mig_{self._configured_version_table}"
|
|
790
|
+
digest = hashlib.sha256(raw_key.encode("utf-8")).digest()
|
|
791
|
+
lock_name = (
|
|
792
|
+
raw_key
|
|
793
|
+
if len(raw_key) <= _MAX_LOCK_NAME_LENGTH
|
|
794
|
+
else f"{raw_key[:_LOCK_NAME_PREFIX_LENGTH]}_{digest[:_LOCK_NAME_HASH_BYTES].hex()}"
|
|
795
|
+
)
|
|
796
|
+
lock_id = int.from_bytes(digest[:8], "big", signed=True)
|
|
797
|
+
return lock_name, lock_id
|
|
798
|
+
|
|
799
|
+
@classmethod
|
|
800
|
+
def _resolve_lock_backend(cls, driver: Any) -> str:
|
|
801
|
+
"""Classify ``driver`` into its migration lock backend family.
|
|
802
|
+
|
|
803
|
+
The dialect is the driver class value, or the instance value for driver adapters whose
|
|
804
|
+
dialect is stored per instance.
|
|
805
|
+
|
|
806
|
+
Returns:
|
|
807
|
+
``"postgres"``, ``"mysql"``, ``"mssql"``, ``"sqlite"``, ``"lease"`` for backends locking
|
|
808
|
+
through a lease row, ``"unsupported"`` for backends that cannot be serialized, or an empty
|
|
809
|
+
string for an unknown dialect.
|
|
810
|
+
"""
|
|
811
|
+
driver_type = type(driver)
|
|
812
|
+
base_names = {base.__name__ for base in driver_type.__mro__}
|
|
813
|
+
is_bridge_driver = not base_names.isdisjoint(_BRIDGE_DRIVER_CLASS_NAMES)
|
|
814
|
+
raw_dialect = getattr(driver_type, "dialect", None)
|
|
815
|
+
if is_bridge_driver or (
|
|
816
|
+
not isinstance(raw_dialect, str) and not base_names.isdisjoint(_DRIVER_BASE_CLASS_NAMES)
|
|
817
|
+
):
|
|
818
|
+
raw_dialect = getattr(driver, "dialect", None)
|
|
819
|
+
dialect = raw_dialect.lower() if isinstance(raw_dialect, str) else ""
|
|
820
|
+
if _is_cockroach_driver(driver):
|
|
821
|
+
return "lease"
|
|
822
|
+
if not dialect:
|
|
823
|
+
return ""
|
|
824
|
+
if dialect in cls._POSTGRES_LOCK_DIALECTS:
|
|
825
|
+
return "postgres"
|
|
826
|
+
if dialect in cls._MYSQL_LOCK_DIALECTS:
|
|
827
|
+
return "mysql"
|
|
828
|
+
if dialect in cls._MSSQL_LOCK_DIALECTS:
|
|
829
|
+
return "mssql"
|
|
830
|
+
if dialect == "sqlite":
|
|
831
|
+
return "lease" if is_bridge_driver else "sqlite"
|
|
832
|
+
if dialect in _LEASE_LOCK_DIALECTS:
|
|
833
|
+
return "lease"
|
|
834
|
+
if dialect in _UNSUPPORTED_LOCK_DIALECTS:
|
|
835
|
+
return "unsupported"
|
|
836
|
+
return ""
|
|
837
|
+
|
|
838
|
+
def _uses_sequenced_insert(self, driver: Any) -> bool:
|
|
839
|
+
"""Return True when ``driver`` uses single-statement ``execution_sequence`` inserts."""
|
|
840
|
+
return str(getattr(driver, "dialect", "") or "").lower() in self._SEQUENCED_INSERT_DIALECTS
|
|
841
|
+
|
|
842
|
+
@staticmethod
|
|
843
|
+
def _translate_mssql_lock_exception(
|
|
844
|
+
lock_name: str, timeout_seconds: int, exc: SQLSpecError
|
|
845
|
+
) -> MigrationError | None:
|
|
846
|
+
"""Convert T-SQL lock acquisition errors into ``MigrationError`` when matched."""
|
|
847
|
+
if "Migration lock acquisition failed" in str(exc):
|
|
848
|
+
msg = f"Failed to acquire SQL Server migration lock {lock_name!r} within {timeout_seconds}s"
|
|
849
|
+
return MigrationError(msg)
|
|
850
|
+
return None
|
|
851
|
+
|
|
852
|
+
@staticmethod
|
|
853
|
+
def _validate_mssql_lock_result(lock_name: str, result: Any) -> None:
|
|
854
|
+
"""Raise ``MigrationError`` when ``sp_getapplock`` returns a negative status code."""
|
|
855
|
+
if result.data:
|
|
856
|
+
lock_code = result.scalar()
|
|
857
|
+
if isinstance(lock_code, int) and lock_code < 0:
|
|
858
|
+
msg = f"Failed to acquire SQL Server migration lock {lock_name!r} (code {lock_code})"
|
|
859
|
+
raise MigrationError(msg)
|
|
860
|
+
|
|
861
|
+
@staticmethod
|
|
862
|
+
def _validate_mysql_lock_result(lock_name: str, timeout_seconds: int, lock_result: Any) -> None:
|
|
863
|
+
"""Raise ``MigrationError`` when MySQL ``GET_LOCK`` does not acquire ownership."""
|
|
864
|
+
if lock_result != 1:
|
|
865
|
+
msg = f"Failed to acquire MySQL migration lock {lock_name!r} within {timeout_seconds}s"
|
|
866
|
+
raise MigrationError(msg)
|
|
867
|
+
|
|
868
|
+
def _detect_missing_columns(self, existing_columns: "set[str]") -> "set[str]":
|
|
869
|
+
"""Detect which columns are missing from the current schema.
|
|
870
|
+
|
|
871
|
+
Args:
|
|
872
|
+
existing_columns: Set of existing column names (may be uppercase/lowercase).
|
|
873
|
+
|
|
874
|
+
Returns:
|
|
875
|
+
Set of missing column names (lowercase).
|
|
876
|
+
"""
|
|
877
|
+
target_create = self._tracking_table_ddl()
|
|
878
|
+
target_columns = {col.name.lower() for col in target_create.columns}
|
|
879
|
+
existing_lower = {col.lower() for col in existing_columns}
|
|
880
|
+
return target_columns - existing_lower
|
|
881
|
+
|
|
882
|
+
def _derive_version_type(self, version: str) -> str:
|
|
883
|
+
"""Return the version-format type ('sequential' or 'timestamp') for a version."""
|
|
884
|
+
return parse_version(version).type.value
|
|
885
|
+
|
|
886
|
+
def _applied_by(self) -> str:
|
|
887
|
+
"""Return the user recorded as having applied a migration."""
|
|
888
|
+
return os.environ.get("USER", "unknown")
|
|
889
|
+
|
|
890
|
+
def _extract_next_sequence(self, result: Any) -> int:
|
|
891
|
+
"""Return the next execution sequence from a sequence-query result."""
|
|
892
|
+
return result.get_data()[0]["next_seq"] if result.data else 1
|
|
893
|
+
|
|
894
|
+
def _extract_applied_versions(self, result: Any) -> "set[str]":
|
|
895
|
+
"""Return the set of applied version numbers from a query result."""
|
|
896
|
+
return {row["version_num"] for row in result.get_data()} if result.data else set()
|
|
897
|
+
|
|
898
|
+
def _is_autocommit_error(self, exc: Exception) -> bool:
|
|
899
|
+
"""Return True when an exception indicates an autocommit-managed transaction."""
|
|
900
|
+
exc_str = str(exc).lower()
|
|
901
|
+
return "autocommit" in exc_str or "cannot commit" in exc_str
|
|
902
|
+
|
|
903
|
+
|
|
904
|
+
class ExtensionReconcilerDescriptor:
|
|
905
|
+
"""Immutable descriptor locating an opted-in extension reconciler module."""
|
|
906
|
+
|
|
907
|
+
__slots__ = ("module_path", "name")
|
|
908
|
+
|
|
909
|
+
def __init__(self, name: str, module_path: Path) -> None:
|
|
910
|
+
self.name = name
|
|
911
|
+
self.module_path = module_path
|
|
912
|
+
|
|
913
|
+
def __eq__(self, other: object) -> bool:
|
|
914
|
+
if not isinstance(other, ExtensionReconcilerDescriptor):
|
|
915
|
+
return NotImplemented
|
|
916
|
+
return self.name == other.name and self.module_path == other.module_path
|
|
917
|
+
|
|
918
|
+
def __hash__(self) -> int:
|
|
919
|
+
return hash((self.name, self.module_path))
|
|
920
|
+
|
|
921
|
+
def __repr__(self) -> str:
|
|
922
|
+
return f"ExtensionReconcilerDescriptor(name={self.name!r}, module_path={self.module_path!r})"
|
|
923
|
+
|
|
924
|
+
|
|
925
|
+
@mypyc_attr(allow_interpreted_subclasses=True)
|
|
926
|
+
class BaseMigrationCommands(Generic[ConfigT, DriverT]):
|
|
927
|
+
"""Base class for migration commands."""
|
|
928
|
+
|
|
929
|
+
extension_configs: "dict[str, dict[str, Any]]"
|
|
930
|
+
extension_reconcilers: "tuple[ExtensionReconcilerDescriptor, ...]"
|
|
931
|
+
_resolved_extension_dirs: "dict[str, Path | None]"
|
|
932
|
+
|
|
933
|
+
def __init__(self, config: ConfigT) -> None:
|
|
934
|
+
"""Initialize migration commands.
|
|
935
|
+
|
|
936
|
+
Args:
|
|
937
|
+
config: The SQLSpec configuration.
|
|
938
|
+
"""
|
|
939
|
+
if getattr(config, "is_replica", False):
|
|
940
|
+
msg = "Migrations cannot run against a read replica configuration; use the primary configuration instead"
|
|
941
|
+
raise MigrationError(msg)
|
|
942
|
+
raw_features = getattr(config, "driver_features", None)
|
|
943
|
+
driver_features = raw_features if isinstance(raw_features, dict) else {}
|
|
944
|
+
direct_dsn = driver_features.get("direct_dsn")
|
|
945
|
+
derive_fn = getattr(config, "derive_direct_config", None)
|
|
946
|
+
if isinstance(direct_dsn, str) and direct_dsn and callable(derive_fn):
|
|
947
|
+
config = cast("ConfigT", derive_fn())
|
|
948
|
+
self.config = config
|
|
949
|
+
if self.config.driver_features.get("tenant_strategy") is not None:
|
|
950
|
+
msg = "Migrations cannot use tenant_strategy; use a separate configuration without tenant_strategy"
|
|
951
|
+
raise MigrationError(msg)
|
|
952
|
+
migration_config = self._get_migration_config()
|
|
953
|
+
|
|
954
|
+
self.version_table = migration_config.get("version_table_name", "ddl_migrations")
|
|
955
|
+
self.migrations_path = Path(migration_config.get("script_location", "migrations"))
|
|
956
|
+
raw_project_root = migration_config.get("project_root")
|
|
957
|
+
self.project_root = Path(raw_project_root) if raw_project_root is not None else None
|
|
958
|
+
self.include_extensions = migration_config.get("include_extensions", [])
|
|
959
|
+
self.extension_configs = self._parse_extension_configs()
|
|
960
|
+
self._resolved_extension_dirs = {}
|
|
961
|
+
self.extension_reconcilers = self._discover_extension_reconcilers()
|
|
962
|
+
self._template_settings: MigrationTemplateSettings = build_template_settings(migration_config)
|
|
963
|
+
self._runtime: ObservabilityRuntime | None = self.config.get_observability_runtime()
|
|
964
|
+
self._last_command_error: Exception | None = None
|
|
965
|
+
self._last_command_metrics: dict[str, float] | None = None
|
|
966
|
+
|
|
967
|
+
def init_directory(self, directory: str, package: bool = True) -> None:
|
|
968
|
+
"""Initialize migration directory structure without overwriting existing files.
|
|
969
|
+
|
|
970
|
+
Args:
|
|
971
|
+
directory: Directory to initialize migrations in.
|
|
972
|
+
package: Whether to create __init__.py file.
|
|
973
|
+
|
|
974
|
+
Raises:
|
|
975
|
+
MigrationError: If target initialization files already exist.
|
|
976
|
+
"""
|
|
977
|
+
console = importlib.import_module("rich.console").Console()
|
|
978
|
+
|
|
979
|
+
migrations_dir = Path(directory)
|
|
980
|
+
init = migrations_dir / "__init__.py"
|
|
981
|
+
readme = migrations_dir / "README.md"
|
|
982
|
+
targets = (init, readme) if package else (readme,)
|
|
983
|
+
existing = [path for path in targets if path.exists()]
|
|
984
|
+
if existing:
|
|
985
|
+
existing_display = ", ".join(str(path) for path in existing)
|
|
986
|
+
msg = f"Refusing to overwrite existing migration file(s): {existing_display}"
|
|
987
|
+
raise MigrationError(msg)
|
|
988
|
+
|
|
989
|
+
migrations_dir.mkdir(parents=True, exist_ok=True)
|
|
990
|
+
|
|
991
|
+
if package:
|
|
992
|
+
init.write_text(self._get_init_init_content(), encoding="utf-8")
|
|
993
|
+
|
|
994
|
+
readme.write_text(self._get_init_readme_content(), encoding="utf-8")
|
|
995
|
+
|
|
996
|
+
use_logger, echo, summary_only = self._resolve_output_policy(False, None, None)
|
|
997
|
+
if echo and not use_logger:
|
|
998
|
+
console.print(f"[green]Initialized migrations in {directory}[/]")
|
|
999
|
+
elif use_logger and not summary_only:
|
|
1000
|
+
logger.info("Initialized migrations in %s", directory)
|
|
1001
|
+
|
|
1002
|
+
@abstractmethod
|
|
1003
|
+
def init(self, directory: str, package: bool = True) -> "Awaitable[None] | None":
|
|
1004
|
+
"""Initialize migration directory structure."""
|
|
1005
|
+
...
|
|
1006
|
+
|
|
1007
|
+
@abstractmethod
|
|
1008
|
+
def current(self, verbose: bool = False) -> "str | Awaitable[str | None] | None":
|
|
1009
|
+
"""Show current migration version."""
|
|
1010
|
+
...
|
|
1011
|
+
|
|
1012
|
+
@abstractmethod
|
|
1013
|
+
def upgrade(self, revision: str = "head") -> "Awaitable[None] | None":
|
|
1014
|
+
"""Upgrade to a target revision."""
|
|
1015
|
+
...
|
|
1016
|
+
|
|
1017
|
+
@abstractmethod
|
|
1018
|
+
def downgrade(self, revision: str = "-1") -> "Awaitable[None] | None":
|
|
1019
|
+
"""Downgrade to a target revision."""
|
|
1020
|
+
...
|
|
1021
|
+
|
|
1022
|
+
@abstractmethod
|
|
1023
|
+
def stamp(self, revision: str) -> "Awaitable[None] | None":
|
|
1024
|
+
"""Mark database as being at a specific revision without running migrations."""
|
|
1025
|
+
...
|
|
1026
|
+
|
|
1027
|
+
@abstractmethod
|
|
1028
|
+
def revision(
|
|
1029
|
+
self,
|
|
1030
|
+
message: str,
|
|
1031
|
+
file_type: str | None = None,
|
|
1032
|
+
*,
|
|
1033
|
+
from_schema: bool = False,
|
|
1034
|
+
from_data: "str | Path | None" = None,
|
|
1035
|
+
schema: str | None = None,
|
|
1036
|
+
target_table: str | None = None,
|
|
1037
|
+
) -> "Path | Awaitable[Path]":
|
|
1038
|
+
"""Create a new migration file."""
|
|
1039
|
+
...
|
|
1040
|
+
|
|
1041
|
+
def _get_migration_config(self) -> "dict[str, Any]":
|
|
1042
|
+
"""Return migration config as a plain dictionary."""
|
|
1043
|
+
return cast("dict[str, Any]", self.config.migration_config) or {}
|
|
1044
|
+
|
|
1045
|
+
def _resolve_default_schema(self) -> str | None:
|
|
1046
|
+
"""Return the configured default migration schema."""
|
|
1047
|
+
return resolve_default_schema(self._get_migration_config())
|
|
1048
|
+
|
|
1049
|
+
def _config_supports_schemas(self) -> bool:
|
|
1050
|
+
"""Return whether the bound config opts into schema-aware migrations."""
|
|
1051
|
+
return bool(getattr(self.config, "supports_migration_schemas", False))
|
|
1052
|
+
|
|
1053
|
+
def _resolve_tracker_schema(self) -> str | None:
|
|
1054
|
+
"""Return the tracker schema, rejecting schema options the adapter cannot honor.
|
|
1055
|
+
|
|
1056
|
+
Returns:
|
|
1057
|
+
The tracker schema, or None when no schema applies.
|
|
1058
|
+
|
|
1059
|
+
Raises:
|
|
1060
|
+
MigrationError: The adapter lacks schema support and a schema option is configured.
|
|
1061
|
+
"""
|
|
1062
|
+
migration_config = self._get_migration_config()
|
|
1063
|
+
if self._config_supports_schemas():
|
|
1064
|
+
explicit_schema = migration_config.get("version_table_schema")
|
|
1065
|
+
if (
|
|
1066
|
+
not (isinstance(explicit_schema, str) and explicit_schema.strip())
|
|
1067
|
+
and BaseMigrationTracker._split_version_table(self.version_table)[1] is not None
|
|
1068
|
+
):
|
|
1069
|
+
return None
|
|
1070
|
+
return resolve_tracker_schema(migration_config)
|
|
1071
|
+
self._reject_schema_options(migration_config)
|
|
1072
|
+
return None
|
|
1073
|
+
|
|
1074
|
+
def _reject_schema_options(self, migration_config: "dict[str, Any]") -> None:
|
|
1075
|
+
adapter = type(self.config).__name__
|
|
1076
|
+
default_schema = resolve_default_schema(migration_config)
|
|
1077
|
+
if default_schema is not None:
|
|
1078
|
+
msg = (
|
|
1079
|
+
f"{adapter} does not support migration default schemas; "
|
|
1080
|
+
f"remove default_schema={default_schema!r} from migration_config."
|
|
1081
|
+
)
|
|
1082
|
+
raise MigrationError(msg)
|
|
1083
|
+
version_table_schema = migration_config.get("version_table_schema")
|
|
1084
|
+
if isinstance(version_table_schema, str) and version_table_schema:
|
|
1085
|
+
msg = (
|
|
1086
|
+
f"{adapter} does not support migration version table schemas; "
|
|
1087
|
+
f"remove version_table_schema={version_table_schema!r} from migration_config "
|
|
1088
|
+
"or qualify version_table_name with the schema."
|
|
1089
|
+
)
|
|
1090
|
+
raise MigrationError(msg)
|
|
1091
|
+
|
|
1092
|
+
def _create_tracker(self) -> Any:
|
|
1093
|
+
"""Create the configured migration tracker without breaking legacy constructors."""
|
|
1094
|
+
tracker_schema = self._resolve_tracker_schema()
|
|
1095
|
+
lease_seconds = self._get_migration_config().get("lock_lease_seconds")
|
|
1096
|
+
options: dict[str, Any] = {} if lease_seconds is None else {"lock_lease_seconds": lease_seconds}
|
|
1097
|
+
if tracker_schema is None:
|
|
1098
|
+
return self.config.migration_tracker_type(self.version_table, **options)
|
|
1099
|
+
return self.config.migration_tracker_type(self.version_table, version_table_schema=tracker_schema, **options)
|
|
1100
|
+
|
|
1101
|
+
def _parse_extension_configs(self) -> "dict[str, dict[str, Any]]":
|
|
1102
|
+
"""Parse extension configurations from include_extensions.
|
|
1103
|
+
|
|
1104
|
+
Reads extension configuration from config.extension_config for each
|
|
1105
|
+
extension listed in include_extensions.
|
|
1106
|
+
|
|
1107
|
+
Returns:
|
|
1108
|
+
Dictionary mapping extension names to shallow copies of their configurations.
|
|
1109
|
+
"""
|
|
1110
|
+
configs: dict[str, dict[str, Any]] = {}
|
|
1111
|
+
extension_config_map = cast("dict[str, Any]", self.config.extension_config)
|
|
1112
|
+
|
|
1113
|
+
for ext_config in self.include_extensions:
|
|
1114
|
+
if not isinstance(ext_config, str):
|
|
1115
|
+
logger.warning("Extension must be a string name, got: %s", ext_config)
|
|
1116
|
+
continue
|
|
1117
|
+
|
|
1118
|
+
ext_name = ext_config
|
|
1119
|
+
if ext_name in configs:
|
|
1120
|
+
continue
|
|
1121
|
+
raw_options = extension_config_map.get(ext_name, {})
|
|
1122
|
+
configs[ext_name] = dict(raw_options) if isinstance(raw_options, Mapping) else {}
|
|
1123
|
+
|
|
1124
|
+
return configs
|
|
1125
|
+
|
|
1126
|
+
def _resolve_extension_migrations_dir(self, ext_name: str, ext_options: "Mapping[str, Any]") -> "Path | None":
|
|
1127
|
+
"""Resolve the filesystem directory containing migrations for an extension.
|
|
1128
|
+
|
|
1129
|
+
Args:
|
|
1130
|
+
ext_name: Configured extension name.
|
|
1131
|
+
ext_options: Per-extension configuration mapping.
|
|
1132
|
+
|
|
1133
|
+
Raises:
|
|
1134
|
+
MigrationError: Extension explicitly configures ``reconcile`` mode and its migrations directory cannot be resolved.
|
|
1135
|
+
|
|
1136
|
+
Returns:
|
|
1137
|
+
Resolved directory path, or ``None`` when absent without explicit ``reconcile`` mode.
|
|
1138
|
+
"""
|
|
1139
|
+
resolve_extension_migration_mode(None, ext_options, extension_name=ext_name)
|
|
1140
|
+
explicit_reconcile = ext_options.get("migration_mode") == "reconcile"
|
|
1141
|
+
if ext_name in self._resolved_extension_dirs and not explicit_reconcile:
|
|
1142
|
+
return self._resolved_extension_dirs[ext_name]
|
|
1143
|
+
spec = ext_options.get("migrations_path")
|
|
1144
|
+
if spec is not None:
|
|
1145
|
+
resolved = resolve_extension_migrations_path(ext_name, spec)
|
|
1146
|
+
if resolved is None:
|
|
1147
|
+
if explicit_reconcile:
|
|
1148
|
+
msg = (
|
|
1149
|
+
f"Extension '{ext_name}' configured migration_mode='reconcile', "
|
|
1150
|
+
f"but migrations_path {spec!r} is not an existing directory."
|
|
1151
|
+
)
|
|
1152
|
+
raise MigrationError(msg)
|
|
1153
|
+
logger.warning(
|
|
1154
|
+
"Extension '%s' migrations_path %r is not an existing directory; "
|
|
1155
|
+
"no migrations were registered for it.",
|
|
1156
|
+
ext_name,
|
|
1157
|
+
spec,
|
|
1158
|
+
)
|
|
1159
|
+
self._resolved_extension_dirs[ext_name] = None
|
|
1160
|
+
return None
|
|
1161
|
+
self._resolved_extension_dirs[ext_name] = resolved
|
|
1162
|
+
return resolved
|
|
1163
|
+
|
|
1164
|
+
module_name = f"sqlspec.extensions.{ext_name}"
|
|
1165
|
+
try:
|
|
1166
|
+
module_path = module_to_os_path(module_name)
|
|
1167
|
+
except ImportError as exc:
|
|
1168
|
+
if explicit_reconcile:
|
|
1169
|
+
msg = (
|
|
1170
|
+
f"Extension '{ext_name}' configured migration_mode='reconcile', "
|
|
1171
|
+
f"but '{module_name}' could not be imported ({exc}). "
|
|
1172
|
+
f"Set extension_config['{ext_name}']['migrations_path'] to register "
|
|
1173
|
+
"reconcilers shipped by another package."
|
|
1174
|
+
)
|
|
1175
|
+
raise with_cause(MigrationError(msg), exc) from exc
|
|
1176
|
+
logger.warning(
|
|
1177
|
+
"Extension '%s' is configured but '%s' is not importable; no migrations were "
|
|
1178
|
+
"registered for it. Set extension_config['%s']['migrations_path'] to register "
|
|
1179
|
+
"migrations shipped by another package.",
|
|
1180
|
+
ext_name,
|
|
1181
|
+
module_name,
|
|
1182
|
+
ext_name,
|
|
1183
|
+
)
|
|
1184
|
+
self._resolved_extension_dirs[ext_name] = None
|
|
1185
|
+
return None
|
|
1186
|
+
|
|
1187
|
+
migrations_dir = module_path / "migrations"
|
|
1188
|
+
if not migrations_dir.is_dir():
|
|
1189
|
+
if explicit_reconcile:
|
|
1190
|
+
msg = (
|
|
1191
|
+
f"Extension '{ext_name}' configured migration_mode='reconcile', "
|
|
1192
|
+
f"but ships no migrations directory at '{migrations_dir}'."
|
|
1193
|
+
)
|
|
1194
|
+
raise MigrationError(msg)
|
|
1195
|
+
logger.debug("Extension %s ships no migrations directory", ext_name)
|
|
1196
|
+
self._resolved_extension_dirs[ext_name] = None
|
|
1197
|
+
return None
|
|
1198
|
+
|
|
1199
|
+
self._resolved_extension_dirs[ext_name] = migrations_dir
|
|
1200
|
+
return migrations_dir
|
|
1201
|
+
|
|
1202
|
+
def _discover_extension_reconcilers(self) -> "tuple[ExtensionReconcilerDescriptor, ...]":
|
|
1203
|
+
"""Discover extension reconciler modules without importing them.
|
|
1204
|
+
|
|
1205
|
+
Raises:
|
|
1206
|
+
MigrationError: An extension with explicit ``migration_mode='reconcile'`` lacks a ``reconcile.py`` file.
|
|
1207
|
+
|
|
1208
|
+
Returns:
|
|
1209
|
+
Ordered tuple of reconciler descriptors matching ``include_extensions`` order.
|
|
1210
|
+
"""
|
|
1211
|
+
reconcilers: list[ExtensionReconcilerDescriptor] = []
|
|
1212
|
+
for ext_name, ext_options in self.extension_configs.items():
|
|
1213
|
+
mode = resolve_extension_migration_mode(None, ext_options, extension_name=ext_name)
|
|
1214
|
+
if mode != "reconcile":
|
|
1215
|
+
continue
|
|
1216
|
+
explicit_reconcile = ext_options.get("migration_mode") == "reconcile"
|
|
1217
|
+
ext_dir = self._resolve_extension_migrations_dir(ext_name, ext_options)
|
|
1218
|
+
if ext_dir is None:
|
|
1219
|
+
continue
|
|
1220
|
+
reconcile_path = ext_dir / "reconcile.py"
|
|
1221
|
+
if not reconcile_path.is_file():
|
|
1222
|
+
if explicit_reconcile:
|
|
1223
|
+
msg = (
|
|
1224
|
+
f"Extension '{ext_name}' configured migration_mode='reconcile', "
|
|
1225
|
+
f"but no reconcile.py file exists at '{reconcile_path}'."
|
|
1226
|
+
)
|
|
1227
|
+
raise MigrationError(msg)
|
|
1228
|
+
continue
|
|
1229
|
+
reconcilers.append(ExtensionReconcilerDescriptor(ext_name, reconcile_path))
|
|
1230
|
+
return tuple(reconcilers)
|
|
1231
|
+
|
|
1232
|
+
def _retained_reconcile_versions(self, applied_migrations: "Sequence[AppliedMigrationRecord]") -> set[str]:
|
|
1233
|
+
"""Return applied version_num values belonging to extensions currently configured in reconcile mode.
|
|
1234
|
+
|
|
1235
|
+
Args:
|
|
1236
|
+
applied_migrations: Applied migration records from the tracking table.
|
|
1237
|
+
|
|
1238
|
+
Returns:
|
|
1239
|
+
Set of retained ``version_num`` strings belonging to active ``reconcile`` extensions.
|
|
1240
|
+
"""
|
|
1241
|
+
reconcile_names = {descriptor.name for descriptor in self.extension_reconcilers}
|
|
1242
|
+
if not reconcile_names:
|
|
1243
|
+
return set()
|
|
1244
|
+
retained: set[str] = set()
|
|
1245
|
+
for record in applied_migrations:
|
|
1246
|
+
version_num = record["version_num"]
|
|
1247
|
+
try:
|
|
1248
|
+
parsed = parse_version(version_num)
|
|
1249
|
+
except ValueError:
|
|
1250
|
+
continue
|
|
1251
|
+
if parsed.extension in reconcile_names:
|
|
1252
|
+
retained.add(version_num)
|
|
1253
|
+
return retained
|
|
1254
|
+
|
|
1255
|
+
def _applied_checksum_audit(
|
|
1256
|
+
self,
|
|
1257
|
+
applied_migrations: "Sequence[AppliedMigrationRecord]",
|
|
1258
|
+
migration_files: "Sequence[tuple[str, Path]]",
|
|
1259
|
+
*,
|
|
1260
|
+
versions: "AbstractSet[str] | None" = None,
|
|
1261
|
+
) -> "tuple[list[str], dict[str, str]]":
|
|
1262
|
+
"""Compare applied records against the migration files on disk.
|
|
1263
|
+
|
|
1264
|
+
Retained reconcile versions, versions without a file, and squashed files that still await
|
|
1265
|
+
reconciliation of their own version are skipped.
|
|
1266
|
+
|
|
1267
|
+
Args:
|
|
1268
|
+
applied_migrations: Applied migration records from the tracking table.
|
|
1269
|
+
migration_files: Migration files on disk as ``(version, path)`` pairs.
|
|
1270
|
+
versions: Optional subset of applied versions to audit. All applied versions when None.
|
|
1271
|
+
|
|
1272
|
+
Returns:
|
|
1273
|
+
Tuple of the versions whose file no longer matches the recorded checksum and a map of
|
|
1274
|
+
``version -> marker digest`` for records that only match the legacy checksum form.
|
|
1275
|
+
"""
|
|
1276
|
+
files_by_version = dict(migration_files)
|
|
1277
|
+
retained = self._retained_reconcile_versions(applied_migrations)
|
|
1278
|
+
mismatched: list[str] = []
|
|
1279
|
+
rerecord: dict[str, str] = {}
|
|
1280
|
+
for record in applied_migrations:
|
|
1281
|
+
version = record["version_num"]
|
|
1282
|
+
if version in retained or (versions is not None and version not in versions):
|
|
1283
|
+
continue
|
|
1284
|
+
file_path = files_by_version.get(version)
|
|
1285
|
+
if file_path is None:
|
|
1286
|
+
continue
|
|
1287
|
+
content = file_path.read_text(encoding="utf-8")
|
|
1288
|
+
if not record.get("replaces") and version in extract_replaces_versions(content, file_path.suffix):
|
|
1289
|
+
continue
|
|
1290
|
+
match = BaseMigrationRunner.match_migration_checksum(content, str(record.get("checksum") or ""))
|
|
1291
|
+
if match is None:
|
|
1292
|
+
mismatched.append(version)
|
|
1293
|
+
elif match == "legacy":
|
|
1294
|
+
rerecord[version] = hashlib.sha256(
|
|
1295
|
+
BaseMigrationRunner._canonicalize_migration_content(content).encode("utf-8") # pyright: ignore[reportPrivateUsage]
|
|
1296
|
+
).hexdigest()
|
|
1297
|
+
return mismatched, rerecord
|
|
1298
|
+
|
|
1299
|
+
def _discover_extension_migrations(self) -> "dict[str, Path]":
|
|
1300
|
+
"""Discover migration paths for configured versioned extensions.
|
|
1301
|
+
|
|
1302
|
+
An extension may declare ``migrations_path`` in its ``extension_config`` entry to
|
|
1303
|
+
ship migrations from any package. Extensions without it resolve against the
|
|
1304
|
+
``sqlspec.extensions.<name>`` namespace. Extensions resolved as reconcilers
|
|
1305
|
+
are omitted from numbered migration discovery.
|
|
1306
|
+
|
|
1307
|
+
Returns:
|
|
1308
|
+
Dictionary mapping extension names to their migration paths.
|
|
1309
|
+
"""
|
|
1310
|
+
extension_migrations: dict[str, Path] = {}
|
|
1311
|
+
reconcile_names = {descriptor.name for descriptor in self.extension_reconcilers}
|
|
1312
|
+
|
|
1313
|
+
for ext_name, ext_options in self.extension_configs.items():
|
|
1314
|
+
if ext_name in reconcile_names:
|
|
1315
|
+
continue
|
|
1316
|
+
mode = resolve_extension_migration_mode(None, ext_options, extension_name=ext_name)
|
|
1317
|
+
if mode == "reconcile" and ext_options.get("migration_mode") == "reconcile":
|
|
1318
|
+
continue
|
|
1319
|
+
resolved = self._resolve_extension_migrations_dir(ext_name, ext_options)
|
|
1320
|
+
if resolved is not None:
|
|
1321
|
+
extension_migrations[ext_name] = resolved
|
|
1322
|
+
logger.debug("Found migrations for extension %s at %s", ext_name, resolved)
|
|
1323
|
+
|
|
1324
|
+
return extension_migrations
|
|
1325
|
+
|
|
1326
|
+
def _get_init_readme_content(self) -> str:
|
|
1327
|
+
"""Get README content for migration directory initialization.
|
|
1328
|
+
|
|
1329
|
+
Returns:
|
|
1330
|
+
README markdown content.
|
|
1331
|
+
"""
|
|
1332
|
+
return """# SQLSpec Migrations
|
|
1333
|
+
|
|
1334
|
+
This directory contains database migration files.
|
|
1335
|
+
|
|
1336
|
+
## File Format
|
|
1337
|
+
|
|
1338
|
+
Migration files use SQLFileLoader's named query syntax with versioned names:
|
|
1339
|
+
|
|
1340
|
+
```sql
|
|
1341
|
+
-- name: migrate-20251011120000-up
|
|
1342
|
+
CREATE TABLE example (
|
|
1343
|
+
id INTEGER PRIMARY KEY,
|
|
1344
|
+
name TEXT NOT NULL
|
|
1345
|
+
);
|
|
1346
|
+
|
|
1347
|
+
-- name: migrate-20251011120000-down
|
|
1348
|
+
DROP TABLE example;
|
|
1349
|
+
```
|
|
1350
|
+
|
|
1351
|
+
## Naming Conventions
|
|
1352
|
+
|
|
1353
|
+
### File Names
|
|
1354
|
+
|
|
1355
|
+
Format: `{version}_{description}.sql`
|
|
1356
|
+
|
|
1357
|
+
- Version: Timestamp in YYYYMMDDHHmmss format (UTC)
|
|
1358
|
+
- Description: Brief description using underscores
|
|
1359
|
+
- Example: `20251011120000_create_users_table.sql`
|
|
1360
|
+
|
|
1361
|
+
### Query Names
|
|
1362
|
+
|
|
1363
|
+
- Upgrade: `migrate-{version}-up`
|
|
1364
|
+
- Downgrade: `migrate-{version}-down`
|
|
1365
|
+
|
|
1366
|
+
## Version Format
|
|
1367
|
+
|
|
1368
|
+
Migrations use **timestamp-based versioning** (YYYYMMDDHHmmss):
|
|
1369
|
+
|
|
1370
|
+
- **Format**: 14-digit UTC timestamp
|
|
1371
|
+
- **Example**: `20251011120000` (October 11, 2025 at 12:00:00 UTC)
|
|
1372
|
+
- **Benefits**: Eliminates merge conflicts when multiple developers create migrations concurrently
|
|
1373
|
+
|
|
1374
|
+
### Creating Migrations
|
|
1375
|
+
|
|
1376
|
+
Use the CLI to generate timestamped migrations:
|
|
1377
|
+
|
|
1378
|
+
```bash
|
|
1379
|
+
sqlspec create-migration "add user table"
|
|
1380
|
+
# Creates: 20251011120000_add_user_table.sql
|
|
1381
|
+
```
|
|
1382
|
+
|
|
1383
|
+
The timestamp is automatically generated in UTC timezone.
|
|
1384
|
+
|
|
1385
|
+
## Migration Execution
|
|
1386
|
+
|
|
1387
|
+
Migrations are applied in chronological order based on their timestamps.
|
|
1388
|
+
The database tracks both version and execution order separately to handle
|
|
1389
|
+
out-of-order migrations gracefully.
|
|
1390
|
+
"""
|
|
1391
|
+
|
|
1392
|
+
def _get_init_init_content(self) -> str:
|
|
1393
|
+
"""Get __init__.py content for migration directory initialization.
|
|
1394
|
+
|
|
1395
|
+
Returns:
|
|
1396
|
+
Python module docstring content for the __init__.py file.
|
|
1397
|
+
"""
|
|
1398
|
+
return '"""Migrations."""\n'
|
|
1399
|
+
|
|
1400
|
+
def _record_command_metric(self, name: str, value: float) -> None:
|
|
1401
|
+
"""Accumulate per-command metrics for decorator flushing."""
|
|
1402
|
+
|
|
1403
|
+
if self._last_command_metrics is None:
|
|
1404
|
+
self._last_command_metrics = {}
|
|
1405
|
+
self._last_command_metrics[name] = self._last_command_metrics.get(name, 0.0) + value
|
|
1406
|
+
|
|
1407
|
+
def _collect_pending_migrations(
|
|
1408
|
+
self, all_migrations: "list[tuple[str, Path]]", applied_set: set[str], revision: str
|
|
1409
|
+
) -> "list[tuple[str, Path]]":
|
|
1410
|
+
"""Collect pending migrations that need to be applied."""
|
|
1411
|
+
applied_parsed = set()
|
|
1412
|
+
for applied_version in applied_set:
|
|
1413
|
+
try:
|
|
1414
|
+
applied_parsed.add(parse_version(applied_version))
|
|
1415
|
+
except ValueError:
|
|
1416
|
+
continue
|
|
1417
|
+
pending = []
|
|
1418
|
+
parsed_revision = parse_version(revision) if revision != "head" else None
|
|
1419
|
+
for version, file_path in all_migrations:
|
|
1420
|
+
if version in applied_set:
|
|
1421
|
+
continue
|
|
1422
|
+
parsed_version = parse_version(version)
|
|
1423
|
+
if parsed_version in applied_parsed:
|
|
1424
|
+
continue
|
|
1425
|
+
if (
|
|
1426
|
+
parsed_revision is None
|
|
1427
|
+
or (parsed_revision.extension is None and parsed_version.extension is not None)
|
|
1428
|
+
or (parsed_version.extension == parsed_revision.extension and parsed_version <= parsed_revision)
|
|
1429
|
+
):
|
|
1430
|
+
pending.append((version, file_path))
|
|
1431
|
+
return pending
|
|
1432
|
+
|
|
1433
|
+
def _collect_revert_migrations(
|
|
1434
|
+
self, applied: "list[AppliedMigrationRecord]", revision: str
|
|
1435
|
+
) -> "list[AppliedMigrationRecord]":
|
|
1436
|
+
"""Collect migrations to revert based on target revision."""
|
|
1437
|
+
if revision == "-1":
|
|
1438
|
+
core_applied = [m for m in applied if not m["version_num"].startswith("ext_")]
|
|
1439
|
+
if core_applied:
|
|
1440
|
+
return [core_applied[-1]]
|
|
1441
|
+
return [applied[-1]]
|
|
1442
|
+
if revision == "base":
|
|
1443
|
+
return list(reversed(applied))
|
|
1444
|
+
parsed_revision = parse_version(revision)
|
|
1445
|
+
to_revert = []
|
|
1446
|
+
for migration in applied[::-1]:
|
|
1447
|
+
parsed_migration_version = parse_version(migration["version_num"])
|
|
1448
|
+
if (
|
|
1449
|
+
parsed_migration_version.extension == parsed_revision.extension
|
|
1450
|
+
and parsed_migration_version > parsed_revision
|
|
1451
|
+
):
|
|
1452
|
+
to_revert.append(migration)
|
|
1453
|
+
return to_revert
|
|
1454
|
+
|
|
1455
|
+
def _resolve_use_logger(self, method_value: bool) -> bool:
|
|
1456
|
+
"""Resolve effective use_logger setting.
|
|
1457
|
+
|
|
1458
|
+
Method parameter takes precedence over config default. When the method
|
|
1459
|
+
parameter is True, logger output is used. When False, we check the config
|
|
1460
|
+
default.
|
|
1461
|
+
|
|
1462
|
+
Args:
|
|
1463
|
+
method_value: The use_logger parameter passed to the method.
|
|
1464
|
+
|
|
1465
|
+
Returns:
|
|
1466
|
+
True to use logger output, False for Rich console output.
|
|
1467
|
+
"""
|
|
1468
|
+
if method_value:
|
|
1469
|
+
return True
|
|
1470
|
+
migration_config = self._get_migration_config()
|
|
1471
|
+
return bool(migration_config.get("use_logger", False))
|
|
1472
|
+
|
|
1473
|
+
def _resolve_echo(self, method_value: "bool | None") -> bool:
|
|
1474
|
+
"""Resolve effective echo setting."""
|
|
1475
|
+
if method_value is not None:
|
|
1476
|
+
return bool(method_value)
|
|
1477
|
+
migration_config = self._get_migration_config()
|
|
1478
|
+
return bool(migration_config.get("echo", True))
|
|
1479
|
+
|
|
1480
|
+
def _resolve_summary_only(self, method_value: "bool | None") -> bool:
|
|
1481
|
+
"""Resolve effective summary_only setting."""
|
|
1482
|
+
if method_value is not None:
|
|
1483
|
+
return bool(method_value)
|
|
1484
|
+
migration_config = self._get_migration_config()
|
|
1485
|
+
return bool(migration_config.get("summary_only", False))
|
|
1486
|
+
|
|
1487
|
+
def _resolve_output_policy(
|
|
1488
|
+
self, use_logger: bool, echo: "bool | None", summary_only: "bool | None"
|
|
1489
|
+
) -> "tuple[bool, bool, bool]":
|
|
1490
|
+
"""Resolve output policy with method values overriding config defaults."""
|
|
1491
|
+
resolved_use_logger = self._resolve_use_logger(use_logger)
|
|
1492
|
+
resolved_echo = self._resolve_echo(echo)
|
|
1493
|
+
resolved_summary_only = self._resolve_summary_only(summary_only)
|
|
1494
|
+
return resolved_use_logger, resolved_echo, resolved_summary_only
|
|
1495
|
+
|
|
1496
|
+
|
|
1497
|
+
def _is_cockroach_driver(driver: Any) -> bool:
|
|
1498
|
+
"""Return True when ``driver`` targets a CockroachDB adapter or resolved dialect."""
|
|
1499
|
+
if type(driver).__module__.startswith("sqlspec.adapters.cockroach_"):
|
|
1500
|
+
return True
|
|
1501
|
+
resolved_hint = getattr(driver, "_dialect_name", None)
|
|
1502
|
+
return isinstance(resolved_hint, str) and "cockroach" in resolved_hint.lower()
|
|
1503
|
+
|
|
1504
|
+
|
|
1505
|
+
def _supports_postgres_row_security(driver: Any) -> bool:
|
|
1506
|
+
"""Return True when ``driver`` targets PostgreSQL-family backends excluding CockroachDB."""
|
|
1507
|
+
raw_dialect = getattr(driver, "dialect", None)
|
|
1508
|
+
dialect = raw_dialect.lower() if isinstance(raw_dialect, str) else ""
|
|
1509
|
+
if not dialect or _is_cockroach_driver(driver):
|
|
1510
|
+
return False
|
|
1511
|
+
return dialect in BaseMigrationTracker._POSTGRES_LOCK_DIALECTS
|
|
1512
|
+
|
|
1513
|
+
|
|
1514
|
+
def _extract_catalog_rows(result: Any) -> "list[Mapping[str, Any]]":
|
|
1515
|
+
"""Extract mapping rows from a driver result, pairing positional rows with column names.
|
|
1516
|
+
|
|
1517
|
+
Unset mock return values yield no rows.
|
|
1518
|
+
"""
|
|
1519
|
+
if result is None:
|
|
1520
|
+
return []
|
|
1521
|
+
data = getattr(result, "data", result)
|
|
1522
|
+
if not isinstance(data, Sequence) or isinstance(data, (str, bytes)):
|
|
1523
|
+
return []
|
|
1524
|
+
column_names = getattr(result, "column_names", None)
|
|
1525
|
+
names = list(column_names) if isinstance(column_names, (list, tuple)) else []
|
|
1526
|
+
rows: list[Mapping[str, Any]] = []
|
|
1527
|
+
for row in data:
|
|
1528
|
+
if isinstance(row, Mapping):
|
|
1529
|
+
rows.append(row)
|
|
1530
|
+
elif names and isinstance(row, (list, tuple)) and len(row) == len(names):
|
|
1531
|
+
rows.append(dict(zip(names, row, strict=True)))
|
|
1532
|
+
elif callable(getattr(row, "keys", None)) and hasattr(row, "__getitem__"):
|
|
1533
|
+
rows.append(dict(row))
|
|
1534
|
+
return rows
|
|
1535
|
+
|
|
1536
|
+
|
|
1537
|
+
def _excluded_table_names(exclude_tables: "Sequence[str] | None") -> set[str]:
|
|
1538
|
+
"""Return lowercase bare table names from qualified or quoted ``exclude_tables`` entries."""
|
|
1539
|
+
excluded: set[str] = set()
|
|
1540
|
+
for table_name in exclude_tables or ():
|
|
1541
|
+
parts = split_qualified_identifier(table_name, quote_chars='"`', allow_bracket_quotes=True)
|
|
1542
|
+
bare = parts[-1] if parts else table_name.strip('"`[]')
|
|
1543
|
+
if bare:
|
|
1544
|
+
excluded.add(bare.lower())
|
|
1545
|
+
return excluded
|
|
1546
|
+
|
|
1547
|
+
|
|
1548
|
+
def _validate_schema_extraction_rows(
|
|
1549
|
+
refused: "Sequence[Mapping[str, Any]]",
|
|
1550
|
+
omitted: "Sequence[Mapping[str, Any]]",
|
|
1551
|
+
*,
|
|
1552
|
+
backend_label: str,
|
|
1553
|
+
exclude_tables: "Sequence[str] | None" = None,
|
|
1554
|
+
use_squash_error: bool = False,
|
|
1555
|
+
) -> None:
|
|
1556
|
+
"""Refuse row-security objects on included tables and warn about objects extraction does not emit.
|
|
1557
|
+
|
|
1558
|
+
Args:
|
|
1559
|
+
refused: Catalog rows naming tables protected by row-level security policies.
|
|
1560
|
+
omitted: Catalog rows naming grants, functions, triggers, and domains extraction drops.
|
|
1561
|
+
backend_label: Backend name used in messages.
|
|
1562
|
+
exclude_tables: Tables ignored by both checks.
|
|
1563
|
+
use_squash_error: Raise ``SquashValidationError`` instead of ``MigrationError``.
|
|
1564
|
+
|
|
1565
|
+
Raises:
|
|
1566
|
+
SquashValidationError: When ``use_squash_error`` is set and a protected table is found.
|
|
1567
|
+
MigrationError: When a protected table is found.
|
|
1568
|
+
"""
|
|
1569
|
+
excluded = _excluded_table_names(exclude_tables)
|
|
1570
|
+
protected: list[str] = []
|
|
1571
|
+
for row in refused:
|
|
1572
|
+
table_name = str(row.get("table_name") or row.get("relname") or "").strip()
|
|
1573
|
+
if table_name and table_name.lower() in excluded:
|
|
1574
|
+
continue
|
|
1575
|
+
schema_name = str(row.get("schema_name") or row.get("nspname") or "").strip()
|
|
1576
|
+
label = f"{schema_name}.{table_name}" if schema_name and table_name else (table_name or "<table_with_rls>")
|
|
1577
|
+
protected.append(label)
|
|
1578
|
+
if protected:
|
|
1579
|
+
msg = (
|
|
1580
|
+
f"Schema extraction cannot include {backend_label} tables protected by row-level security policies "
|
|
1581
|
+
f"({', '.join(protected)}): extraction does not emit those policies (use --strategy ddl instead)"
|
|
1582
|
+
)
|
|
1583
|
+
if use_squash_error:
|
|
1584
|
+
raise SquashValidationError(msg)
|
|
1585
|
+
raise MigrationError(msg)
|
|
1586
|
+
dropped: list[str] = []
|
|
1587
|
+
kinds: list[str] = []
|
|
1588
|
+
for row in omitted:
|
|
1589
|
+
object_name = str(row.get("object_name") or "").strip()
|
|
1590
|
+
table_part = object_name.split(".", 1)[0].lower()
|
|
1591
|
+
if table_part in excluded:
|
|
1592
|
+
continue
|
|
1593
|
+
kind = str(row.get("object_kind") or "object").strip()
|
|
1594
|
+
schema_name = str(row.get("schema_name") or "").strip()
|
|
1595
|
+
dropped.append(f"{kind}:{schema_name}.{object_name}" if schema_name else f"{kind}:{object_name}")
|
|
1596
|
+
if kind not in kinds:
|
|
1597
|
+
kinds.append(kind)
|
|
1598
|
+
if dropped:
|
|
1599
|
+
log_with_context(
|
|
1600
|
+
logger,
|
|
1601
|
+
logging.WARNING,
|
|
1602
|
+
"migration.schema_extraction.omitted",
|
|
1603
|
+
object_kinds=kinds,
|
|
1604
|
+
object_count=len(dropped),
|
|
1605
|
+
names=dropped[:_MAX_OMITTED_NAMES],
|
|
1606
|
+
)
|
|
1607
|
+
|
|
1608
|
+
|
|
1609
|
+
def _schema_extraction_plan(driver: Any) -> "tuple[str, str, str | None, bool] | None":
|
|
1610
|
+
"""Return ``(backend_label, refusal_sql, omissions_sql, takes_schema)`` for backends with catalog checks."""
|
|
1611
|
+
if _supports_postgres_row_security(driver):
|
|
1612
|
+
return "PostgreSQL", _PG_RLS_SCHEMA_CHECK_SQL, _PG_SCHEMA_OMISSIONS_SQL, True
|
|
1613
|
+
raw_dialect = getattr(driver, "dialect", None)
|
|
1614
|
+
dialect = raw_dialect.lower() if isinstance(raw_dialect, str) else ""
|
|
1615
|
+
if dialect == "oracle":
|
|
1616
|
+
return "Oracle", _ORACLE_VPD_POLICY_SQL, None, True
|
|
1617
|
+
if dialect in {"mssql", "tsql"}:
|
|
1618
|
+
return "SQL Server", _MSSQL_SECURITY_POLICY_SQL, None, False
|
|
1619
|
+
return None
|
|
1620
|
+
|
|
1621
|
+
|
|
1622
|
+
def _extraction_check_error(backend_label: str, exc: Exception) -> MigrationError:
|
|
1623
|
+
"""Build the error raised when a catalog query cannot prove the schema is free of row-security policies."""
|
|
1624
|
+
msg = (
|
|
1625
|
+
f"Schema extraction cannot prove the {backend_label} schema has no row-security policies "
|
|
1626
|
+
f"because the catalog query failed: {exc}"
|
|
1627
|
+
)
|
|
1628
|
+
return MigrationError(msg)
|
|
1629
|
+
|
|
1630
|
+
|
|
1631
|
+
def _ensure_schema_extraction_safe_sync(
|
|
1632
|
+
driver: Any,
|
|
1633
|
+
*,
|
|
1634
|
+
schema: str | None = None,
|
|
1635
|
+
exclude_tables: "Sequence[str] | None" = None,
|
|
1636
|
+
use_squash_error: bool = False,
|
|
1637
|
+
) -> None:
|
|
1638
|
+
"""Refuse row-security objects and warn about dropped objects before schema extraction.
|
|
1639
|
+
|
|
1640
|
+
Args:
|
|
1641
|
+
driver: Active synchronous driver.
|
|
1642
|
+
schema: Inspected schema, or None for the current schema.
|
|
1643
|
+
exclude_tables: Tables ignored by the checks.
|
|
1644
|
+
use_squash_error: Raise ``SquashValidationError`` instead of ``MigrationError``.
|
|
1645
|
+
"""
|
|
1646
|
+
plan = _schema_extraction_plan(driver)
|
|
1647
|
+
if plan is None:
|
|
1648
|
+
return
|
|
1649
|
+
label, refusal_sql, omissions_sql, takes_schema = plan
|
|
1650
|
+
parameters = {"schema_name": schema} if takes_schema else None
|
|
1651
|
+
try:
|
|
1652
|
+
refused = _extract_catalog_rows(driver.execute(refusal_sql, parameters))
|
|
1653
|
+
omitted = _extract_catalog_rows(driver.execute(omissions_sql, parameters)) if omissions_sql else []
|
|
1654
|
+
except SQLSpecError as exc:
|
|
1655
|
+
raise with_cause(_extraction_check_error(label, exc), exc) from exc
|
|
1656
|
+
_validate_schema_extraction_rows(
|
|
1657
|
+
refused, omitted, backend_label=label, exclude_tables=exclude_tables, use_squash_error=use_squash_error
|
|
1658
|
+
)
|
|
1659
|
+
|
|
1660
|
+
|
|
1661
|
+
async def _ensure_schema_extraction_safe_async(
|
|
1662
|
+
driver: Any,
|
|
1663
|
+
*,
|
|
1664
|
+
schema: str | None = None,
|
|
1665
|
+
exclude_tables: "Sequence[str] | None" = None,
|
|
1666
|
+
use_squash_error: bool = False,
|
|
1667
|
+
) -> None:
|
|
1668
|
+
"""Refuse row-security objects and warn about dropped objects before schema extraction.
|
|
1669
|
+
|
|
1670
|
+
Args:
|
|
1671
|
+
driver: Active asynchronous driver.
|
|
1672
|
+
schema: Inspected schema, or None for the current schema.
|
|
1673
|
+
exclude_tables: Tables ignored by the checks.
|
|
1674
|
+
use_squash_error: Raise ``SquashValidationError`` instead of ``MigrationError``.
|
|
1675
|
+
"""
|
|
1676
|
+
plan = _schema_extraction_plan(driver)
|
|
1677
|
+
if plan is None:
|
|
1678
|
+
return
|
|
1679
|
+
label, refusal_sql, omissions_sql, takes_schema = plan
|
|
1680
|
+
parameters = {"schema_name": schema} if takes_schema else None
|
|
1681
|
+
try:
|
|
1682
|
+
refused = _extract_catalog_rows(await driver.execute(refusal_sql, parameters))
|
|
1683
|
+
omitted = _extract_catalog_rows(await driver.execute(omissions_sql, parameters)) if omissions_sql else []
|
|
1684
|
+
except SQLSpecError as exc:
|
|
1685
|
+
raise with_cause(_extraction_check_error(label, exc), exc) from exc
|
|
1686
|
+
_validate_schema_extraction_rows(
|
|
1687
|
+
refused, omitted, backend_label=label, exclude_tables=exclude_tables, use_squash_error=use_squash_error
|
|
1688
|
+
)
|