Initial commit: AuroraMusic monorepo
This commit is contained in:
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"version": "0.0.1",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "web",
|
||||||
|
"runtimeExecutable": "npm",
|
||||||
|
"runtimeArgs": ["run", "dev"],
|
||||||
|
"cwd": "apps/web",
|
||||||
|
"port": 3000
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
node_modules/
|
||||||
|
.next/
|
||||||
|
dist/
|
||||||
|
build/
|
||||||
|
*.log
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Aurora Music
|
||||||
|
|
||||||
|
A generative AI music platform: describe a song in a text prompt (optionally
|
||||||
|
with your own lyrics) and get back a full track with instrumentation and,
|
||||||
|
in vocals mode, sung vocals. Accounts, a personal library, and a public
|
||||||
|
feed with likes.
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
```
|
||||||
|
apps/web Next.js 16 frontend — auth, create, library, feed
|
||||||
|
apps/api FastAPI backend — auth, songs, likes, enqueues generation jobs
|
||||||
|
apps/worker RQ worker — pulls jobs off Redis, calls a generation provider
|
||||||
|
packages/db Shared SQLAlchemy models used by both api and worker
|
||||||
|
packages/inference Pluggable MusicGenerationProvider interface + backends
|
||||||
|
```
|
||||||
|
|
||||||
|
Generation is async: the API creates a `Song` row (`status=pending`) and
|
||||||
|
enqueues a job; the worker picks it up, calls whichever provider is
|
||||||
|
configured, writes the resulting audio to `media/`, and flips the row to
|
||||||
|
`completed`/`failed`. The frontend polls while a song is in flight.
|
||||||
|
|
||||||
|
The generation step is pluggable (`packages/inference/factory.py`,
|
||||||
|
switched via `GENERATION_BACKEND`):
|
||||||
|
|
||||||
|
- `mock` (default, used below) — synthesizes a quick procedural clip.
|
||||||
|
No GPU, no heavy deps. Good enough to build and test the whole product.
|
||||||
|
- `diffrhythm` — a real open-source model (vocals + instrumentation from a
|
||||||
|
prompt + lyrics). Needs an NVIDIA GPU. See
|
||||||
|
[infra/gpu-provider/README.md](infra/gpu-provider/README.md) to run this
|
||||||
|
backend on a machine with a GPU.
|
||||||
|
|
||||||
|
## Quick start (mock backend, any machine)
|
||||||
|
|
||||||
|
**1. Infra**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d postgres redis
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. API**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd apps/api
|
||||||
|
python3.12 -m venv .venv && .venv/bin/pip install -r requirements.txt
|
||||||
|
.venv/bin/pip install -e ../../packages/db -e ../../packages/inference
|
||||||
|
cp .env.example .env # edit MEDIA_DIR to an absolute path
|
||||||
|
.venv/bin/alembic upgrade head
|
||||||
|
.venv/bin/uvicorn app.main:app --reload --port 8000
|
||||||
|
```
|
||||||
|
|
||||||
|
**3. Worker** (separate terminal)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd apps/worker
|
||||||
|
python3.12 -m venv .venv && .venv/bin/pip install -r requirements.txt
|
||||||
|
.venv/bin/pip install -e ../../packages/db -e ../../packages/inference
|
||||||
|
cp .env.example .env # MEDIA_DIR must match the API's
|
||||||
|
.venv/bin/python run_worker.py
|
||||||
|
```
|
||||||
|
|
||||||
|
**4. Web** (separate terminal)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd apps/web
|
||||||
|
npm install
|
||||||
|
npm run dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open http://localhost:3000, sign up, and create a song — it'll show as
|
||||||
|
"Generating…" in your library for a few seconds, then become playable.
|
||||||
|
|
||||||
|
## Switching to real generation
|
||||||
|
|
||||||
|
Everything above works identically once you switch backends — the API,
|
||||||
|
worker, and frontend don't change. Only the worker's `.env` changes
|
||||||
|
(`GENERATION_BACKEND=diffrhythm` plus a few `DIFFRHYTHM_*` vars). See
|
||||||
|
[infra/gpu-provider/README.md](infra/gpu-provider/README.md).
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
DATABASE_URL=postgresql+psycopg://aurora:aurora@localhost:5432/aurora
|
||||||
|
REDIS_URL=redis://localhost:6379/0
|
||||||
|
JWT_SECRET=dev-secret-change-me
|
||||||
|
MEDIA_DIR=/Users/r3ap3r/Projects/AuroraMusic/media
|
||||||
|
GENERATION_BACKEND=mock
|
||||||
|
CORS_ORIGINS=["http://localhost:3000"]
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
<#
|
||||||
|
.Synopsis
|
||||||
|
Activate a Python virtual environment for the current PowerShell session.
|
||||||
|
|
||||||
|
.Description
|
||||||
|
Pushes the python executable for a virtual environment to the front of the
|
||||||
|
$Env:PATH environment variable and sets the prompt to signify that you are
|
||||||
|
in a Python virtual environment. Makes use of the command line switches as
|
||||||
|
well as the `pyvenv.cfg` file values present in the virtual environment.
|
||||||
|
|
||||||
|
.Parameter VenvDir
|
||||||
|
Path to the directory that contains the virtual environment to activate. The
|
||||||
|
default value for this is the parent of the directory that the Activate.ps1
|
||||||
|
script is located within.
|
||||||
|
|
||||||
|
.Parameter Prompt
|
||||||
|
The prompt prefix to display when this virtual environment is activated. By
|
||||||
|
default, this prompt is the name of the virtual environment folder (VenvDir)
|
||||||
|
surrounded by parentheses and followed by a single space (ie. '(.venv) ').
|
||||||
|
|
||||||
|
.Example
|
||||||
|
Activate.ps1
|
||||||
|
Activates the Python virtual environment that contains the Activate.ps1 script.
|
||||||
|
|
||||||
|
.Example
|
||||||
|
Activate.ps1 -Verbose
|
||||||
|
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||||
|
and shows extra information about the activation as it executes.
|
||||||
|
|
||||||
|
.Example
|
||||||
|
Activate.ps1 -VenvDir C:\Users\MyUser\Common\.venv
|
||||||
|
Activates the Python virtual environment located in the specified location.
|
||||||
|
|
||||||
|
.Example
|
||||||
|
Activate.ps1 -Prompt "MyPython"
|
||||||
|
Activates the Python virtual environment that contains the Activate.ps1 script,
|
||||||
|
and prefixes the current prompt with the specified string (surrounded in
|
||||||
|
parentheses) while the virtual environment is active.
|
||||||
|
|
||||||
|
.Notes
|
||||||
|
On Windows, it may be required to enable this Activate.ps1 script by setting the
|
||||||
|
execution policy for the user. You can do this by issuing the following PowerShell
|
||||||
|
command:
|
||||||
|
|
||||||
|
PS C:\> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||||
|
|
||||||
|
For more information on Execution Policies:
|
||||||
|
https://go.microsoft.com/fwlink/?LinkID=135170
|
||||||
|
|
||||||
|
#>
|
||||||
|
Param(
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[String]
|
||||||
|
$VenvDir,
|
||||||
|
[Parameter(Mandatory = $false)]
|
||||||
|
[String]
|
||||||
|
$Prompt
|
||||||
|
)
|
||||||
|
|
||||||
|
<# Function declarations --------------------------------------------------- #>
|
||||||
|
|
||||||
|
<#
|
||||||
|
.Synopsis
|
||||||
|
Remove all shell session elements added by the Activate script, including the
|
||||||
|
addition of the virtual environment's Python executable from the beginning of
|
||||||
|
the PATH variable.
|
||||||
|
|
||||||
|
.Parameter NonDestructive
|
||||||
|
If present, do not remove this function from the global namespace for the
|
||||||
|
session.
|
||||||
|
|
||||||
|
#>
|
||||||
|
function global:deactivate ([switch]$NonDestructive) {
|
||||||
|
# Revert to original values
|
||||||
|
|
||||||
|
# The prior prompt:
|
||||||
|
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
|
||||||
|
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
|
||||||
|
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
|
||||||
|
}
|
||||||
|
|
||||||
|
# The prior PYTHONHOME:
|
||||||
|
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
|
||||||
|
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
|
||||||
|
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
|
||||||
|
}
|
||||||
|
|
||||||
|
# The prior PATH:
|
||||||
|
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
|
||||||
|
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
|
||||||
|
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just remove the VIRTUAL_ENV altogether:
|
||||||
|
if (Test-Path -Path Env:VIRTUAL_ENV) {
|
||||||
|
Remove-Item -Path env:VIRTUAL_ENV
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just remove VIRTUAL_ENV_PROMPT altogether.
|
||||||
|
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
|
||||||
|
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
|
||||||
|
}
|
||||||
|
|
||||||
|
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
|
||||||
|
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
|
||||||
|
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
|
||||||
|
}
|
||||||
|
|
||||||
|
# Leave deactivate function in the global namespace if requested:
|
||||||
|
if (-not $NonDestructive) {
|
||||||
|
Remove-Item -Path function:deactivate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
<#
|
||||||
|
.Description
|
||||||
|
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
|
||||||
|
given folder, and returns them in a map.
|
||||||
|
|
||||||
|
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
|
||||||
|
two strings separated by `=` (with any amount of whitespace surrounding the =)
|
||||||
|
then it is considered a `key = value` line. The left hand string is the key,
|
||||||
|
the right hand is the value.
|
||||||
|
|
||||||
|
If the value starts with a `'` or a `"` then the first and last character is
|
||||||
|
stripped from the value before being captured.
|
||||||
|
|
||||||
|
.Parameter ConfigDir
|
||||||
|
Path to the directory that contains the `pyvenv.cfg` file.
|
||||||
|
#>
|
||||||
|
function Get-PyVenvConfig(
|
||||||
|
[String]
|
||||||
|
$ConfigDir
|
||||||
|
) {
|
||||||
|
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
|
||||||
|
|
||||||
|
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
|
||||||
|
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
|
||||||
|
|
||||||
|
# An empty map will be returned if no config file is found.
|
||||||
|
$pyvenvConfig = @{ }
|
||||||
|
|
||||||
|
if ($pyvenvConfigPath) {
|
||||||
|
|
||||||
|
Write-Verbose "File exists, parse `key = value` lines"
|
||||||
|
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
|
||||||
|
|
||||||
|
$pyvenvConfigContent | ForEach-Object {
|
||||||
|
$keyval = $PSItem -split "\s*=\s*", 2
|
||||||
|
if ($keyval[0] -and $keyval[1]) {
|
||||||
|
$val = $keyval[1]
|
||||||
|
|
||||||
|
# Remove extraneous quotations around a string value.
|
||||||
|
if ("'""".Contains($val.Substring(0, 1))) {
|
||||||
|
$val = $val.Substring(1, $val.Length - 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
$pyvenvConfig[$keyval[0]] = $val
|
||||||
|
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $pyvenvConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
<# Begin Activate script --------------------------------------------------- #>
|
||||||
|
|
||||||
|
# Determine the containing directory of this script
|
||||||
|
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
|
||||||
|
$VenvExecDir = Get-Item -Path $VenvExecPath
|
||||||
|
|
||||||
|
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
|
||||||
|
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
|
||||||
|
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
|
||||||
|
|
||||||
|
# Set values required in priority: CmdLine, ConfigFile, Default
|
||||||
|
# First, get the location of the virtual environment, it might not be
|
||||||
|
# VenvExecDir if specified on the command line.
|
||||||
|
if ($VenvDir) {
|
||||||
|
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
|
||||||
|
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\/")
|
||||||
|
Write-Verbose "VenvDir=$VenvDir"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Next, read the `pyvenv.cfg` file to determine any required value such
|
||||||
|
# as `prompt`.
|
||||||
|
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
|
||||||
|
|
||||||
|
# Next, set the prompt from the command line, or the config file, or
|
||||||
|
# just use the name of the virtual environment folder.
|
||||||
|
if ($Prompt) {
|
||||||
|
Write-Verbose "Prompt specified as argument, using '$Prompt'"
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
|
||||||
|
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
|
||||||
|
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
|
||||||
|
$Prompt = $pyvenvCfg['prompt'];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
|
||||||
|
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
|
||||||
|
$Prompt = Split-Path -Path $venvDir -Leaf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Verbose "Prompt = '$Prompt'"
|
||||||
|
Write-Verbose "VenvDir='$VenvDir'"
|
||||||
|
|
||||||
|
# Deactivate any currently active virtual environment, but leave the
|
||||||
|
# deactivate function in place.
|
||||||
|
deactivate -nondestructive
|
||||||
|
|
||||||
|
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
|
||||||
|
# that there is an activated venv.
|
||||||
|
$env:VIRTUAL_ENV = $VenvDir
|
||||||
|
|
||||||
|
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
|
||||||
|
|
||||||
|
Write-Verbose "Setting prompt to '$Prompt'"
|
||||||
|
|
||||||
|
# Set the prompt to include the env name
|
||||||
|
# Make sure _OLD_VIRTUAL_PROMPT is global
|
||||||
|
function global:_OLD_VIRTUAL_PROMPT { "" }
|
||||||
|
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
|
||||||
|
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
|
||||||
|
|
||||||
|
function global:prompt {
|
||||||
|
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
|
||||||
|
_OLD_VIRTUAL_PROMPT
|
||||||
|
}
|
||||||
|
$env:VIRTUAL_ENV_PROMPT = $Prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clear PYTHONHOME
|
||||||
|
if (Test-Path -Path Env:PYTHONHOME) {
|
||||||
|
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
|
||||||
|
Remove-Item -Path Env:PYTHONHOME
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add the venv to the PATH
|
||||||
|
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
|
||||||
|
$Env:PATH = "$VenvExecDir$([System.IO.Path]::PathSeparator)$Env:PATH"
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
# This file must be used with "source bin/activate" *from bash*
|
||||||
|
# You cannot run it directly
|
||||||
|
|
||||||
|
deactivate () {
|
||||||
|
# reset old environment variables
|
||||||
|
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
|
||||||
|
PATH="${_OLD_VIRTUAL_PATH:-}"
|
||||||
|
export PATH
|
||||||
|
unset _OLD_VIRTUAL_PATH
|
||||||
|
fi
|
||||||
|
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
|
||||||
|
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
|
||||||
|
export PYTHONHOME
|
||||||
|
unset _OLD_VIRTUAL_PYTHONHOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Call hash to forget past locations. Without forgetting
|
||||||
|
# past locations the $PATH changes we made may not be respected.
|
||||||
|
# See "man bash" for more details. hash is usually a builtin of your shell
|
||||||
|
hash -r 2> /dev/null
|
||||||
|
|
||||||
|
if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
|
||||||
|
PS1="${_OLD_VIRTUAL_PS1:-}"
|
||||||
|
export PS1
|
||||||
|
unset _OLD_VIRTUAL_PS1
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset VIRTUAL_ENV
|
||||||
|
unset VIRTUAL_ENV_PROMPT
|
||||||
|
if [ ! "${1:-}" = "nondestructive" ] ; then
|
||||||
|
# Self destruct!
|
||||||
|
unset -f deactivate
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# unset irrelevant variables
|
||||||
|
deactivate nondestructive
|
||||||
|
|
||||||
|
# on Windows, a path can contain colons and backslashes and has to be converted:
|
||||||
|
case "$(uname)" in
|
||||||
|
CYGWIN*|MSYS*|MINGW*)
|
||||||
|
# transform D:\path\to\venv to /d/path/to/venv on MSYS and MINGW
|
||||||
|
# and to /cygdrive/d/path/to/venv on Cygwin
|
||||||
|
VIRTUAL_ENV=$(cygpath /Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv)
|
||||||
|
export VIRTUAL_ENV
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
# use the path as-is
|
||||||
|
export VIRTUAL_ENV=/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
_OLD_VIRTUAL_PATH="$PATH"
|
||||||
|
PATH="$VIRTUAL_ENV/"bin":$PATH"
|
||||||
|
export PATH
|
||||||
|
|
||||||
|
VIRTUAL_ENV_PROMPT='(.venv) '
|
||||||
|
export VIRTUAL_ENV_PROMPT
|
||||||
|
|
||||||
|
# unset PYTHONHOME if set
|
||||||
|
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
|
||||||
|
# could use `if (set -u; : $PYTHONHOME) ;` in bash
|
||||||
|
if [ -n "${PYTHONHOME:-}" ] ; then
|
||||||
|
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
|
||||||
|
unset PYTHONHOME
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
|
||||||
|
_OLD_VIRTUAL_PS1="${PS1:-}"
|
||||||
|
PS1="("'(.venv) '") ${PS1:-}"
|
||||||
|
export PS1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Call hash to forget past commands. Without forgetting
|
||||||
|
# past commands the $PATH changes we made may not be respected
|
||||||
|
hash -r 2> /dev/null
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
# This file must be used with "source bin/activate.csh" *from csh*.
|
||||||
|
# You cannot run it directly.
|
||||||
|
|
||||||
|
# Created by Davide Di Blasi <[email protected]>.
|
||||||
|
# Ported to Python 3.3 venv by Andrew Svetlov <[email protected]>
|
||||||
|
|
||||||
|
alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PATH" && unset _OLD_VIRTUAL_PATH; rehash; test $?_OLD_VIRTUAL_PROMPT != 0 && set prompt="$_OLD_VIRTUAL_PROMPT" && unset _OLD_VIRTUAL_PROMPT; unsetenv VIRTUAL_ENV; unsetenv VIRTUAL_ENV_PROMPT; test "\!:*" != "nondestructive" && unalias deactivate'
|
||||||
|
|
||||||
|
# Unset irrelevant variables.
|
||||||
|
deactivate nondestructive
|
||||||
|
|
||||||
|
setenv VIRTUAL_ENV /Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv
|
||||||
|
|
||||||
|
set _OLD_VIRTUAL_PATH="$PATH"
|
||||||
|
setenv PATH "$VIRTUAL_ENV/"bin":$PATH"
|
||||||
|
|
||||||
|
|
||||||
|
set _OLD_VIRTUAL_PROMPT="$prompt"
|
||||||
|
|
||||||
|
if (! "$?VIRTUAL_ENV_DISABLE_PROMPT") then
|
||||||
|
set prompt = '(.venv) '"$prompt"
|
||||||
|
setenv VIRTUAL_ENV_PROMPT '(.venv) '
|
||||||
|
endif
|
||||||
|
|
||||||
|
alias pydoc python -m pydoc
|
||||||
|
|
||||||
|
rehash
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
# This file must be used with "source <venv>/bin/activate.fish" *from fish*
|
||||||
|
# (https://fishshell.com/). You cannot run it directly.
|
||||||
|
|
||||||
|
function deactivate -d "Exit virtual environment and return to normal shell environment"
|
||||||
|
# reset old environment variables
|
||||||
|
if test -n "$_OLD_VIRTUAL_PATH"
|
||||||
|
set -gx PATH $_OLD_VIRTUAL_PATH
|
||||||
|
set -e _OLD_VIRTUAL_PATH
|
||||||
|
end
|
||||||
|
if test -n "$_OLD_VIRTUAL_PYTHONHOME"
|
||||||
|
set -gx PYTHONHOME $_OLD_VIRTUAL_PYTHONHOME
|
||||||
|
set -e _OLD_VIRTUAL_PYTHONHOME
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -n "$_OLD_FISH_PROMPT_OVERRIDE"
|
||||||
|
set -e _OLD_FISH_PROMPT_OVERRIDE
|
||||||
|
# prevents error when using nested fish instances (Issue #93858)
|
||||||
|
if functions -q _old_fish_prompt
|
||||||
|
functions -e fish_prompt
|
||||||
|
functions -c _old_fish_prompt fish_prompt
|
||||||
|
functions -e _old_fish_prompt
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
set -e VIRTUAL_ENV
|
||||||
|
set -e VIRTUAL_ENV_PROMPT
|
||||||
|
if test "$argv[1]" != "nondestructive"
|
||||||
|
# Self-destruct!
|
||||||
|
functions -e deactivate
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Unset irrelevant variables.
|
||||||
|
deactivate nondestructive
|
||||||
|
|
||||||
|
set -gx VIRTUAL_ENV /Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv
|
||||||
|
|
||||||
|
set -gx _OLD_VIRTUAL_PATH $PATH
|
||||||
|
set -gx PATH "$VIRTUAL_ENV/"bin $PATH
|
||||||
|
|
||||||
|
# Unset PYTHONHOME if set.
|
||||||
|
if set -q PYTHONHOME
|
||||||
|
set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME
|
||||||
|
set -e PYTHONHOME
|
||||||
|
end
|
||||||
|
|
||||||
|
if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
|
||||||
|
# fish uses a function instead of an env var to generate the prompt.
|
||||||
|
|
||||||
|
# Save the current fish_prompt function as the function _old_fish_prompt.
|
||||||
|
functions -c fish_prompt _old_fish_prompt
|
||||||
|
|
||||||
|
# With the original prompt function renamed, we can override with our own.
|
||||||
|
function fish_prompt
|
||||||
|
# Save the return status of the last command.
|
||||||
|
set -l old_status $status
|
||||||
|
|
||||||
|
# Output the venv prompt; color taken from the blue of the Python logo.
|
||||||
|
printf "%s%s%s" (set_color 4B8BBE) '(.venv) ' (set_color normal)
|
||||||
|
|
||||||
|
# Restore the return status of the previous command.
|
||||||
|
echo "exit $old_status" | .
|
||||||
|
# Output the original/"old" prompt.
|
||||||
|
_old_fish_prompt
|
||||||
|
end
|
||||||
|
|
||||||
|
set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"
|
||||||
|
set -gx VIRTUAL_ENV_PROMPT '(.venv) '
|
||||||
|
end
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from alembic.config import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from cffi._cffi_gen_src import run
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(run())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from dotenv.__main__ import cli
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(cli())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from email_validator.__main__ import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from numpy.f2py.f2py2e import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from fastapi.cli import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from idna.cli import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from mako.cmd import cmdline
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(cmdline())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from pip._internal.cli.main import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from pip._internal.cli.main import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from pip._internal.cli.main import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.cli import decrypt
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(decrypt())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.cli import encrypt
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(encrypt())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.cli import keygen
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(keygen())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.util import private_to_public
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(private_to_public())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.cli import sign
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(sign())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rsa.cli import verify
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(verify())
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
python3.12
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
python3.12
|
||||||
Symlink
+1
@@ -0,0 +1 @@
|
|||||||
|
/opt/homebrew/opt/[email protected]/bin/python3.12
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rq.cli import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rq.cli import info
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(info())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from rq.cli import worker
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(worker())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from uvicorn.main import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from watchfiles.cli import cli
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(cli())
|
||||||
Executable
+6
@@ -0,0 +1,6 @@
|
|||||||
|
#!/Users/r3ap3r/Projects/AuroraMusic/apps/api/.venv/bin/python3.12
|
||||||
|
import sys
|
||||||
|
from websockets.cli import main
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.argv[0] = sys.argv[0].removesuffix('.exe')
|
||||||
|
sys.exit(main())
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
pip
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
Copyright 2005-2024 SQLAlchemy authors and contributors <see AUTHORS file>.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: SQLAlchemy
|
||||||
|
Version: 2.0.35
|
||||||
|
Summary: Database Abstraction Library
|
||||||
|
Home-page: https://www.sqlalchemy.org
|
||||||
|
Author: Mike Bayer
|
||||||
|
Author-email: [email protected]
|
||||||
|
License: MIT
|
||||||
|
Project-URL: Documentation, https://docs.sqlalchemy.org
|
||||||
|
Project-URL: Issue Tracker, https://github.com/sqlalchemy/sqlalchemy/
|
||||||
|
Classifier: Development Status :: 5 - Production/Stable
|
||||||
|
Classifier: Intended Audience :: Developers
|
||||||
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
|
Classifier: Operating System :: OS Independent
|
||||||
|
Classifier: Programming Language :: Python
|
||||||
|
Classifier: Programming Language :: Python :: 3
|
||||||
|
Classifier: Programming Language :: Python :: 3.7
|
||||||
|
Classifier: Programming Language :: Python :: 3.8
|
||||||
|
Classifier: Programming Language :: Python :: 3.9
|
||||||
|
Classifier: Programming Language :: Python :: 3.10
|
||||||
|
Classifier: Programming Language :: Python :: 3.11
|
||||||
|
Classifier: Programming Language :: Python :: 3.12
|
||||||
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||||
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||||
|
Classifier: Topic :: Database :: Front-Ends
|
||||||
|
Requires-Python: >=3.7
|
||||||
|
Description-Content-Type: text/x-rst
|
||||||
|
License-File: LICENSE
|
||||||
|
Requires-Dist: typing-extensions >=4.6.0
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; python_version < "3.13" and (platform_machine == "aarch64" or (platform_machine == "ppc64le" or (platform_machine == "x86_64" or (platform_machine == "amd64" or (platform_machine == "AMD64" or (platform_machine == "win32" or platform_machine == "WIN32"))))))
|
||||||
|
Requires-Dist: importlib-metadata ; python_version < "3.8"
|
||||||
|
Provides-Extra: aiomysql
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'aiomysql'
|
||||||
|
Requires-Dist: aiomysql >=0.2.0 ; extra == 'aiomysql'
|
||||||
|
Provides-Extra: aioodbc
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'aioodbc'
|
||||||
|
Requires-Dist: aioodbc ; extra == 'aioodbc'
|
||||||
|
Provides-Extra: aiosqlite
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'aiosqlite'
|
||||||
|
Requires-Dist: aiosqlite ; extra == 'aiosqlite'
|
||||||
|
Requires-Dist: typing-extensions !=3.10.0.1 ; extra == 'aiosqlite'
|
||||||
|
Provides-Extra: asyncio
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'asyncio'
|
||||||
|
Provides-Extra: asyncmy
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'asyncmy'
|
||||||
|
Requires-Dist: asyncmy !=0.2.4,!=0.2.6,>=0.2.3 ; extra == 'asyncmy'
|
||||||
|
Provides-Extra: mariadb_connector
|
||||||
|
Requires-Dist: mariadb !=1.1.2,!=1.1.5,>=1.0.1 ; extra == 'mariadb_connector'
|
||||||
|
Provides-Extra: mssql
|
||||||
|
Requires-Dist: pyodbc ; extra == 'mssql'
|
||||||
|
Provides-Extra: mssql_pymssql
|
||||||
|
Requires-Dist: pymssql ; extra == 'mssql_pymssql'
|
||||||
|
Provides-Extra: mssql_pyodbc
|
||||||
|
Requires-Dist: pyodbc ; extra == 'mssql_pyodbc'
|
||||||
|
Provides-Extra: mypy
|
||||||
|
Requires-Dist: mypy >=0.910 ; extra == 'mypy'
|
||||||
|
Provides-Extra: mysql
|
||||||
|
Requires-Dist: mysqlclient >=1.4.0 ; extra == 'mysql'
|
||||||
|
Provides-Extra: mysql_connector
|
||||||
|
Requires-Dist: mysql-connector-python ; extra == 'mysql_connector'
|
||||||
|
Provides-Extra: oracle
|
||||||
|
Requires-Dist: cx-oracle >=8 ; extra == 'oracle'
|
||||||
|
Provides-Extra: oracle_oracledb
|
||||||
|
Requires-Dist: oracledb >=1.0.1 ; extra == 'oracle_oracledb'
|
||||||
|
Provides-Extra: postgresql
|
||||||
|
Requires-Dist: psycopg2 >=2.7 ; extra == 'postgresql'
|
||||||
|
Provides-Extra: postgresql_asyncpg
|
||||||
|
Requires-Dist: greenlet !=0.4.17 ; extra == 'postgresql_asyncpg'
|
||||||
|
Requires-Dist: asyncpg ; extra == 'postgresql_asyncpg'
|
||||||
|
Provides-Extra: postgresql_pg8000
|
||||||
|
Requires-Dist: pg8000 >=1.29.1 ; extra == 'postgresql_pg8000'
|
||||||
|
Provides-Extra: postgresql_psycopg
|
||||||
|
Requires-Dist: psycopg >=3.0.7 ; extra == 'postgresql_psycopg'
|
||||||
|
Provides-Extra: postgresql_psycopg2binary
|
||||||
|
Requires-Dist: psycopg2-binary ; extra == 'postgresql_psycopg2binary'
|
||||||
|
Provides-Extra: postgresql_psycopg2cffi
|
||||||
|
Requires-Dist: psycopg2cffi ; extra == 'postgresql_psycopg2cffi'
|
||||||
|
Provides-Extra: postgresql_psycopgbinary
|
||||||
|
Requires-Dist: psycopg[binary] >=3.0.7 ; extra == 'postgresql_psycopgbinary'
|
||||||
|
Provides-Extra: pymysql
|
||||||
|
Requires-Dist: pymysql ; extra == 'pymysql'
|
||||||
|
Provides-Extra: sqlcipher
|
||||||
|
Requires-Dist: sqlcipher3-binary ; extra == 'sqlcipher'
|
||||||
|
|
||||||
|
SQLAlchemy
|
||||||
|
==========
|
||||||
|
|
||||||
|
|PyPI| |Python| |Downloads|
|
||||||
|
|
||||||
|
.. |PyPI| image:: https://img.shields.io/pypi/v/sqlalchemy
|
||||||
|
:target: https://pypi.org/project/sqlalchemy
|
||||||
|
:alt: PyPI
|
||||||
|
|
||||||
|
.. |Python| image:: https://img.shields.io/pypi/pyversions/sqlalchemy
|
||||||
|
:target: https://pypi.org/project/sqlalchemy
|
||||||
|
:alt: PyPI - Python Version
|
||||||
|
|
||||||
|
.. |Downloads| image:: https://static.pepy.tech/badge/sqlalchemy/month
|
||||||
|
:target: https://pepy.tech/project/sqlalchemy
|
||||||
|
:alt: PyPI - Downloads
|
||||||
|
|
||||||
|
|
||||||
|
The Python SQL Toolkit and Object Relational Mapper
|
||||||
|
|
||||||
|
Introduction
|
||||||
|
-------------
|
||||||
|
|
||||||
|
SQLAlchemy is the Python SQL toolkit and Object Relational Mapper
|
||||||
|
that gives application developers the full power and
|
||||||
|
flexibility of SQL. SQLAlchemy provides a full suite
|
||||||
|
of well known enterprise-level persistence patterns,
|
||||||
|
designed for efficient and high-performing database
|
||||||
|
access, adapted into a simple and Pythonic domain
|
||||||
|
language.
|
||||||
|
|
||||||
|
Major SQLAlchemy features include:
|
||||||
|
|
||||||
|
* An industrial strength ORM, built
|
||||||
|
from the core on the identity map, unit of work,
|
||||||
|
and data mapper patterns. These patterns
|
||||||
|
allow transparent persistence of objects
|
||||||
|
using a declarative configuration system.
|
||||||
|
Domain models
|
||||||
|
can be constructed and manipulated naturally,
|
||||||
|
and changes are synchronized with the
|
||||||
|
current transaction automatically.
|
||||||
|
* A relationally-oriented query system, exposing
|
||||||
|
the full range of SQL's capabilities
|
||||||
|
explicitly, including joins, subqueries,
|
||||||
|
correlation, and most everything else,
|
||||||
|
in terms of the object model.
|
||||||
|
Writing queries with the ORM uses the same
|
||||||
|
techniques of relational composition you use
|
||||||
|
when writing SQL. While you can drop into
|
||||||
|
literal SQL at any time, it's virtually never
|
||||||
|
needed.
|
||||||
|
* A comprehensive and flexible system
|
||||||
|
of eager loading for related collections and objects.
|
||||||
|
Collections are cached within a session,
|
||||||
|
and can be loaded on individual access, all
|
||||||
|
at once using joins, or by query per collection
|
||||||
|
across the full result set.
|
||||||
|
* A Core SQL construction system and DBAPI
|
||||||
|
interaction layer. The SQLAlchemy Core is
|
||||||
|
separate from the ORM and is a full database
|
||||||
|
abstraction layer in its own right, and includes
|
||||||
|
an extensible Python-based SQL expression
|
||||||
|
language, schema metadata, connection pooling,
|
||||||
|
type coercion, and custom types.
|
||||||
|
* All primary and foreign key constraints are
|
||||||
|
assumed to be composite and natural. Surrogate
|
||||||
|
integer primary keys are of course still the
|
||||||
|
norm, but SQLAlchemy never assumes or hardcodes
|
||||||
|
to this model.
|
||||||
|
* Database introspection and generation. Database
|
||||||
|
schemas can be "reflected" in one step into
|
||||||
|
Python structures representing database metadata;
|
||||||
|
those same structures can then generate
|
||||||
|
CREATE statements right back out - all within
|
||||||
|
the Core, independent of the ORM.
|
||||||
|
|
||||||
|
SQLAlchemy's philosophy:
|
||||||
|
|
||||||
|
* SQL databases behave less and less like object
|
||||||
|
collections the more size and performance start to
|
||||||
|
matter; object collections behave less and less like
|
||||||
|
tables and rows the more abstraction starts to matter.
|
||||||
|
SQLAlchemy aims to accommodate both of these
|
||||||
|
principles.
|
||||||
|
* An ORM doesn't need to hide the "R". A relational
|
||||||
|
database provides rich, set-based functionality
|
||||||
|
that should be fully exposed. SQLAlchemy's
|
||||||
|
ORM provides an open-ended set of patterns
|
||||||
|
that allow a developer to construct a custom
|
||||||
|
mediation layer between a domain model and
|
||||||
|
a relational schema, turning the so-called
|
||||||
|
"object relational impedance" issue into
|
||||||
|
a distant memory.
|
||||||
|
* The developer, in all cases, makes all decisions
|
||||||
|
regarding the design, structure, and naming conventions
|
||||||
|
of both the object model as well as the relational
|
||||||
|
schema. SQLAlchemy only provides the means
|
||||||
|
to automate the execution of these decisions.
|
||||||
|
* With SQLAlchemy, there's no such thing as
|
||||||
|
"the ORM generated a bad query" - you
|
||||||
|
retain full control over the structure of
|
||||||
|
queries, including how joins are organized,
|
||||||
|
how subqueries and correlation is used, what
|
||||||
|
columns are requested. Everything SQLAlchemy
|
||||||
|
does is ultimately the result of a developer-initiated
|
||||||
|
decision.
|
||||||
|
* Don't use an ORM if the problem doesn't need one.
|
||||||
|
SQLAlchemy consists of a Core and separate ORM
|
||||||
|
component. The Core offers a full SQL expression
|
||||||
|
language that allows Pythonic construction
|
||||||
|
of SQL constructs that render directly to SQL
|
||||||
|
strings for a target database, returning
|
||||||
|
result sets that are essentially enhanced DBAPI
|
||||||
|
cursors.
|
||||||
|
* Transactions should be the norm. With SQLAlchemy's
|
||||||
|
ORM, nothing goes to permanent storage until
|
||||||
|
commit() is called. SQLAlchemy encourages applications
|
||||||
|
to create a consistent means of delineating
|
||||||
|
the start and end of a series of operations.
|
||||||
|
* Never render a literal value in a SQL statement.
|
||||||
|
Bound parameters are used to the greatest degree
|
||||||
|
possible, allowing query optimizers to cache
|
||||||
|
query plans effectively and making SQL injection
|
||||||
|
attacks a non-issue.
|
||||||
|
|
||||||
|
Documentation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Latest documentation is at:
|
||||||
|
|
||||||
|
https://www.sqlalchemy.org/docs/
|
||||||
|
|
||||||
|
Installation / Requirements
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
Full documentation for installation is at
|
||||||
|
`Installation <https://www.sqlalchemy.org/docs/intro.html#installation>`_.
|
||||||
|
|
||||||
|
Getting Help / Development / Bug reporting
|
||||||
|
------------------------------------------
|
||||||
|
|
||||||
|
Please refer to the `SQLAlchemy Community Guide <https://www.sqlalchemy.org/support.html>`_.
|
||||||
|
|
||||||
|
Code of Conduct
|
||||||
|
---------------
|
||||||
|
|
||||||
|
Above all, SQLAlchemy places great emphasis on polite, thoughtful, and
|
||||||
|
constructive communication between users and developers.
|
||||||
|
Please see our current Code of Conduct at
|
||||||
|
`Code of Conduct <https://www.sqlalchemy.org/codeofconduct.html>`_.
|
||||||
|
|
||||||
|
License
|
||||||
|
-------
|
||||||
|
|
||||||
|
SQLAlchemy is distributed under the `MIT license
|
||||||
|
<https://www.opensource.org/licenses/mit-license.php>`_.
|
||||||
|
|
||||||
@@ -0,0 +1,530 @@
|
|||||||
|
SQLAlchemy-2.0.35.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||||
|
SQLAlchemy-2.0.35.dist-info/LICENSE,sha256=PA9Zq4h9BB3mpOUv_j6e212VIt6Qn66abNettue-MpM,1100
|
||||||
|
SQLAlchemy-2.0.35.dist-info/METADATA,sha256=nz-ukujebAhwlZl0txMOxlkTwDyPwTn3tWuKTcw8OMU,9632
|
||||||
|
SQLAlchemy-2.0.35.dist-info/RECORD,,
|
||||||
|
SQLAlchemy-2.0.35.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
SQLAlchemy-2.0.35.dist-info/WHEEL,sha256=lWey-nzGdePMz7fsIJ1fIMVKiFg5IkOcUVqkuIpdbws,109
|
||||||
|
SQLAlchemy-2.0.35.dist-info/top_level.txt,sha256=rp-ZgB7D8G11ivXON5VGPjupT1voYmWqkciDt5Uaw_Q,11
|
||||||
|
sqlalchemy/__init__.py,sha256=xHEMNoAWZaZfX2Zdm2gnVT8EWjaBfg6HpzG4ncSmPrk,13033
|
||||||
|
sqlalchemy/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/events.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/exc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/inspection.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/log.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/schema.cpython-312.pyc,,
|
||||||
|
sqlalchemy/__pycache__/types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/connectors/__init__.py,sha256=PzXPqZqi3BzEnrs1eW0DcsR4lyknAzhhN9rWcQ97hb4,476
|
||||||
|
sqlalchemy/connectors/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/connectors/__pycache__/aioodbc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/connectors/__pycache__/asyncio.cpython-312.pyc,,
|
||||||
|
sqlalchemy/connectors/__pycache__/pyodbc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/connectors/aioodbc.py,sha256=GSTiNMO9h0qjPxgqaxDwWZ8HvhWMFNVR6MJQnN1oc40,5288
|
||||||
|
sqlalchemy/connectors/asyncio.py,sha256=Hq2bkXmG6-KO_RfCrwMqx4oGH-uH1Z1WWKqPWNjz8p4,6138
|
||||||
|
sqlalchemy/connectors/pyodbc.py,sha256=t7AjyxIOnaWg3CrlUEpBs4Y5l0HFdNt3P_cSSKhbi0Y,8501
|
||||||
|
sqlalchemy/cyextension/__init__.py,sha256=GzhhN8cjMnDTE0qerlUlpbrNmFPHQWCZ4Gk74OAxl04,244
|
||||||
|
sqlalchemy/cyextension/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/cyextension/collections.cpython-312-darwin.so,sha256=il8u1J1cKrEkdBCgsLLFiKjFfXX1AI3-EhZyOgT4XR4,247360
|
||||||
|
sqlalchemy/cyextension/collections.pyx,sha256=L7DZ3DGKpgw2MT2ZZRRxCnrcyE5pU1NAFowWgAzQPEc,12571
|
||||||
|
sqlalchemy/cyextension/immutabledict.cpython-312-darwin.so,sha256=y2tPZbpLxHTirSCbdJIYLRCUSirqE5dVfDkw0Lm-ukY,122336
|
||||||
|
sqlalchemy/cyextension/immutabledict.pxd,sha256=3x3-rXG5eRQ7bBnktZ-OJ9-6ft8zToPmTDOd92iXpB0,291
|
||||||
|
sqlalchemy/cyextension/immutabledict.pyx,sha256=KfDTYbTfebstE8xuqAtuXsHNAK0_b5q_ymUiinUe_xs,3535
|
||||||
|
sqlalchemy/cyextension/processors.cpython-312-darwin.so,sha256=DjD52jnGEA1gbUx6GyQg8_6T55D3lK-7lilRb-V-UY4,102928
|
||||||
|
sqlalchemy/cyextension/processors.pyx,sha256=R1rHsGLEaGeBq5VeCydjClzYlivERIJ9B-XLOJlf2MQ,1792
|
||||||
|
sqlalchemy/cyextension/resultproxy.cpython-312-darwin.so,sha256=S6n7RZ8K0FxpTN_Oequ-d11VZskDOYrby4W_BSCFiOc,104864
|
||||||
|
sqlalchemy/cyextension/resultproxy.pyx,sha256=eWLdyBXiBy_CLQrF5ScfWJm7X0NeelscSXedtj1zv9Q,2725
|
||||||
|
sqlalchemy/cyextension/util.cpython-312-darwin.so,sha256=ZICErQKs5qfvOCgJNdN9cdiX-wLOvVc5oNHlHVLH4Fo,122296
|
||||||
|
sqlalchemy/cyextension/util.pyx,sha256=B85orxa9LddLuQEaDoVSq1XmAXIbLKxrxpvuB8ogV_o,2530
|
||||||
|
sqlalchemy/dialects/__init__.py,sha256=Kos9Gf5JZg1Vg6GWaCqEbD6e0r1jCwCmcnJIfcxDdcY,1770
|
||||||
|
sqlalchemy/dialects/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/__pycache__/_typing.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/_typing.py,sha256=hyv0nKucX2gI8ispB1IsvaUgrEPn9zEcq9hS7kfstEw,888
|
||||||
|
sqlalchemy/dialects/mssql/__init__.py,sha256=r5t8wFRNtBQoiUWh0WfIEWzXZW6f3D0uDt6NZTW_7Cc,1880
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/aioodbc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/information_schema.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/json.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/pymssql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/__pycache__/pyodbc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mssql/aioodbc.py,sha256=UQd9ecSMIML713TDnLAviuBVJle7P7i1FtqGZZePk2Y,2022
|
||||||
|
sqlalchemy/dialects/mssql/base.py,sha256=TQekFOsor8Rc-cnDPmbq_JLQekKrHPtUdBdNsCYFw7w,132447
|
||||||
|
sqlalchemy/dialects/mssql/information_schema.py,sha256=HswjDc6y0mPXCf_x6VyylHlBdBa4PSY6Evxmmlch700,8084
|
||||||
|
sqlalchemy/dialects/mssql/json.py,sha256=evUACW2O62TAPq8B7QIPagz7jfc664ql9ms68JqiYzg,4816
|
||||||
|
sqlalchemy/dialects/mssql/provision.py,sha256=ZAtt6Div9NLIngMs8kyloxfphw0KDNMsnRCAVd7-esE,5593
|
||||||
|
sqlalchemy/dialects/mssql/pymssql.py,sha256=LAv43q4vBCB85OsAwHQItaQUYTYIO0QJ-jvzaBrswmY,4097
|
||||||
|
sqlalchemy/dialects/mssql/pyodbc.py,sha256=vwM-vBlmRwrqxOc73P0sFOrBSwn24wzc5IkEOpalbXQ,27056
|
||||||
|
sqlalchemy/dialects/mysql/__init__.py,sha256=bxbi4hkysUK2OOVvr1F49akUj1cky27kKb07tgFzI9U,2153
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/aiomysql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/asyncmy.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/cymysql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/dml.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/enumerated.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/expression.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/json.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/mariadb.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/mariadbconnector.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/mysqlconnector.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/mysqldb.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/pymysql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/pyodbc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/reflection.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/reserved_words.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/__pycache__/types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/mysql/aiomysql.py,sha256=-oMZnCqNsSki8mlQRTWIwiQPT1OVdZIuANkb90q8LAs,9999
|
||||||
|
sqlalchemy/dialects/mysql/asyncmy.py,sha256=YpuuOh8VknEeqHqUXQGfQ3jhfO3Xb-vZv78Jq5cscJ0,10067
|
||||||
|
sqlalchemy/dialects/mysql/base.py,sha256=8shrZRSnVwDXtl6ybaO6cvul_RZ34zEWqvpYW5sNfOQ,120986
|
||||||
|
sqlalchemy/dialects/mysql/cymysql.py,sha256=eXT1ry0w_qRxjiO24M980c-8PZ9qSsbhqBHntjEiKB0,2300
|
||||||
|
sqlalchemy/dialects/mysql/dml.py,sha256=HXJMAvimJsqvhj3UZO4vW_6LkF5RqaKbHvklAjor7yU,7645
|
||||||
|
sqlalchemy/dialects/mysql/enumerated.py,sha256=ipEPPQqoXfFwcywNdcLlZCEzHBtnitHRah1Gn6nItcg,8448
|
||||||
|
sqlalchemy/dialects/mysql/expression.py,sha256=lsmQCHKwfPezUnt27d2kR6ohk4IRFCA64KBS16kx5dc,4097
|
||||||
|
sqlalchemy/dialects/mysql/json.py,sha256=l6MEZ0qp8FgiRrIQvOMhyEJq0q6OqiEnvDTx5Cbt9uQ,2269
|
||||||
|
sqlalchemy/dialects/mysql/mariadb.py,sha256=kTfBLioLKk4JFFst4TY_iWqPtnvvQXFHknLfm89H2N8,853
|
||||||
|
sqlalchemy/dialects/mysql/mariadbconnector.py,sha256=_S1aV93kyP52Nvj7HR9weThML4oUvSLsLqiVFdoLR2o,8623
|
||||||
|
sqlalchemy/dialects/mysql/mysqlconnector.py,sha256=oq3mtsNOMldUjs32JbJG2u3Hy3DObyVzUUMYfOkwkHg,5729
|
||||||
|
sqlalchemy/dialects/mysql/mysqldb.py,sha256=qUBbA6STeYGozutyTxHCo5p1W3p59QFFS2FwCgPrjBA,9503
|
||||||
|
sqlalchemy/dialects/mysql/provision.py,sha256=Jnk8UO9_Apd2odR2IQFLrscCfAmYxuBKcB8giS3bBog,3575
|
||||||
|
sqlalchemy/dialects/mysql/pymysql.py,sha256=GUnSHd2M2uKjmN46Hheymtm26g7phEgwYOXrX0zLY8M,4083
|
||||||
|
sqlalchemy/dialects/mysql/pyodbc.py,sha256=072crI4qVyPhajYvHnsfFeSrNjLFVPIjBQKo5uyz5yk,4297
|
||||||
|
sqlalchemy/dialects/mysql/reflection.py,sha256=3u34YwT1JJh3uThGZJZ3FKdnUcT7v08QB-tAl1r7VRk,22834
|
||||||
|
sqlalchemy/dialects/mysql/reserved_words.py,sha256=ucKX2p2c3UnMq2ayZuOHuf73eXhu7SKsOsTlIN1Q83I,9258
|
||||||
|
sqlalchemy/dialects/mysql/types.py,sha256=L5cTCsMT1pTedszNEM3jSxFNZEMcHQLprYCZ0vmfsnA,24343
|
||||||
|
sqlalchemy/dialects/oracle/__init__.py,sha256=p4-2gw7TT0bX_MoJXTGD4i8WHctYsK9kCRbkpzykBrc,1493
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/cx_oracle.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/dictionary.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/oracledb.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/__pycache__/types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/oracle/base.py,sha256=HykzMCkN1LSRteoEttWb_ln9Q0YmOJ5tLbJan7TuWZ4,119699
|
||||||
|
sqlalchemy/dialects/oracle/cx_oracle.py,sha256=q8Nyj15UZCE2TWOmxuWp5ZsxiCiGMzqfd_9UkmjIja0,55235
|
||||||
|
sqlalchemy/dialects/oracle/dictionary.py,sha256=7WMrbPkqo8ZdGjaEZyQr-5f2pajSOF1OTGb8P97z8-g,19519
|
||||||
|
sqlalchemy/dialects/oracle/oracledb.py,sha256=fZRKGqNIwW9LG4i8yDOXABrucbfzn_yC86Od-BJ3PcM,13619
|
||||||
|
sqlalchemy/dialects/oracle/provision.py,sha256=O9ZpF4OG6Cx4mMzLRfZwhs8dZjrJETWR402n9c7726A,8304
|
||||||
|
sqlalchemy/dialects/oracle/types.py,sha256=QK3hJvWzKnnCe3oD3rItwEEIwcoBze8qGg7VFOvVlIk,8231
|
||||||
|
sqlalchemy/dialects/postgresql/__init__.py,sha256=wwnNAq4wDQzrlPRzDNB06ayuq3L2HNO99nzeEvq-YcU,3892
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/_psycopg_common.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/array.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/asyncpg.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/dml.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/ext.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/hstore.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/json.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/named_types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/operators.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/pg8000.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/pg_catalog.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/psycopg.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/psycopg2.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/psycopg2cffi.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/ranges.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/__pycache__/types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/postgresql/_psycopg_common.py,sha256=7TudtgsPiSB8O5kX8W8KxcNYR8t5h_UHb86b_ChL0P8,5696
|
||||||
|
sqlalchemy/dialects/postgresql/array.py,sha256=bWcame7ntmI_Kx6gmBX0-chwADFdLHeCvaDQ4iX8id8,13734
|
||||||
|
sqlalchemy/dialects/postgresql/asyncpg.py,sha256=se1HXkikKQFcR2D-15jS6iKIaQs-M8Y8ke99ih0Y4NM,41132
|
||||||
|
sqlalchemy/dialects/postgresql/base.py,sha256=ed49Ode09deJF3jXr8V5sSHTwVoFVq0dlvNdP3mJaBQ,178989
|
||||||
|
sqlalchemy/dialects/postgresql/dml.py,sha256=Pc69Le6qzmUHHb1FT5zeUSD31dWm6SBgdCAGW89cs3s,11212
|
||||||
|
sqlalchemy/dialects/postgresql/ext.py,sha256=1bZ--iNh2O9ym7l2gXZX48yP3yMO4dqb9RpYro2Mj2Q,16262
|
||||||
|
sqlalchemy/dialects/postgresql/hstore.py,sha256=otAx-RTDfpi_tcXkMuQV0JOIXtYgevgnsikLKKOkI6U,11541
|
||||||
|
sqlalchemy/dialects/postgresql/json.py,sha256=73nmtG-7TN01DytjIJnG8CHa8Q7KwlRdN0bhx4fEAT0,11590
|
||||||
|
sqlalchemy/dialects/postgresql/named_types.py,sha256=3IV1ufo7zJjKmX4VtGDEnoXE6xEqLJAtGG82IiqHXwY,17594
|
||||||
|
sqlalchemy/dialects/postgresql/operators.py,sha256=NsAaWun_tL3d_be0fs9YL6T4LPKK6crnmFxxIJHgyeY,2808
|
||||||
|
sqlalchemy/dialects/postgresql/pg8000.py,sha256=3yoekiWSF-xnaWMqG76XrYPMqerg-42TdmfsW_ivK9E,18640
|
||||||
|
sqlalchemy/dialects/postgresql/pg_catalog.py,sha256=hY3NXEUHxTWD4umhd2aowNu3laC-61Q_qQ_pReyXTUM,9254
|
||||||
|
sqlalchemy/dialects/postgresql/provision.py,sha256=t6TZj0XaWG9zrpCjNr0oJRjAC_WQzaNdp3kaKJIbS8I,5770
|
||||||
|
sqlalchemy/dialects/postgresql/psycopg.py,sha256=ACkfuT87vUJEW4kJyUqDYTwlnl5u0FZFlDcvLzxNzFQ,23226
|
||||||
|
sqlalchemy/dialects/postgresql/psycopg2.py,sha256=kwEnflz5bAqJcuO_20eYiCtha_a4m_tg5_lppdDnaeU,31998
|
||||||
|
sqlalchemy/dialects/postgresql/psycopg2cffi.py,sha256=M7wAYSL6Pvt-4nbfacAHGyyw4XMKJ_bQZ1tc1pBtIdg,1756
|
||||||
|
sqlalchemy/dialects/postgresql/ranges.py,sha256=6CgV7qkxEMJ9AQsiibo_XBLJYzGh-2ZxpG83sRaesVY,32949
|
||||||
|
sqlalchemy/dialects/postgresql/types.py,sha256=Jfxqw9JaKNOq29JRWBublywgb3lLMyzx8YZI7CXpS2s,7300
|
||||||
|
sqlalchemy/dialects/sqlite/__init__.py,sha256=lp9DIggNn349M-7IYhUA8et8--e8FRExWD2V_r1LJk4,1182
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/aiosqlite.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/dml.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/json.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/pysqlcipher.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/__pycache__/pysqlite.cpython-312.pyc,,
|
||||||
|
sqlalchemy/dialects/sqlite/aiosqlite.py,sha256=g3qGV6jmiXabWyb3282g_Nmxtj1jThxGSe9C9yalb-U,12345
|
||||||
|
sqlalchemy/dialects/sqlite/base.py,sha256=P15AcHoVWS20mMNQqnCfj94owUsTEX2ULtRn290AoF0,97837
|
||||||
|
sqlalchemy/dialects/sqlite/dml.py,sha256=9GE55WvwoktKy2fHeT-Wbc9xPHgsbh5oBfd_fckMH5Q,8443
|
||||||
|
sqlalchemy/dialects/sqlite/json.py,sha256=Eoplbb_4dYlfrtmQaI8Xddd2suAIHA-IdbDQYM-LIhs,2777
|
||||||
|
sqlalchemy/dialects/sqlite/provision.py,sha256=UCpmwxf4IWlrpb2eLHGbPTpCFVbdI_KAh2mKtjiLYao,5632
|
||||||
|
sqlalchemy/dialects/sqlite/pysqlcipher.py,sha256=OL2S_05DK9kllZj6DOz7QtEl7jI7syxjW6woS725ii4,5356
|
||||||
|
sqlalchemy/dialects/sqlite/pysqlite.py,sha256=aDp47n0J509kl2hDchoaBKXEQVZtkux54DwfKytUAe4,28068
|
||||||
|
sqlalchemy/dialects/type_migration_guidelines.txt,sha256=-uHNdmYFGB7bzUNT6i8M5nb4j6j9YUKAtW4lcBZqsMg,8239
|
||||||
|
sqlalchemy/engine/__init__.py,sha256=Stb2oV6l8w65JvqEo6J4qtKoApcmOpXy3AAxQud4C1o,2818
|
||||||
|
sqlalchemy/engine/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/_py_processors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/_py_row.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/_py_util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/characteristics.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/create.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/cursor.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/default.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/events.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/interfaces.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/mock.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/processors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/reflection.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/result.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/row.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/strategies.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/url.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/__pycache__/util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/engine/_py_processors.py,sha256=j9i_lcYYQOYJMcsDerPxI0sVFBIlX5sqoYMdMJlgWPI,3744
|
||||||
|
sqlalchemy/engine/_py_row.py,sha256=wSqoUFzLOJ1f89kgDb6sJm9LUrF5LMFpXPcK1vUsKcs,3787
|
||||||
|
sqlalchemy/engine/_py_util.py,sha256=f2DI3AN1kv6EplelowesCVpwS8hSXNufRkZoQmJtSH8,2484
|
||||||
|
sqlalchemy/engine/base.py,sha256=frWSMmt3dlentYH4QNN3cijdGzp8NbunColUZwWsWgI,122958
|
||||||
|
sqlalchemy/engine/characteristics.py,sha256=N3kbvw_ApMh86wb5yAGnxtPYD4YRhYMWion1H_aVZBI,4765
|
||||||
|
sqlalchemy/engine/create.py,sha256=mYJtOG2ZKM8sgyfjpGpamW15RDU7JXi5s6iibbJHMIs,33206
|
||||||
|
sqlalchemy/engine/cursor.py,sha256=cFq61yrw76k-QR_xNUBWuL-Zeyb14ltG-6jo2Q2iuuw,76392
|
||||||
|
sqlalchemy/engine/default.py,sha256=2wwKKdsagb3QTajRSEw8Hl-EnQ-LmRxy822xOGyenHc,84648
|
||||||
|
sqlalchemy/engine/events.py,sha256=c0unNFFiHzTAvkUtXoJaxzMFMDwurBkHiiUhuN8qluc,37381
|
||||||
|
sqlalchemy/engine/interfaces.py,sha256=fcVHOmnMo7JZLHzgSKoK3QsdVHH7kJ_AmrDvwW9Ka3k,112936
|
||||||
|
sqlalchemy/engine/mock.py,sha256=yvpxgFmRw5G4QsHeF-ZwQGHKES-HqQOucTxFtN1uzdk,4179
|
||||||
|
sqlalchemy/engine/processors.py,sha256=XyfINKbo-2fjN-mW55YybvFyQMOil50_kVqsunahkNs,2379
|
||||||
|
sqlalchemy/engine/reflection.py,sha256=gwGs8y7x6py5z-ZWx3hQqQrwpHepMCTJyQcFwWJjPlw,75364
|
||||||
|
sqlalchemy/engine/result.py,sha256=j6BI4Wj2bziQNQG5OlG_Cm4KcNWY9AoYvTXVlJUU-D8,77603
|
||||||
|
sqlalchemy/engine/row.py,sha256=9AAQo9zYDL88GcZ3bjcQTwMT-YIcuGTSMAyTfmBJ_yM,12032
|
||||||
|
sqlalchemy/engine/strategies.py,sha256=DqFSWaXJPL-29Omot9O0aOcuGL8KmCGyOvnPGDkAJoE,442
|
||||||
|
sqlalchemy/engine/url.py,sha256=8eWkUaIUyDExOcJ2D4xJXRcn4OY1GQJ3Q2duSX6UGAg,30784
|
||||||
|
sqlalchemy/engine/util.py,sha256=bNirO8k1S8yOW61uNH-a9QrWtAJ9VGFgbiR0lk1lUQU,5682
|
||||||
|
sqlalchemy/event/__init__.py,sha256=KBrp622xojnC3FFquxa2JsMamwAbfkvzfv6Op0NKiYc,997
|
||||||
|
sqlalchemy/event/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/__pycache__/api.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/__pycache__/attr.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/__pycache__/legacy.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/__pycache__/registry.cpython-312.pyc,,
|
||||||
|
sqlalchemy/event/api.py,sha256=DtDVgjKSorOfp9MGJ7fgMWrj4seC_hkwF4D8CW1RFZU,8226
|
||||||
|
sqlalchemy/event/attr.py,sha256=X8QeHGK4ioSYht1vkhc11f606_mq_t91jMNIT314ubs,20751
|
||||||
|
sqlalchemy/event/base.py,sha256=270OShTD17-bSFUFnPtKdVnB0NFJZ2AouYPo1wT0aJw,15127
|
||||||
|
sqlalchemy/event/legacy.py,sha256=teMPs00fO-4g8a_z2omcVKkYce5wj_1uvJO2n2MIeuo,8227
|
||||||
|
sqlalchemy/event/registry.py,sha256=nfTSSyhjZZXc5wseWB4sXn-YibSc0LKX8mg17XlWmAo,10835
|
||||||
|
sqlalchemy/events.py,sha256=k-ZD38aSPD29LYhED7CBqttp5MDVVx_YSaWC2-cu9ec,525
|
||||||
|
sqlalchemy/exc.py,sha256=M_8-O1hd8i6gbyx-TapV400p_Lxq2QqTGMXUAO-YgCc,23976
|
||||||
|
sqlalchemy/ext/__init__.py,sha256=S1fGKAbycnQDV01gs-JWGaFQ9GCD4QHwKcU2wnugg_o,322
|
||||||
|
sqlalchemy/ext/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/associationproxy.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/automap.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/baked.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/compiler.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/horizontal_shard.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/hybrid.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/indexable.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/instrumentation.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/mutable.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/orderinglist.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/__pycache__/serializer.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/associationproxy.py,sha256=5O5ANHARO8jytvqBQmOu-QjNVE4Hh3tfYquqKAj5ajs,65771
|
||||||
|
sqlalchemy/ext/asyncio/__init__.py,sha256=1OqSxEyIUn7RWLGyO12F-jAUIvk1I6DXlVy80-Gvkds,1317
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/engine.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/exc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/result.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/scoping.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/__pycache__/session.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/asyncio/base.py,sha256=fl7wxZD9KjgFiCtG3WXrYjHEvanamcsodCqq9pH9lOk,8905
|
||||||
|
sqlalchemy/ext/asyncio/engine.py,sha256=S_IRWX4QAjj2veLSu4Y3gKBIXkKQt7_2StJAK2_KUDY,48190
|
||||||
|
sqlalchemy/ext/asyncio/exc.py,sha256=8sII7VMXzs2TrhizhFQMzSfcroRtiesq8o3UwLfXSgQ,639
|
||||||
|
sqlalchemy/ext/asyncio/result.py,sha256=ID2eh-NHW-lnNFTxbKhje8fr-tnsucUsiw_jcpGcSPc,30409
|
||||||
|
sqlalchemy/ext/asyncio/scoping.py,sha256=UxHAFxtWKqA7TEozyN2h7MJyzSspTCrS-1SlgQLTExo,52608
|
||||||
|
sqlalchemy/ext/asyncio/session.py,sha256=mkFFC1C2mPuopz3BwkfSVTlp3vuIDc8hxiQx5ky5rvc,63103
|
||||||
|
sqlalchemy/ext/automap.py,sha256=r0mUSyogNyqdBL4m9AA1NXbLiTLQmtvyQymsssNEipo,61581
|
||||||
|
sqlalchemy/ext/baked.py,sha256=H6T1il7GY84BhzPFj49UECSpZh_eBuiHomA-QIsYOYQ,17807
|
||||||
|
sqlalchemy/ext/compiler.py,sha256=ONPoxoKD2yUS9R2-oOhmPsA7efm-Bs0BXo7HE1dGlsU,20391
|
||||||
|
sqlalchemy/ext/declarative/__init__.py,sha256=20psLdFQbbOWfpdXHZ0CTY6I1k4UqXvKemNVu1LvPOI,1818
|
||||||
|
sqlalchemy/ext/declarative/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/declarative/__pycache__/extensions.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/declarative/extensions.py,sha256=uCjN1GisQt54AjqYnKYzJdUjnGd2pZBW47WWdPlS7FE,19547
|
||||||
|
sqlalchemy/ext/horizontal_shard.py,sha256=wuwAPnHymln0unSBnyx-cpX0AfESKSsypaSQTYCvzDk,16750
|
||||||
|
sqlalchemy/ext/hybrid.py,sha256=IYkCaPZ29gm2cPKPg0cWMkLCEqMykD8-JJTvgacGbmc,52458
|
||||||
|
sqlalchemy/ext/indexable.py,sha256=UkTelbydKCdKelzbv3HWFFavoET9WocKaGRPGEOVfN8,11032
|
||||||
|
sqlalchemy/ext/instrumentation.py,sha256=sg8ghDjdHSODFXh_jAmpgemnNX1rxCeeXEG3-PMdrNk,15707
|
||||||
|
sqlalchemy/ext/mutable.py,sha256=L5ZkHBGYhMaqO75Xtyrk2DBR44RDk0g6Rz2HzHH0F8Q,37355
|
||||||
|
sqlalchemy/ext/mypy/__init__.py,sha256=0WebDIZmqBD0OTq5JLtd_PmfF9JGxe4d4Qv3Ml3PKUg,241
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/apply.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/decl_class.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/infer.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/names.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/plugin.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/__pycache__/util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/ext/mypy/apply.py,sha256=Aek_-XA1eXihT4attxhfE43yBKtCgsxBSb--qgZKUqc,10550
|
||||||
|
sqlalchemy/ext/mypy/decl_class.py,sha256=1vVJRII2apnLTUbc5HkJS6Z2GueaUv_eKvhbqh7Wik4,17384
|
||||||
|
sqlalchemy/ext/mypy/infer.py,sha256=KVnmLFEVS33Al8pUKI7MJbJQu3KeveBUMl78EluBORw,19369
|
||||||
|
sqlalchemy/ext/mypy/names.py,sha256=Q3ef8XQBgVm9WUwlItqlYCXDNi_kbV5DdLEgbtEMEI8,10479
|
||||||
|
sqlalchemy/ext/mypy/plugin.py,sha256=74ML8LI9xar0V86oCxnPFv5FQGEEfUzK64vOay4BKFs,9750
|
||||||
|
sqlalchemy/ext/mypy/util.py,sha256=DKRaurkXHI2lAMAAcEO5GLXbX_m2Xqy7l_juh8Byf5U,9960
|
||||||
|
sqlalchemy/ext/orderinglist.py,sha256=TGYbsGH72wEZcFNQDYDsZg9OSPuzf__P8YX8_2HtYUo,14384
|
||||||
|
sqlalchemy/ext/serializer.py,sha256=D0g4jMZkRk0Gjr0L-FZe81SR63h0Zs-9JzuWtT_SD7k,6140
|
||||||
|
sqlalchemy/future/__init__.py,sha256=q2mw-gxk_xoxJLEvRoyMha3vO1xSRHrslcExOHZwmPA,512
|
||||||
|
sqlalchemy/future/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/future/__pycache__/engine.cpython-312.pyc,,
|
||||||
|
sqlalchemy/future/engine.py,sha256=AgIw6vMsef8W6tynOTkxsjd6o_OQDwGjLdbpoMD8ue8,495
|
||||||
|
sqlalchemy/inspection.py,sha256=MF-LE358wZDUEl1IH8-Uwt2HI65EsQpQW5o5udHkZwA,5063
|
||||||
|
sqlalchemy/log.py,sha256=8x9UR3nj0uFm6or6bQF-JWb4fYv2zOeQjG_w-0wOJFA,8607
|
||||||
|
sqlalchemy/orm/__init__.py,sha256=ZYys5nL3RFUDCMOLFDBrRI52F6er3S1U1OY9TeORuKs,8463
|
||||||
|
sqlalchemy/orm/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/_orm_constructors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/_typing.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/attributes.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/bulk_persistence.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/clsregistry.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/collections.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/context.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/decl_api.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/decl_base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/dependency.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/descriptor_props.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/dynamic.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/evaluator.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/events.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/exc.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/identity.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/instrumentation.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/interfaces.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/loading.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/mapped_collection.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/mapper.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/path_registry.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/persistence.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/properties.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/query.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/relationships.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/scoping.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/session.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/state.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/state_changes.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/strategies.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/strategy_options.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/sync.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/unitofwork.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/__pycache__/writeonly.cpython-312.pyc,,
|
||||||
|
sqlalchemy/orm/_orm_constructors.py,sha256=c4RMiYKIXzOTjuPIBbyRIzpizYjUBm2sd7k0n1vqb2o,100717
|
||||||
|
sqlalchemy/orm/_typing.py,sha256=DVBfpHmDVK4x1zxaGJPY2GoTrAsyR6uexv20Lzf1afc,4973
|
||||||
|
sqlalchemy/orm/attributes.py,sha256=lorOHBJvJJYndOuafWJhHBbQ1pR6FAyimhqz-mErBRQ,92534
|
||||||
|
sqlalchemy/orm/base.py,sha256=re6A8ooMxLyfCAeQfhBwwxeJQkiH7EtzzOZIVIiTPlw,27466
|
||||||
|
sqlalchemy/orm/bulk_persistence.py,sha256=gNp2gFsGvV-5NhOPBL51TqKgR3ZRrS43jSwqUF-SwgY,71430
|
||||||
|
sqlalchemy/orm/clsregistry.py,sha256=IjoDZwWpjG42ji59L4M1EZvjBEoXPZykzENDtKWxU8A,17974
|
||||||
|
sqlalchemy/orm/collections.py,sha256=WEKuUCRgLhDhJEIBhZ21UrE0pBOyRm2zxD20GvbgA9g,52243
|
||||||
|
sqlalchemy/orm/context.py,sha256=FMPyw07OA9OXWQ32RQx52AEa2xTLSkqdYgx9R_yN1x0,112955
|
||||||
|
sqlalchemy/orm/decl_api.py,sha256=_WPKQ_vSE5k2TLtNmkaxxYmvbhZvkRMrrvCeDxdqDQE,63998
|
||||||
|
sqlalchemy/orm/decl_base.py,sha256=FTHf3bCVlg52KR6JWVEwuG3XjOaGQ5KJMYFYXastGhw,82832
|
||||||
|
sqlalchemy/orm/dependency.py,sha256=hgjksUWhgbmgHK5GdJdiDCBgDAIGQXIrY-Tj79tbL2k,47631
|
||||||
|
sqlalchemy/orm/descriptor_props.py,sha256=dR_h4Gvdtpcdp4sj_ZOR4P5Nng2J2vhsvFHouRLlntc,37244
|
||||||
|
sqlalchemy/orm/dynamic.py,sha256=rWAZ-nfAkREuNjt8e_FRdqYrvHDdbODn1CcfyP8Y18k,9816
|
||||||
|
sqlalchemy/orm/evaluator.py,sha256=tRETz4dNZ71VsEA8nG0hpefByB-W0zBt02IxcSR5H2g,12353
|
||||||
|
sqlalchemy/orm/events.py,sha256=1PiGT7JMUWTDAb3X1T79P02BMVDmcWEpatz1FwpLqoA,127777
|
||||||
|
sqlalchemy/orm/exc.py,sha256=IP40P-wOeXhkYk0YizuTC3wqm6W9cPTaQU08f5MMaQ0,7413
|
||||||
|
sqlalchemy/orm/identity.py,sha256=jHdCxCpCyda_8mFOfGmN_Pr0XZdKiU-2hFZshlNxbHs,9249
|
||||||
|
sqlalchemy/orm/instrumentation.py,sha256=M-kZmkUvHUxtf-0mCA8RIM5QmMH1hWlYR_pKMwaidjA,24321
|
||||||
|
sqlalchemy/orm/interfaces.py,sha256=Hmf1BjbfOarZRgMlruqghR7cgH2xyugA9v5t0x-a-wU,48502
|
||||||
|
sqlalchemy/orm/loading.py,sha256=9RacpzFOWbuKgPRWHFmyIvD4fYCLAnkpwBFASyQ2CoI,58277
|
||||||
|
sqlalchemy/orm/mapped_collection.py,sha256=zK3d3iozORzDruBUrAmkVC0RR3Orj5szk-TSQ24xzIU,19682
|
||||||
|
sqlalchemy/orm/mapper.py,sha256=bfoRzNKKnjF-CDvr2Df7HZC9TepvtuQ49LRz_fW7DGQ,171088
|
||||||
|
sqlalchemy/orm/path_registry.py,sha256=sJZMv_WPqUpHfQtKWaX3WYFeKBcNJ8C3wOM2mkBGkTE,25920
|
||||||
|
sqlalchemy/orm/persistence.py,sha256=dzyB2JOXNwQgaCbN8kh0sEz00WFePr48qf8NWVCUZH8,61701
|
||||||
|
sqlalchemy/orm/properties.py,sha256=eDPFzxYUgdM3uWjHywnb1XW-i0tVKKyx7A2MCD31GQU,29306
|
||||||
|
sqlalchemy/orm/query.py,sha256=Cf0e94-u1XyoXJoOAmr4iFvtCwNY98kxUYyMPenaWTE,117708
|
||||||
|
sqlalchemy/orm/relationships.py,sha256=dS5SY0v1MiD7iCNnAQlHaI6prUQhL5EkXT7ijc8FR8E,128644
|
||||||
|
sqlalchemy/orm/scoping.py,sha256=rJVc7_Lic4V00HZ-UvYFWkVpXqdrMayRmIs4fIwH1UA,78688
|
||||||
|
sqlalchemy/orm/session.py,sha256=CZJTQ-wPwIy0c3AMFxgJnBgaft6eEf4JzcCLcaaCSjg,195979
|
||||||
|
sqlalchemy/orm/state.py,sha256=327-F4TG29s6mLC8oWRiO2PuvYIUZzY1MqUPjtUy7M4,37670
|
||||||
|
sqlalchemy/orm/state_changes.py,sha256=qKYg7NxwrDkuUY3EPygAztym6oAVUFcP2wXn7QD3Mz4,6815
|
||||||
|
sqlalchemy/orm/strategies.py,sha256=U5EL1FBXOmkIV5HsryIlTvfQfoajYGCnvTbuKBnH0pQ,116224
|
||||||
|
sqlalchemy/orm/strategy_options.py,sha256=oeDl_rMDNAC_90N7ytsni-psXWAeQMhABQFyKBSmai0,85353
|
||||||
|
sqlalchemy/orm/sync.py,sha256=g7iZfSge1HgxMk9SKRgUgtHEbpbZ1kP_CBqOIdTOXqc,5779
|
||||||
|
sqlalchemy/orm/unitofwork.py,sha256=fiVaqcymbDDHRa1NjS90N9Z466nd5pkJOEi1dHO6QLY,27033
|
||||||
|
sqlalchemy/orm/util.py,sha256=Q0JT2JydyGiNiYT8AVe9B6jOdBRVHSOVDIcWOsXXIUQ,80929
|
||||||
|
sqlalchemy/orm/writeonly.py,sha256=SYu2sAaHZONk2pW4PmtE871LG-O0P_bjidvKzY1H_zI,22305
|
||||||
|
sqlalchemy/pool/__init__.py,sha256=qiDdq4r4FFAoDrK6ncugF_i6usi_X1LeJt-CuBHey0s,1804
|
||||||
|
sqlalchemy/pool/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/pool/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/pool/__pycache__/events.cpython-312.pyc,,
|
||||||
|
sqlalchemy/pool/__pycache__/impl.cpython-312.pyc,,
|
||||||
|
sqlalchemy/pool/base.py,sha256=WF4az4ZKuzQGuKeSJeyexaYjmWZUvYdC6KIi8zTGodw,52236
|
||||||
|
sqlalchemy/pool/events.py,sha256=xGjkIUZl490ZDtCHqnQF9ZCwe2Jv93eGXmnQxftB11E,13147
|
||||||
|
sqlalchemy/pool/impl.py,sha256=JwpALSkH-pCoO_6oENbkHYY00Jx9nlttyoI61LivRNc,18944
|
||||||
|
sqlalchemy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
sqlalchemy/schema.py,sha256=dKiWmgHYjcKQ4TiiD6vD0UMmIsD8u0Fsor1M9AAeGUs,3194
|
||||||
|
sqlalchemy/sql/__init__.py,sha256=UNa9EUiYWoPayf-FzNcwVgQvpsBdInPZfpJesAStN9o,5820
|
||||||
|
sqlalchemy/sql/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_dml_constructors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_elements_constructors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_orm_types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_py_util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_selectable_constructors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/_typing.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/annotation.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/cache_key.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/coercions.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/compiler.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/crud.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/ddl.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/default_comparator.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/dml.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/elements.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/events.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/expression.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/functions.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/lambdas.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/naming.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/operators.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/roles.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/schema.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/selectable.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/sqltypes.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/traversals.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/type_api.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/__pycache__/visitors.cpython-312.pyc,,
|
||||||
|
sqlalchemy/sql/_dml_constructors.py,sha256=YdBJex0MCVACv4q2nl_ii3uhxzwU6aDB8zAsratX5UQ,3867
|
||||||
|
sqlalchemy/sql/_elements_constructors.py,sha256=1SX6o1ezeB8C9DAa2m0WxmfhM3ji3FeCprXFQkNerNY,63048
|
||||||
|
sqlalchemy/sql/_orm_types.py,sha256=T-vjcry4C1y0GToFKVxQCnmly_-Zsq4IO4SHN6bvUF4,625
|
||||||
|
sqlalchemy/sql/_py_util.py,sha256=hiM9ePbRSGs60bAMxPFuJCIC_p9SQ1VzqXGiPchiYwE,2173
|
||||||
|
sqlalchemy/sql/_selectable_constructors.py,sha256=wjE6HrLm9cR7bxvZXT8sFLUqT6t_J9G1XyQCnYmBDl0,18780
|
||||||
|
sqlalchemy/sql/_typing.py,sha256=oqwrYHVMtK-AuKGH9c4SgfiOEJUt5vjkzSEzzscMHkM,12771
|
||||||
|
sqlalchemy/sql/annotation.py,sha256=aqbbVz9kfbCT3_66CZ9GEirVN197Cukoqt8rq48FgkQ,18245
|
||||||
|
sqlalchemy/sql/base.py,sha256=M1b-Tg49ikUW2mnZv0aI38oASG6dgeo4jBNWDgJgAg8,73925
|
||||||
|
sqlalchemy/sql/cache_key.py,sha256=0Db8mR8IrpBgdzXs4TGTt98LOpL3c7KABd72MAPKUQQ,33668
|
||||||
|
sqlalchemy/sql/coercions.py,sha256=KjrVc2ks6cx_o6-_Zpu6uPuNGjJy2xvFzXy8z5oshQg,40628
|
||||||
|
sqlalchemy/sql/compiler.py,sha256=hrTptbOKIgVIHapywj4Lk5OMwpXvHS-KGg3odFwlo-I,274687
|
||||||
|
sqlalchemy/sql/crud.py,sha256=HBX4QPtW_PYYJmIKfNr-wE8IdEr963N24WXzFBUZOo0,56514
|
||||||
|
sqlalchemy/sql/ddl.py,sha256=CIqMilCKfuQnF0lrZsQdTxgrbXqcTauKr0Ojzj77PFQ,45602
|
||||||
|
sqlalchemy/sql/default_comparator.py,sha256=utXWsZVGEjflhFfCT4ywa6RnhORc1Rryo87Hga71Rps,16707
|
||||||
|
sqlalchemy/sql/dml.py,sha256=pn0Lm1ofC5qVZzwGWFW73lPCiNba8OsTeemurJgwRyg,65614
|
||||||
|
sqlalchemy/sql/elements.py,sha256=YfccXzQc9DlgF8q15kDf-zKBUY_vpIe0FGaVDBPoic4,176544
|
||||||
|
sqlalchemy/sql/events.py,sha256=iC_Q1Htm1Aobt5tOYxWfHHqNpoytrULORmUKcusH_-E,18290
|
||||||
|
sqlalchemy/sql/expression.py,sha256=VMX-dLpsZYnVRJpYNDozDUgaj7iQ0HuewUKVefD57PE,7586
|
||||||
|
sqlalchemy/sql/functions.py,sha256=kMMYplvuIHFAPwxBI03SizwaLcYEHzysecWk-R1V-JM,63762
|
||||||
|
sqlalchemy/sql/lambdas.py,sha256=DP0Qz7Ypo8QhzMwygGHYgRhwJMx-rNezO1euouH3iYU,49292
|
||||||
|
sqlalchemy/sql/naming.py,sha256=ZHs1qSV3ou8TYmZ92uvU3sfdklUQlIz4uhe330n05SU,6858
|
||||||
|
sqlalchemy/sql/operators.py,sha256=himArRqBzrljob3Zfhi_ZS-Jleg1u6YFp0g3d7Co6IM,76106
|
||||||
|
sqlalchemy/sql/roles.py,sha256=pOsVn_OZD7mF2gJByHf24Rjopt0_Hu3dUCEOK5t4KS8,7662
|
||||||
|
sqlalchemy/sql/schema.py,sha256=iFleWHkxi-3mKGiK_N1TzUqxnNwOpypB4bWDuAVQe8c,229717
|
||||||
|
sqlalchemy/sql/selectable.py,sha256=cgyV0AsPy4CXAFdhMiTCkbgaHiFilW9sclzxlHJKH3o,236460
|
||||||
|
sqlalchemy/sql/sqltypes.py,sha256=fajBVE_CCJykrQpOOnb8_HFOKCSoUF48AxljJymvGk4,127330
|
||||||
|
sqlalchemy/sql/traversals.py,sha256=3ScTC1fh1-y8Y478h_2Azmd2xdQdWPWkDve4YgrwMf8,33664
|
||||||
|
sqlalchemy/sql/type_api.py,sha256=q_FieFRALHiRkhy5Bj-cVgFHa7DXF1dP23FaRRYKeho,83717
|
||||||
|
sqlalchemy/sql/util.py,sha256=qGHQF-tPCj-m1FBerzT7weCanGcXU7dK5m-W7NHio-4,48077
|
||||||
|
sqlalchemy/sql/visitors.py,sha256=71wdVvhhZL4nJvVwFAs6ssaW-qZgNRSmKjpAcOzF_TA,36317
|
||||||
|
sqlalchemy/testing/__init__.py,sha256=zgitAYzsCWT_U48ZiifXHHLJFo8nZBYmI-5TueA4_lE,3160
|
||||||
|
sqlalchemy/testing/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/assertions.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/assertsql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/asyncio.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/config.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/engines.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/entities.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/exclusions.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/pickleable.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/profiling.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/provision.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/requirements.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/schema.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/util.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/__pycache__/warnings.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/assertions.py,sha256=gL0rA7CCZJbcVgvWOPV91tTZTRwQc1_Ta0-ykBn83Ew,31439
|
||||||
|
sqlalchemy/testing/assertsql.py,sha256=IgQG7l94WaiRP8nTbilJh1ZHZl125g7GPq-S5kmQZN0,16817
|
||||||
|
sqlalchemy/testing/asyncio.py,sha256=kM8uuOqDBagZF0r9xvGmsiirUVLUQ_KBzjUFU67W-b8,3830
|
||||||
|
sqlalchemy/testing/config.py,sha256=AqyH1qub_gDqX0BvlL-JBQe7N-t2wo8655FtwblUNOY,12090
|
||||||
|
sqlalchemy/testing/engines.py,sha256=HFJceEBD3Q_TTFQMTtIV5wGWO_a7oUgoKtUF_z636SM,13481
|
||||||
|
sqlalchemy/testing/entities.py,sha256=IphFegPKbff3Un47jY6bi7_MQXy6qkx_50jX2tHZJR4,3354
|
||||||
|
sqlalchemy/testing/exclusions.py,sha256=T8B01hmm8WVs-EKcUOQRzabahPqblWJfOidi6bHJ6GA,12460
|
||||||
|
sqlalchemy/testing/fixtures/__init__.py,sha256=dMClrIoxqlYIFpk2ia4RZpkbfxsS_3EBigr9QsPJ66g,1198
|
||||||
|
sqlalchemy/testing/fixtures/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/fixtures/__pycache__/base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/fixtures/__pycache__/mypy.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/fixtures/__pycache__/orm.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/fixtures/__pycache__/sql.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/fixtures/base.py,sha256=9r_J2ksiTzClpUxW0TczICHrWR7Ny8PV8IsBz6TsGFI,12256
|
||||||
|
sqlalchemy/testing/fixtures/mypy.py,sha256=gdxiwNFIzDlNGSOdvM3gbwDceVCC9t8oM5kKbwyhGBk,11973
|
||||||
|
sqlalchemy/testing/fixtures/orm.py,sha256=8EFbnaBbXX_Bf4FcCzBUaAHgyVpsLGBHX16SGLqE3Fg,6095
|
||||||
|
sqlalchemy/testing/fixtures/sql.py,sha256=KZMjco9_3dsuspmkew5Ejp88Wlr9PsSBB1qeJGFxQAk,15900
|
||||||
|
sqlalchemy/testing/pickleable.py,sha256=U9mIqk-zaxq9Xfy7HErP7UrKgTov-A3QFnhZh-NiOjI,2833
|
||||||
|
sqlalchemy/testing/plugin/__init__.py,sha256=79F--BIY_NTBzVRIlJGgAY5LNJJ3cD19XvrAo4X0W9A,247
|
||||||
|
sqlalchemy/testing/plugin/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/plugin/__pycache__/bootstrap.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/plugin/__pycache__/plugin_base.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/plugin/__pycache__/pytestplugin.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/plugin/bootstrap.py,sha256=oYScMbEW4pCnWlPEAq1insFruCXFQeEVBwo__i4McpU,1685
|
||||||
|
sqlalchemy/testing/plugin/plugin_base.py,sha256=BgNzWNEmgpK4CwhyblQQKnH-7FDKVi_Uul5vw8fFjBU,21578
|
||||||
|
sqlalchemy/testing/plugin/pytestplugin.py,sha256=6jkQHH2VQMD75k2As9CuWXmEy9jrscoFRhCNg6-PaTw,27656
|
||||||
|
sqlalchemy/testing/profiling.py,sha256=PbuPhRFbauFilUONeY3tV_Y_5lBkD7iCa8VVyH2Sk9Y,10148
|
||||||
|
sqlalchemy/testing/provision.py,sha256=3qFor_sN1FFlS7odUGkKqLUxGmQZC9XM67I9vQ_zeXo,14626
|
||||||
|
sqlalchemy/testing/requirements.py,sha256=Z__o-1Rj9B7dI8E_l3qsKTvsg0rK198vB0A1p7A5dcM,52832
|
||||||
|
sqlalchemy/testing/schema.py,sha256=lr4GkGrGwagaHMuSGzWdzkMaj3HnS7dgfLLWfxt__-U,6513
|
||||||
|
sqlalchemy/testing/suite/__init__.py,sha256=Y5DRNG0Yl1u3ypt9zVF0Z9suPZeuO_UQGLl-wRgvTjU,722
|
||||||
|
sqlalchemy/testing/suite/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_cte.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_ddl.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_deprecations.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_dialect.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_insert.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_reflection.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_results.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_rowcount.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_select.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_sequence.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_types.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_unicode_ddl.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/__pycache__/test_update_delete.cpython-312.pyc,,
|
||||||
|
sqlalchemy/testing/suite/test_cte.py,sha256=6zBC3W2OwX1Xs-HedzchcKN2S7EaLNkgkvV_JSZ_Pq0,6451
|
||||||
|
sqlalchemy/testing/suite/test_ddl.py,sha256=1Npkf0C_4UNxphthAGjG078n0vPEgnSIHpDu5MfokxQ,12031
|
||||||
|
sqlalchemy/testing/suite/test_deprecations.py,sha256=BcJxZTcjYqeOAENVElCg3hVvU6fkGEW3KGBMfnW8bng,5337
|
||||||
|
sqlalchemy/testing/suite/test_dialect.py,sha256=EH4ZQWbnGdtjmx5amZtTyhYmrkXJCvW1SQoLahoE7uk,22923
|
||||||
|
sqlalchemy/testing/suite/test_insert.py,sha256=9azifj6-OCD7s8h_tAO1uPw100ibQv8YoKc_VA3hn3c,18824
|
||||||
|
sqlalchemy/testing/suite/test_reflection.py,sha256=7sML8-owubSQeEM7Ve6LbnB8uIVlNV00WWepKwII2a8,109648
|
||||||
|
sqlalchemy/testing/suite/test_results.py,sha256=X720GafdA4p75SOGS93j-dXkt6QDEnnJbU2bh18VCcg,16914
|
||||||
|
sqlalchemy/testing/suite/test_rowcount.py,sha256=3KDTlRgjpQ1OVfp__1cv8Hvq4CsDKzmrhJQ_WIJWoJg,7900
|
||||||
|
sqlalchemy/testing/suite/test_select.py,sha256=ulRZQJlzkwwcewEyisuBEXVWFR0Wshz9MEDxYYiYLwQ,61732
|
||||||
|
sqlalchemy/testing/suite/test_sequence.py,sha256=66bCoy4xo99GBSaX6Hxb88foANAykLGRz1YEKbvpfuA,9923
|
||||||
|
sqlalchemy/testing/suite/test_types.py,sha256=K4MGHvnTtgqeksoQOBCZRVQYC7HoYO6Z6rVt5vj2t9o,67805
|
||||||
|
sqlalchemy/testing/suite/test_unicode_ddl.py,sha256=c3_eIxLyORuSOhNDP0jWKxPyUf3SwMFpdalxtquwqlM,6141
|
||||||
|
sqlalchemy/testing/suite/test_update_delete.py,sha256=yTiM2unnfOK9rK8ZkqeTTU_MkT-RsKFLmdYliniZfAY,3994
|
||||||
|
sqlalchemy/testing/util.py,sha256=qldXKw8gRJ4I2x3uXsBssYMqwatmcMFMTOveRQCmfDU,14469
|
||||||
|
sqlalchemy/testing/warnings.py,sha256=fJ-QJUY2zY2PPxZJKv9medW-BKKbCNbA4Ns_V3YwFXM,1546
|
||||||
|
sqlalchemy/types.py,sha256=cQFM-hFRmaf1GErun1qqgEs6QxufvzMuwKqj9tuMPpE,3168
|
||||||
|
sqlalchemy/util/__init__.py,sha256=B3bedg-LSQEscwqgmYYU-VENUX8_zAE3q9vb7tkfJNY,8277
|
||||||
|
sqlalchemy/util/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/_collections.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/_concurrency_py3k.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/_has_cy.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/_py_collections.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/compat.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/concurrency.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/deprecations.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/langhelpers.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/preloaded.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/queue.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/tool_support.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/topological.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/__pycache__/typing.cpython-312.pyc,,
|
||||||
|
sqlalchemy/util/_collections.py,sha256=aZoSAVOXnHBoYEsxDOi0O9odg9wqLbGb7PGjaWQKiyY,20078
|
||||||
|
sqlalchemy/util/_concurrency_py3k.py,sha256=zb0Bow2Y_QjTdaACEviBEEaFvqDuVvpJfmwCjaw8xNE,9170
|
||||||
|
sqlalchemy/util/_has_cy.py,sha256=wCQmeSjT3jaH_oxfCEtGk-1g0gbSpt5MCK5UcWdMWqk,1247
|
||||||
|
sqlalchemy/util/_py_collections.py,sha256=U6L5AoyLdgSv7cdqB4xxQbw1rpeJjyOZVXffgxgga8I,16714
|
||||||
|
sqlalchemy/util/compat.py,sha256=fJWqZVkW7qPY2l0DxK-7fHKjyp7b-wa-5wOlmuZlick,8724
|
||||||
|
sqlalchemy/util/concurrency.py,sha256=9lT_cMoO1fZNdY8QTUZ22oeSf-L5I-79Ke7chcBNPA0,3304
|
||||||
|
sqlalchemy/util/deprecations.py,sha256=YBwvvYhSB8LhasIZRKvg_-WNoVhPUcaYI1ZrnjDn868,11971
|
||||||
|
sqlalchemy/util/langhelpers.py,sha256=uIK3szZuq9aMnO-vEpSlNekNWv4I-E391e56bkTnUm0,65090
|
||||||
|
sqlalchemy/util/preloaded.py,sha256=az7NmLJLsqs0mtM9uBkIu10-841RYDq8wOyqJ7xXvqE,5904
|
||||||
|
sqlalchemy/util/queue.py,sha256=CaeSEaYZ57YwtmLdNdOIjT5PK_LCuwMFiO0mpp39ybM,10185
|
||||||
|
sqlalchemy/util/tool_support.py,sha256=9braZyidaiNrZVsWtGmkSmus50-byhuYrlAqvhjcmnA,6135
|
||||||
|
sqlalchemy/util/topological.py,sha256=N3M3Le7KzGHCmqPGg0ZBqixTDGwmFLhOZvBtc4rHL_g,3458
|
||||||
|
sqlalchemy/util/typing.py,sha256=lFcGo1dJbZIZ9drAnvef-PzP0cX4LMxMSwgk3lJBb0g,18182
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Wheel-Version: 1.0
|
||||||
|
Generator: setuptools (75.1.0)
|
||||||
|
Root-Is-Purelib: false
|
||||||
|
Tag: cp312-cp312-macosx_11_0_arm64
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
sqlalchemy
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
import __editable___aurora_db_0_1_0_finder; __editable___aurora_db_0_1_0_finder.install()
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
import __editable___aurora_inference_0_1_0_finder; __editable___aurora_inference_0_1_0_finder.install()
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import sys
|
||||||
|
from importlib.machinery import ModuleSpec, PathFinder
|
||||||
|
from importlib.machinery import all_suffixes as module_suffixes
|
||||||
|
from importlib.util import spec_from_file_location
|
||||||
|
from itertools import chain
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
MAPPING: dict[str, str] = {'aurora_db': '/Users/r3ap3r/Projects/AuroraMusic/packages/db'}
|
||||||
|
NAMESPACES: dict[str, list[str]] = {}
|
||||||
|
PATH_PLACEHOLDER = '__editable__.aurora_db-0.1.0.finder' + ".__path_hook__"
|
||||||
|
|
||||||
|
|
||||||
|
class _EditableFinder: # MetaPathFinder
|
||||||
|
@classmethod
|
||||||
|
def find_spec(cls, fullname: str, path=None, target=None) -> ModuleSpec | None: # type: ignore
|
||||||
|
# Top-level packages and modules (we know these exist in the FS)
|
||||||
|
if fullname in MAPPING:
|
||||||
|
pkg_path = MAPPING[fullname]
|
||||||
|
return cls._find_spec(fullname, Path(pkg_path))
|
||||||
|
|
||||||
|
# Handle immediate children modules (required for namespaces to work)
|
||||||
|
# To avoid problems with case sensitivity in the file system we delegate
|
||||||
|
# to the importlib.machinery implementation.
|
||||||
|
parent, _, child = fullname.rpartition(".")
|
||||||
|
if parent and parent in MAPPING:
|
||||||
|
return PathFinder.find_spec(fullname, path=[MAPPING[parent]])
|
||||||
|
|
||||||
|
# Other levels of nesting should be handled automatically by importlib
|
||||||
|
# using the parent path.
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _find_spec(cls, fullname: str, candidate_path: Path) -> ModuleSpec | None:
|
||||||
|
init = candidate_path / "__init__.py"
|
||||||
|
candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
|
||||||
|
for candidate in chain([init], candidates):
|
||||||
|
if candidate.exists():
|
||||||
|
return spec_from_file_location(fullname, candidate)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class _EditableNamespaceFinder: # PathEntryFinder
|
||||||
|
@classmethod
|
||||||
|
def _path_hook(cls, path) -> type[_EditableNamespaceFinder]:
|
||||||
|
if path == PATH_PLACEHOLDER:
|
||||||
|
return cls
|
||||||
|
raise ImportError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _paths(cls, fullname: str) -> list[str]:
|
||||||
|
paths = NAMESPACES[fullname]
|
||||||
|
if not paths and fullname in MAPPING:
|
||||||
|
paths = [MAPPING[fullname]]
|
||||||
|
# Always add placeholder, for 2 reasons:
|
||||||
|
# 1. __path__ cannot be empty for the spec to be considered namespace.
|
||||||
|
# 2. In the case of nested namespaces, we need to force
|
||||||
|
# import machinery to query _EditableNamespaceFinder again.
|
||||||
|
return [*paths, PATH_PLACEHOLDER]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def find_spec(cls, fullname: str, target=None) -> ModuleSpec | None: # type: ignore
|
||||||
|
if fullname in NAMESPACES:
|
||||||
|
spec = ModuleSpec(fullname, None, is_package=True)
|
||||||
|
spec.submodule_search_locations = cls._paths(fullname)
|
||||||
|
return spec
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def find_module(cls, _fullname) -> None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
if not any(finder == _EditableFinder for finder in sys.meta_path):
|
||||||
|
sys.meta_path.append(_EditableFinder)
|
||||||
|
|
||||||
|
if not NAMESPACES:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not any(hook == _EditableNamespaceFinder._path_hook for hook in sys.path_hooks):
|
||||||
|
# PathEntryFinder is needed to create NamespaceSpec without private APIS
|
||||||
|
sys.path_hooks.append(_EditableNamespaceFinder._path_hook)
|
||||||
|
if PATH_PLACEHOLDER not in sys.path:
|
||||||
|
sys.path.append(PATH_PLACEHOLDER) # Used just to trigger the path hook
|
||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
import sys
|
||||||
|
from importlib.machinery import ModuleSpec, PathFinder
|
||||||
|
from importlib.machinery import all_suffixes as module_suffixes
|
||||||
|
from importlib.util import spec_from_file_location
|
||||||
|
from itertools import chain
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
MAPPING: dict[str, str] = {'inference': '/Users/r3ap3r/Projects/AuroraMusic/packages/inference'}
|
||||||
|
NAMESPACES: dict[str, list[str]] = {}
|
||||||
|
PATH_PLACEHOLDER = '__editable__.aurora_inference-0.1.0.finder' + ".__path_hook__"
|
||||||
|
|
||||||
|
|
||||||
|
class _EditableFinder: # MetaPathFinder
|
||||||
|
@classmethod
|
||||||
|
def find_spec(cls, fullname: str, path=None, target=None) -> ModuleSpec | None: # type: ignore
|
||||||
|
# Top-level packages and modules (we know these exist in the FS)
|
||||||
|
if fullname in MAPPING:
|
||||||
|
pkg_path = MAPPING[fullname]
|
||||||
|
return cls._find_spec(fullname, Path(pkg_path))
|
||||||
|
|
||||||
|
# Handle immediate children modules (required for namespaces to work)
|
||||||
|
# To avoid problems with case sensitivity in the file system we delegate
|
||||||
|
# to the importlib.machinery implementation.
|
||||||
|
parent, _, child = fullname.rpartition(".")
|
||||||
|
if parent and parent in MAPPING:
|
||||||
|
return PathFinder.find_spec(fullname, path=[MAPPING[parent]])
|
||||||
|
|
||||||
|
# Other levels of nesting should be handled automatically by importlib
|
||||||
|
# using the parent path.
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _find_spec(cls, fullname: str, candidate_path: Path) -> ModuleSpec | None:
|
||||||
|
init = candidate_path / "__init__.py"
|
||||||
|
candidates = (candidate_path.with_suffix(x) for x in module_suffixes())
|
||||||
|
for candidate in chain([init], candidates):
|
||||||
|
if candidate.exists():
|
||||||
|
return spec_from_file_location(fullname, candidate)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
class _EditableNamespaceFinder: # PathEntryFinder
|
||||||
|
@classmethod
|
||||||
|
def _path_hook(cls, path) -> type[_EditableNamespaceFinder]:
|
||||||
|
if path == PATH_PLACEHOLDER:
|
||||||
|
return cls
|
||||||
|
raise ImportError
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _paths(cls, fullname: str) -> list[str]:
|
||||||
|
paths = NAMESPACES[fullname]
|
||||||
|
if not paths and fullname in MAPPING:
|
||||||
|
paths = [MAPPING[fullname]]
|
||||||
|
# Always add placeholder, for 2 reasons:
|
||||||
|
# 1. __path__ cannot be empty for the spec to be considered namespace.
|
||||||
|
# 2. In the case of nested namespaces, we need to force
|
||||||
|
# import machinery to query _EditableNamespaceFinder again.
|
||||||
|
return [*paths, PATH_PLACEHOLDER]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def find_spec(cls, fullname: str, target=None) -> ModuleSpec | None: # type: ignore
|
||||||
|
if fullname in NAMESPACES:
|
||||||
|
spec = ModuleSpec(fullname, None, is_package=True)
|
||||||
|
spec.submodule_search_locations = cls._paths(fullname)
|
||||||
|
return spec
|
||||||
|
return None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def find_module(cls, _fullname) -> None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def install():
|
||||||
|
if not any(finder == _EditableFinder for finder in sys.meta_path):
|
||||||
|
sys.meta_path.append(_EditableFinder)
|
||||||
|
|
||||||
|
if not NAMESPACES:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not any(hook == _EditableNamespaceFinder._path_hook for hook in sys.path_hooks):
|
||||||
|
# PathEntryFinder is needed to create NamespaceSpec without private APIS
|
||||||
|
sys.path_hooks.append(_EditableNamespaceFinder._path_hook)
|
||||||
|
if PATH_PLACEHOLDER not in sys.path:
|
||||||
|
sys.path.append(PATH_PLACEHOLDER) # Used just to trigger the path hook
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,33 @@
|
|||||||
|
# This is a stub package designed to roughly emulate the _yaml
|
||||||
|
# extension module, which previously existed as a standalone module
|
||||||
|
# and has been moved into the `yaml` package namespace.
|
||||||
|
# It does not perfectly mimic its old counterpart, but should get
|
||||||
|
# close enough for anyone who's relying on it even when they shouldn't.
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
# in some circumstances, the yaml module we imoprted may be from a different version, so we need
|
||||||
|
# to tread carefully when poking at it here (it may not have the attributes we expect)
|
||||||
|
if not getattr(yaml, '__with_libyaml__', False):
|
||||||
|
from sys import version_info
|
||||||
|
|
||||||
|
exc = ModuleNotFoundError if version_info >= (3, 6) else ImportError
|
||||||
|
raise exc("No module named '_yaml'")
|
||||||
|
else:
|
||||||
|
from yaml._yaml import *
|
||||||
|
import warnings
|
||||||
|
warnings.warn(
|
||||||
|
'The _yaml extension module is now located at yaml._yaml'
|
||||||
|
' and its location is subject to change. To use the'
|
||||||
|
' LibYAML-based parser and emitter, import from `yaml`:'
|
||||||
|
' `from yaml import CLoader as Loader, CDumper as Dumper`.',
|
||||||
|
DeprecationWarning
|
||||||
|
)
|
||||||
|
del warnings
|
||||||
|
# Don't `del yaml` here because yaml is actually an existing
|
||||||
|
# namespace member of _yaml.
|
||||||
|
|
||||||
|
__name__ = '_yaml'
|
||||||
|
# If the module is top-level (i.e. not a part of any specific package)
|
||||||
|
# then the attribute should be set to ''.
|
||||||
|
# https://docs.python.org/3.8/library/types.html
|
||||||
|
__package__ = ''
|
||||||
BIN
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
pip
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
Copyright 2009-2024 Michael Bayer.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,142 @@
|
|||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: alembic
|
||||||
|
Version: 1.13.2
|
||||||
|
Summary: A database migration tool for SQLAlchemy.
|
||||||
|
Home-page: https://alembic.sqlalchemy.org
|
||||||
|
Author: Mike Bayer
|
||||||
|
Author-email: [email protected]
|
||||||
|
License: MIT
|
||||||
|
Project-URL: Documentation, https://alembic.sqlalchemy.org/en/latest/
|
||||||
|
Project-URL: Changelog, https://alembic.sqlalchemy.org/en/latest/changelog.html
|
||||||
|
Project-URL: Source, https://github.com/sqlalchemy/alembic/
|
||||||
|
Project-URL: Issue Tracker, https://github.com/sqlalchemy/alembic/issues/
|
||||||
|
Classifier: Development Status :: 5 - Production/Stable
|
||||||
|
Classifier: Intended Audience :: Developers
|
||||||
|
Classifier: Environment :: Console
|
||||||
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
|
Classifier: Operating System :: OS Independent
|
||||||
|
Classifier: Programming Language :: Python
|
||||||
|
Classifier: Programming Language :: Python :: 3
|
||||||
|
Classifier: Programming Language :: Python :: 3.8
|
||||||
|
Classifier: Programming Language :: Python :: 3.9
|
||||||
|
Classifier: Programming Language :: Python :: 3.10
|
||||||
|
Classifier: Programming Language :: Python :: 3.11
|
||||||
|
Classifier: Programming Language :: Python :: 3.12
|
||||||
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
||||||
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
||||||
|
Classifier: Topic :: Database :: Front-Ends
|
||||||
|
Requires-Python: >=3.8
|
||||||
|
Description-Content-Type: text/x-rst
|
||||||
|
License-File: LICENSE
|
||||||
|
Requires-Dist: SQLAlchemy >=1.3.0
|
||||||
|
Requires-Dist: Mako
|
||||||
|
Requires-Dist: typing-extensions >=4
|
||||||
|
Requires-Dist: importlib-metadata ; python_version < "3.9"
|
||||||
|
Requires-Dist: importlib-resources ; python_version < "3.9"
|
||||||
|
Provides-Extra: tz
|
||||||
|
Requires-Dist: backports.zoneinfo ; (python_version < "3.9") and extra == 'tz'
|
||||||
|
|
||||||
|
Alembic is a database migrations tool written by the author
|
||||||
|
of `SQLAlchemy <http://www.sqlalchemy.org>`_. A migrations tool
|
||||||
|
offers the following functionality:
|
||||||
|
|
||||||
|
* Can emit ALTER statements to a database in order to change
|
||||||
|
the structure of tables and other constructs
|
||||||
|
* Provides a system whereby "migration scripts" may be constructed;
|
||||||
|
each script indicates a particular series of steps that can "upgrade" a
|
||||||
|
target database to a new version, and optionally a series of steps that can
|
||||||
|
"downgrade" similarly, doing the same steps in reverse.
|
||||||
|
* Allows the scripts to execute in some sequential manner.
|
||||||
|
|
||||||
|
The goals of Alembic are:
|
||||||
|
|
||||||
|
* Very open ended and transparent configuration and operation. A new
|
||||||
|
Alembic environment is generated from a set of templates which is selected
|
||||||
|
among a set of options when setup first occurs. The templates then deposit a
|
||||||
|
series of scripts that define fully how database connectivity is established
|
||||||
|
and how migration scripts are invoked; the migration scripts themselves are
|
||||||
|
generated from a template within that series of scripts. The scripts can
|
||||||
|
then be further customized to define exactly how databases will be
|
||||||
|
interacted with and what structure new migration files should take.
|
||||||
|
* Full support for transactional DDL. The default scripts ensure that all
|
||||||
|
migrations occur within a transaction - for those databases which support
|
||||||
|
this (Postgresql, Microsoft SQL Server), migrations can be tested with no
|
||||||
|
need to manually undo changes upon failure.
|
||||||
|
* Minimalist script construction. Basic operations like renaming
|
||||||
|
tables/columns, adding/removing columns, changing column attributes can be
|
||||||
|
performed through one line commands like alter_column(), rename_table(),
|
||||||
|
add_constraint(). There is no need to recreate full SQLAlchemy Table
|
||||||
|
structures for simple operations like these - the functions themselves
|
||||||
|
generate minimalist schema structures behind the scenes to achieve the given
|
||||||
|
DDL sequence.
|
||||||
|
* "auto generation" of migrations. While real world migrations are far more
|
||||||
|
complex than what can be automatically determined, Alembic can still
|
||||||
|
eliminate the initial grunt work in generating new migration directives
|
||||||
|
from an altered schema. The ``--autogenerate`` feature will inspect the
|
||||||
|
current status of a database using SQLAlchemy's schema inspection
|
||||||
|
capabilities, compare it to the current state of the database model as
|
||||||
|
specified in Python, and generate a series of "candidate" migrations,
|
||||||
|
rendering them into a new migration script as Python directives. The
|
||||||
|
developer then edits the new file, adding additional directives and data
|
||||||
|
migrations as needed, to produce a finished migration. Table and column
|
||||||
|
level changes can be detected, with constraints and indexes to follow as
|
||||||
|
well.
|
||||||
|
* Full support for migrations generated as SQL scripts. Those of us who
|
||||||
|
work in corporate environments know that direct access to DDL commands on a
|
||||||
|
production database is a rare privilege, and DBAs want textual SQL scripts.
|
||||||
|
Alembic's usage model and commands are oriented towards being able to run a
|
||||||
|
series of migrations into a textual output file as easily as it runs them
|
||||||
|
directly to a database. Care must be taken in this mode to not invoke other
|
||||||
|
operations that rely upon in-memory SELECTs of rows - Alembic tries to
|
||||||
|
provide helper constructs like bulk_insert() to help with data-oriented
|
||||||
|
operations that are compatible with script-based DDL.
|
||||||
|
* Non-linear, dependency-graph versioning. Scripts are given UUID
|
||||||
|
identifiers similarly to a DVCS, and the linkage of one script to the next
|
||||||
|
is achieved via human-editable markers within the scripts themselves.
|
||||||
|
The structure of a set of migration files is considered as a
|
||||||
|
directed-acyclic graph, meaning any migration file can be dependent
|
||||||
|
on any other arbitrary set of migration files, or none at
|
||||||
|
all. Through this open-ended system, migration files can be organized
|
||||||
|
into branches, multiple roots, and mergepoints, without restriction.
|
||||||
|
Commands are provided to produce new branches, roots, and merges of
|
||||||
|
branches automatically.
|
||||||
|
* Provide a library of ALTER constructs that can be used by any SQLAlchemy
|
||||||
|
application. The DDL constructs build upon SQLAlchemy's own DDLElement base
|
||||||
|
and can be used standalone by any application or script.
|
||||||
|
* At long last, bring SQLite and its inability to ALTER things into the fold,
|
||||||
|
but in such a way that SQLite's very special workflow needs are accommodated
|
||||||
|
in an explicit way that makes the most of a bad situation, through the
|
||||||
|
concept of a "batch" migration, where multiple changes to a table can
|
||||||
|
be batched together to form a series of instructions for a single, subsequent
|
||||||
|
"move-and-copy" workflow. You can even use "move-and-copy" workflow for
|
||||||
|
other databases, if you want to recreate a table in the background
|
||||||
|
on a busy system.
|
||||||
|
|
||||||
|
Documentation and status of Alembic is at https://alembic.sqlalchemy.org/
|
||||||
|
|
||||||
|
The SQLAlchemy Project
|
||||||
|
======================
|
||||||
|
|
||||||
|
Alembic is part of the `SQLAlchemy Project <https://www.sqlalchemy.org>`_ and
|
||||||
|
adheres to the same standards and conventions as the core project.
|
||||||
|
|
||||||
|
Development / Bug reporting / Pull requests
|
||||||
|
___________________________________________
|
||||||
|
|
||||||
|
Please refer to the
|
||||||
|
`SQLAlchemy Community Guide <https://www.sqlalchemy.org/develop.html>`_ for
|
||||||
|
guidelines on coding and participating in this project.
|
||||||
|
|
||||||
|
Code of Conduct
|
||||||
|
_______________
|
||||||
|
|
||||||
|
Above all, SQLAlchemy places great emphasis on polite, thoughtful, and
|
||||||
|
constructive communication between users and developers.
|
||||||
|
Please see our current Code of Conduct at
|
||||||
|
`Code of Conduct <https://www.sqlalchemy.org/codeofconduct.html>`_.
|
||||||
|
|
||||||
|
License
|
||||||
|
=======
|
||||||
|
|
||||||
|
Alembic is distributed under the `MIT license
|
||||||
|
<https://opensource.org/licenses/MIT>`_.
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
../../../bin/alembic,sha256=ApD6jrhsvOPGk--BQR5qXCUEmQC_UhcWLI99MBYseRg,209
|
||||||
|
alembic-1.13.2.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
||||||
|
alembic-1.13.2.dist-info/LICENSE,sha256=zhnnuit3ylhLgqZ5KFbhOOswsxHIlrB2wJpAXuRfvuk,1059
|
||||||
|
alembic-1.13.2.dist-info/METADATA,sha256=MiPeqh7s3_-Fw3qSLli6kj69bv82oARVZhLA5ToJ5rk,7390
|
||||||
|
alembic-1.13.2.dist-info/RECORD,,
|
||||||
|
alembic-1.13.2.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
alembic-1.13.2.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
||||||
|
alembic-1.13.2.dist-info/entry_points.txt,sha256=aykM30soxwGN0pB7etLc1q0cHJbL9dy46RnK9VX4LLw,48
|
||||||
|
alembic-1.13.2.dist-info/top_level.txt,sha256=FwKWd5VsPFC8iQjpu1u9Cn-JnK3-V1RhUCmWqz1cl-s,8
|
||||||
|
alembic/__init__.py,sha256=Cgo-xQ2JolKXx84viUN_535WHtufvauqLNTDnW4vMmc,63
|
||||||
|
alembic/__main__.py,sha256=373m7-TBh72JqrSMYviGrxCHZo-cnweM8AGF8A22PmY,78
|
||||||
|
alembic/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/__main__.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/command.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/config.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/context.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/environment.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/migration.cpython-312.pyc,,
|
||||||
|
alembic/__pycache__/op.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/__init__.py,sha256=ntmUTXhjLm4_zmqIwyVaECdpPDn6_u1yM9vYk6-553E,543
|
||||||
|
alembic/autogenerate/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/__pycache__/api.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/__pycache__/compare.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/__pycache__/render.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/__pycache__/rewriter.cpython-312.pyc,,
|
||||||
|
alembic/autogenerate/api.py,sha256=Bh-37G0PSFeT9WSfEQ-3TZoainXGLL2nsl4okv_xYc0,22173
|
||||||
|
alembic/autogenerate/compare.py,sha256=cdUBH6qsedaJsnToSOu4MfcJaI4bjUJ4VWqtBlqsSr8,44944
|
||||||
|
alembic/autogenerate/render.py,sha256=Sx4aQy1OafI0eii_uEtO9venaI8GOOBj1p-TMhTWNNw,35099
|
||||||
|
alembic/autogenerate/rewriter.py,sha256=uZWRkTYJoncoEJ5WY1QBRiozjyChqZDJPy4LtcRibjM,7846
|
||||||
|
alembic/command.py,sha256=2tkKrIoEgPfXrGgvMRGrUXH4l-7z466DOxd7Q2XOfL8,22169
|
||||||
|
alembic/config.py,sha256=BZ7mwFRk2gq8GFNxxy9qvMUFx43YbDbQTC99OnjqiKY,22216
|
||||||
|
alembic/context.py,sha256=hK1AJOQXJ29Bhn276GYcosxeG7pC5aZRT5E8c4bMJ4Q,195
|
||||||
|
alembic/context.pyi,sha256=hUHbSnbSeEEMVkk0gDSXOq4_9edSjYzsjmmf-mL9Iao,31737
|
||||||
|
alembic/ddl/__init__.py,sha256=Df8fy4Vn_abP8B7q3x8gyFwEwnLw6hs2Ljt_bV3EZWE,152
|
||||||
|
alembic/ddl/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/_autogen.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/base.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/impl.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/mssql.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/mysql.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/oracle.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/postgresql.cpython-312.pyc,,
|
||||||
|
alembic/ddl/__pycache__/sqlite.cpython-312.pyc,,
|
||||||
|
alembic/ddl/_autogen.py,sha256=Blv2RrHNyF4cE6znCQXNXG5T9aO-YmiwD4Fz-qfoaWA,9275
|
||||||
|
alembic/ddl/base.py,sha256=fzGvWyvpSluIOKDQ7Ajc-i_jlDpH4j-JZFOOPxxYS-s,9986
|
||||||
|
alembic/ddl/impl.py,sha256=R4oIVxl4OllYBU6BuQRH-4MhUAU4Qfu_M3lBkYb5pv4,29033
|
||||||
|
alembic/ddl/mssql.py,sha256=ydvgBSaftKYjaBaMyqius66Ta4CICQSj79Og3Ed2atY,14219
|
||||||
|
alembic/ddl/mysql.py,sha256=kXOGYmpnL_9WL3ijXNsG4aAwy3m1HWJOoLZSePzmJF0,17316
|
||||||
|
alembic/ddl/oracle.py,sha256=669YlkcZihlXFbnXhH2krdrvDry8q5pcUGfoqkg_R6Y,6243
|
||||||
|
alembic/ddl/postgresql.py,sha256=GNCnx-N8UsCIstfW49J8ivYcKgRB8KFNPRgNtORC_AM,29883
|
||||||
|
alembic/ddl/sqlite.py,sha256=wLXhb8bJWRspKQTb-iVfepR4LXYgOuEbUWKX5qwDhIQ,7570
|
||||||
|
alembic/environment.py,sha256=MM5lPayGT04H3aeng1H7GQ8HEAs3VGX5yy6mDLCPLT4,43
|
||||||
|
alembic/migration.py,sha256=MV6Fju6rZtn2fTREKzXrCZM6aIBGII4OMZFix0X-GLs,41
|
||||||
|
alembic/op.py,sha256=flHtcsVqOD-ZgZKK2pv-CJ5Cwh-KJ7puMUNXzishxLw,167
|
||||||
|
alembic/op.pyi,sha256=8R6SJr1dQharU0blmMJJj23XFO_hk9ZmAQBJBQOeXRU,49816
|
||||||
|
alembic/operations/__init__.py,sha256=e0KQSZAgLpTWvyvreB7DWg7RJV_MWSOPVDgCqsd2FzY,318
|
||||||
|
alembic/operations/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/operations/__pycache__/base.cpython-312.pyc,,
|
||||||
|
alembic/operations/__pycache__/batch.cpython-312.pyc,,
|
||||||
|
alembic/operations/__pycache__/ops.cpython-312.pyc,,
|
||||||
|
alembic/operations/__pycache__/schemaobj.cpython-312.pyc,,
|
||||||
|
alembic/operations/__pycache__/toimpl.cpython-312.pyc,,
|
||||||
|
alembic/operations/base.py,sha256=ExTfmPvL1XPu8GGftmJfRavbj47A8rJwO13nfM1Vb9c,74000
|
||||||
|
alembic/operations/batch.py,sha256=YqtD4hJ3_RkFxvI7zbmBwxcLEyLHYyWQpsz4l5L85yI,26943
|
||||||
|
alembic/operations/ops.py,sha256=MUXsztT8LngGbv3wL06OSQuoty-FcI9uJWLwTmlm_GQ,94381
|
||||||
|
alembic/operations/schemaobj.py,sha256=Wp-bBe4a8lXPTvIHJttBY0ejtpVR5Jvtb2kI-U2PztQ,9468
|
||||||
|
alembic/operations/toimpl.py,sha256=SoNY2_gZX2baXTD-pNjpCWnON8D2QBSYQBIjo13-WKA,7115
|
||||||
|
alembic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
alembic/runtime/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
alembic/runtime/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/runtime/__pycache__/environment.cpython-312.pyc,,
|
||||||
|
alembic/runtime/__pycache__/migration.cpython-312.pyc,,
|
||||||
|
alembic/runtime/environment.py,sha256=SkYB_am1h3FSG8IsExAQxGP_7WwzOVigqjlO747Aokc,41497
|
||||||
|
alembic/runtime/migration.py,sha256=sku7-2_TralZQnNeoDaEFlydTStL-SJechbr9K8AHJs,50093
|
||||||
|
alembic/script/__init__.py,sha256=lSj06O391Iy5avWAiq8SPs6N8RBgxkSPjP8wpXcNDGg,100
|
||||||
|
alembic/script/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/script/__pycache__/base.cpython-312.pyc,,
|
||||||
|
alembic/script/__pycache__/revision.cpython-312.pyc,,
|
||||||
|
alembic/script/__pycache__/write_hooks.cpython-312.pyc,,
|
||||||
|
alembic/script/base.py,sha256=XPydgsjabSI2sxmGEX-Ij_2mbtB1jC7aM66z7Ni3ZsI,37689
|
||||||
|
alembic/script/revision.py,sha256=NTu-eu5Y78u4NoVXpT0alpD2oL40SGATA2sEMEf1el4,62306
|
||||||
|
alembic/script/write_hooks.py,sha256=NGB6NGgfdf7HK6XNNpSKqUCfzxazj-NRUePgFx7MJSM,5036
|
||||||
|
alembic/templates/async/README,sha256=ISVtAOvqvKk_5ThM5ioJE-lMkvf9IbknFUFVU_vPma4,58
|
||||||
|
alembic/templates/async/__pycache__/env.cpython-312.pyc,,
|
||||||
|
alembic/templates/async/alembic.ini.mako,sha256=mtG-32u1WzE9pQCGRy4Pw_G2hPmnrGO0sVC7wRtk9G0,3597
|
||||||
|
alembic/templates/async/env.py,sha256=zbOCf3Y7w2lg92hxSwmG1MM_7y56i_oRH4AKp0pQBYo,2389
|
||||||
|
alembic/templates/async/script.py.mako,sha256=MEqL-2qATlST9TAOeYgscMn1uy6HUS9NFvDgl93dMj8,635
|
||||||
|
alembic/templates/generic/README,sha256=MVlc9TYmr57RbhXET6QxgyCcwWP7w-vLkEsirENqiIQ,38
|
||||||
|
alembic/templates/generic/__pycache__/env.cpython-312.pyc,,
|
||||||
|
alembic/templates/generic/alembic.ini.mako,sha256=fJLaRCOrnd_qRHdfMMrZA5iqzBxdtIpxKCo4jdLx6KA,3705
|
||||||
|
alembic/templates/generic/env.py,sha256=TLRWOVW3Xpt_Tpf8JFzlnoPn_qoUu8UV77Y4o9XD6yI,2103
|
||||||
|
alembic/templates/generic/script.py.mako,sha256=MEqL-2qATlST9TAOeYgscMn1uy6HUS9NFvDgl93dMj8,635
|
||||||
|
alembic/templates/multidb/README,sha256=dWLDhnBgphA4Nzb7sNlMfCS3_06YqVbHhz-9O5JNqyI,606
|
||||||
|
alembic/templates/multidb/__pycache__/env.cpython-312.pyc,,
|
||||||
|
alembic/templates/multidb/alembic.ini.mako,sha256=57TVeVTk4jjuAT42AyTHFqgr7gEssMGFKARzE2yEtIU,3799
|
||||||
|
alembic/templates/multidb/env.py,sha256=6zNjnW8mXGUk7erTsAvrfhvqoczJ-gagjVq1Ypg2YIQ,4230
|
||||||
|
alembic/templates/multidb/script.py.mako,sha256=N06nMtNSwHkgl0EBXDyMt8njp9tlOesR583gfq21nbY,1090
|
||||||
|
alembic/testing/__init__.py,sha256=kOxOh5nwmui9d-_CCq9WA4Udwy7ITjm453w74CTLZDo,1159
|
||||||
|
alembic/testing/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/assertions.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/env.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/fixtures.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/requirements.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/schemacompare.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/util.cpython-312.pyc,,
|
||||||
|
alembic/testing/__pycache__/warnings.cpython-312.pyc,,
|
||||||
|
alembic/testing/assertions.py,sha256=1CbJk8c8-WO9eJ0XJ0jJvMsNRLUrXV41NOeIJUAlOBk,5015
|
||||||
|
alembic/testing/env.py,sha256=zJacVb_z6uLs2U1TtkmnFH9P3_F-3IfYbVv4UEPOvfo,10754
|
||||||
|
alembic/testing/fixtures.py,sha256=nBntOynOmVCFc7IYiN3DIQ3TBNTfiGCvL_1-FyCry8o,9462
|
||||||
|
alembic/testing/plugin/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
||||||
|
alembic/testing/plugin/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/testing/plugin/__pycache__/bootstrap.cpython-312.pyc,,
|
||||||
|
alembic/testing/plugin/bootstrap.py,sha256=9C6wtjGrIVztZ928w27hsQE0KcjDLIUtUN3dvZKsMVk,50
|
||||||
|
alembic/testing/requirements.py,sha256=dKeAO1l5TwBqXarJN-IPORlCqCJv-41Dj6oXoEikxHQ,5133
|
||||||
|
alembic/testing/schemacompare.py,sha256=N5UqSNCOJetIKC4vKhpYzQEpj08XkdgIoqBmEPQ3tlc,4838
|
||||||
|
alembic/testing/suite/__init__.py,sha256=MvE7-hwbaVN1q3NM-ztGxORU9dnIelUCINKqNxewn7Y,288
|
||||||
|
alembic/testing/suite/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/_autogen_fixtures.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_autogen_comments.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_autogen_computed.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_autogen_diffs.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_autogen_fks.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_autogen_identity.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_environment.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/__pycache__/test_op.cpython-312.pyc,,
|
||||||
|
alembic/testing/suite/_autogen_fixtures.py,sha256=cDq1pmzHe15S6dZPGNC6sqFaCQ3hLT_oPV2IDigUGQ0,9880
|
||||||
|
alembic/testing/suite/test_autogen_comments.py,sha256=aEGqKUDw4kHjnDk298aoGcQvXJWmZXcIX_2FxH4cJK8,6283
|
||||||
|
alembic/testing/suite/test_autogen_computed.py,sha256=CXAeF-5Wr2cmW8PB7ztHG_4ZQsn1gSWrHWfxi72grNU,6147
|
||||||
|
alembic/testing/suite/test_autogen_diffs.py,sha256=T4SR1n_kmcOKYhR4W1-dA0e5sddJ69DSVL2HW96kAkE,8394
|
||||||
|
alembic/testing/suite/test_autogen_fks.py,sha256=AqFmb26Buex167HYa9dZWOk8x-JlB1OK3bwcvvjDFaU,32927
|
||||||
|
alembic/testing/suite/test_autogen_identity.py,sha256=kcuqngG7qXAKPJDX4U8sRzPKHEJECHuZ0DtuaS6tVkk,5824
|
||||||
|
alembic/testing/suite/test_environment.py,sha256=OwD-kpESdLoc4byBrGrXbZHvqtPbzhFCG4W9hJOJXPQ,11877
|
||||||
|
alembic/testing/suite/test_op.py,sha256=2XQCdm_NmnPxHGuGj7hmxMzIhKxXNotUsKdACXzE1mM,1343
|
||||||
|
alembic/testing/util.py,sha256=CQrcQDA8fs_7ME85z5ydb-Bt70soIIID-qNY1vbR2dg,3350
|
||||||
|
alembic/testing/warnings.py,sha256=RxA7x_8GseANgw07Us8JN_1iGbANxaw6_VitX2ZGQH4,1078
|
||||||
|
alembic/util/__init__.py,sha256=KSZ7UT2YzH6CietgUtljVoE3QnGjoFKOi7RL5sgUxrk,1688
|
||||||
|
alembic/util/__pycache__/__init__.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/compat.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/editor.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/exc.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/langhelpers.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/messaging.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/pyfiles.cpython-312.pyc,,
|
||||||
|
alembic/util/__pycache__/sqla_compat.cpython-312.pyc,,
|
||||||
|
alembic/util/compat.py,sha256=RjHdQa1NomU3Zlvgfvza0OMiSRQSLRL3xVl3OdUy2UE,2594
|
||||||
|
alembic/util/editor.py,sha256=JIz6_BdgV8_oKtnheR6DZoB7qnrHrlRgWjx09AsTsUw,2546
|
||||||
|
alembic/util/exc.py,sha256=KQTru4zcgAmN4IxLMwLFS56XToUewaXB7oOLcPNjPwg,98
|
||||||
|
alembic/util/langhelpers.py,sha256=LpOcovnhMnP45kTt8zNJ4BHpyQrlF40OL6yDXjqKtsE,10026
|
||||||
|
alembic/util/messaging.py,sha256=BxAHiJsYHBPb2m8zv4yaueSRAlVuYXWkRCeN02JXhqw,3250
|
||||||
|
alembic/util/pyfiles.py,sha256=zltVdcwEJJCPS2gHsQvkHkQakuF6wXiZ6zfwHbGNT0g,3489
|
||||||
|
alembic/util/sqla_compat.py,sha256=cg1kUQcatV8whwiYIP_IVVktQe7RkAzQ4aekHTWTITo,19520
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
Wheel-Version: 1.0
|
||||||
|
Generator: bdist_wheel (0.43.0)
|
||||||
|
Root-Is-Purelib: true
|
||||||
|
Tag: py3-none-any
|
||||||
|
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
[console_scripts]
|
||||||
|
alembic = alembic.config:main
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
alembic
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from . import context
|
||||||
|
from . import op
|
||||||
|
|
||||||
|
__version__ = "1.13.2"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
from .config import main
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(prog="alembic")
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,10 @@
|
|||||||
|
from .api import _render_migration_diffs as _render_migration_diffs
|
||||||
|
from .api import compare_metadata as compare_metadata
|
||||||
|
from .api import produce_migrations as produce_migrations
|
||||||
|
from .api import render_python_code as render_python_code
|
||||||
|
from .api import RevisionContext as RevisionContext
|
||||||
|
from .compare import _produce_net_changes as _produce_net_changes
|
||||||
|
from .compare import comparators as comparators
|
||||||
|
from .render import render_op_text as render_op_text
|
||||||
|
from .render import renderers as renderers
|
||||||
|
from .rewriter import Rewriter as Rewriter
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,650 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import contextlib
|
||||||
|
from typing import Any
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Iterator
|
||||||
|
from typing import List
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import Set
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy import inspect
|
||||||
|
|
||||||
|
from . import compare
|
||||||
|
from . import render
|
||||||
|
from .. import util
|
||||||
|
from ..operations import ops
|
||||||
|
from ..util import sqla_compat
|
||||||
|
|
||||||
|
"""Provide the 'autogenerate' feature which can produce migration operations
|
||||||
|
automatically."""
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from sqlalchemy.engine import Connection
|
||||||
|
from sqlalchemy.engine import Dialect
|
||||||
|
from sqlalchemy.engine import Inspector
|
||||||
|
from sqlalchemy.sql.schema import MetaData
|
||||||
|
from sqlalchemy.sql.schema import SchemaItem
|
||||||
|
from sqlalchemy.sql.schema import Table
|
||||||
|
|
||||||
|
from ..config import Config
|
||||||
|
from ..operations.ops import DowngradeOps
|
||||||
|
from ..operations.ops import MigrationScript
|
||||||
|
from ..operations.ops import UpgradeOps
|
||||||
|
from ..runtime.environment import NameFilterParentNames
|
||||||
|
from ..runtime.environment import NameFilterType
|
||||||
|
from ..runtime.environment import ProcessRevisionDirectiveFn
|
||||||
|
from ..runtime.environment import RenderItemFn
|
||||||
|
from ..runtime.migration import MigrationContext
|
||||||
|
from ..script.base import Script
|
||||||
|
from ..script.base import ScriptDirectory
|
||||||
|
from ..script.revision import _GetRevArg
|
||||||
|
|
||||||
|
|
||||||
|
def compare_metadata(context: MigrationContext, metadata: MetaData) -> Any:
|
||||||
|
"""Compare a database schema to that given in a
|
||||||
|
:class:`~sqlalchemy.schema.MetaData` instance.
|
||||||
|
|
||||||
|
The database connection is presented in the context
|
||||||
|
of a :class:`.MigrationContext` object, which
|
||||||
|
provides database connectivity as well as optional
|
||||||
|
comparison functions to use for datatypes and
|
||||||
|
server defaults - see the "autogenerate" arguments
|
||||||
|
at :meth:`.EnvironmentContext.configure`
|
||||||
|
for details on these.
|
||||||
|
|
||||||
|
The return format is a list of "diff" directives,
|
||||||
|
each representing individual differences::
|
||||||
|
|
||||||
|
from alembic.migration import MigrationContext
|
||||||
|
from alembic.autogenerate import compare_metadata
|
||||||
|
from sqlalchemy import (
|
||||||
|
create_engine,
|
||||||
|
MetaData,
|
||||||
|
Column,
|
||||||
|
Integer,
|
||||||
|
String,
|
||||||
|
Table,
|
||||||
|
text,
|
||||||
|
)
|
||||||
|
import pprint
|
||||||
|
|
||||||
|
engine = create_engine("sqlite://")
|
||||||
|
|
||||||
|
with engine.begin() as conn:
|
||||||
|
conn.execute(
|
||||||
|
text(
|
||||||
|
'''
|
||||||
|
create table foo (
|
||||||
|
id integer not null primary key,
|
||||||
|
old_data varchar,
|
||||||
|
x integer
|
||||||
|
)
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
)
|
||||||
|
conn.execute(text("create table bar (data varchar)"))
|
||||||
|
|
||||||
|
metadata = MetaData()
|
||||||
|
Table(
|
||||||
|
"foo",
|
||||||
|
metadata,
|
||||||
|
Column("id", Integer, primary_key=True),
|
||||||
|
Column("data", Integer),
|
||||||
|
Column("x", Integer, nullable=False),
|
||||||
|
)
|
||||||
|
Table("bat", metadata, Column("info", String))
|
||||||
|
|
||||||
|
mc = MigrationContext.configure(engine.connect())
|
||||||
|
|
||||||
|
diff = compare_metadata(mc, metadata)
|
||||||
|
pprint.pprint(diff, indent=2, width=20)
|
||||||
|
|
||||||
|
Output::
|
||||||
|
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"add_table",
|
||||||
|
Table(
|
||||||
|
"bat",
|
||||||
|
MetaData(),
|
||||||
|
Column("info", String(), table=<bat>),
|
||||||
|
schema=None,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"remove_table",
|
||||||
|
Table(
|
||||||
|
"bar",
|
||||||
|
MetaData(),
|
||||||
|
Column("data", VARCHAR(), table=<bar>),
|
||||||
|
schema=None,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"add_column",
|
||||||
|
None,
|
||||||
|
"foo",
|
||||||
|
Column("data", Integer(), table=<foo>),
|
||||||
|
),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"modify_nullable",
|
||||||
|
None,
|
||||||
|
"foo",
|
||||||
|
"x",
|
||||||
|
{
|
||||||
|
"existing_comment": None,
|
||||||
|
"existing_server_default": False,
|
||||||
|
"existing_type": INTEGER(),
|
||||||
|
},
|
||||||
|
True,
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
],
|
||||||
|
(
|
||||||
|
"remove_column",
|
||||||
|
None,
|
||||||
|
"foo",
|
||||||
|
Column("old_data", VARCHAR(), table=<foo>),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
:param context: a :class:`.MigrationContext`
|
||||||
|
instance.
|
||||||
|
:param metadata: a :class:`~sqlalchemy.schema.MetaData`
|
||||||
|
instance.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:func:`.produce_migrations` - produces a :class:`.MigrationScript`
|
||||||
|
structure based on metadata comparison.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
migration_script = produce_migrations(context, metadata)
|
||||||
|
assert migration_script.upgrade_ops is not None
|
||||||
|
return migration_script.upgrade_ops.as_diffs()
|
||||||
|
|
||||||
|
|
||||||
|
def produce_migrations(
|
||||||
|
context: MigrationContext, metadata: MetaData
|
||||||
|
) -> MigrationScript:
|
||||||
|
"""Produce a :class:`.MigrationScript` structure based on schema
|
||||||
|
comparison.
|
||||||
|
|
||||||
|
This function does essentially what :func:`.compare_metadata` does,
|
||||||
|
but then runs the resulting list of diffs to produce the full
|
||||||
|
:class:`.MigrationScript` object. For an example of what this looks like,
|
||||||
|
see the example in :ref:`customizing_revision`.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:func:`.compare_metadata` - returns more fundamental "diff"
|
||||||
|
data from comparing a schema.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
autogen_context = AutogenContext(context, metadata=metadata)
|
||||||
|
|
||||||
|
migration_script = ops.MigrationScript(
|
||||||
|
rev_id=None,
|
||||||
|
upgrade_ops=ops.UpgradeOps([]),
|
||||||
|
downgrade_ops=ops.DowngradeOps([]),
|
||||||
|
)
|
||||||
|
|
||||||
|
compare._populate_migration_script(autogen_context, migration_script)
|
||||||
|
|
||||||
|
return migration_script
|
||||||
|
|
||||||
|
|
||||||
|
def render_python_code(
|
||||||
|
up_or_down_op: Union[UpgradeOps, DowngradeOps],
|
||||||
|
sqlalchemy_module_prefix: str = "sa.",
|
||||||
|
alembic_module_prefix: str = "op.",
|
||||||
|
render_as_batch: bool = False,
|
||||||
|
imports: Sequence[str] = (),
|
||||||
|
render_item: Optional[RenderItemFn] = None,
|
||||||
|
migration_context: Optional[MigrationContext] = None,
|
||||||
|
user_module_prefix: Optional[str] = None,
|
||||||
|
) -> str:
|
||||||
|
"""Render Python code given an :class:`.UpgradeOps` or
|
||||||
|
:class:`.DowngradeOps` object.
|
||||||
|
|
||||||
|
This is a convenience function that can be used to test the
|
||||||
|
autogenerate output of a user-defined :class:`.MigrationScript` structure.
|
||||||
|
|
||||||
|
:param up_or_down_op: :class:`.UpgradeOps` or :class:`.DowngradeOps` object
|
||||||
|
:param sqlalchemy_module_prefix: module prefix for SQLAlchemy objects
|
||||||
|
:param alembic_module_prefix: module prefix for Alembic constructs
|
||||||
|
:param render_as_batch: use "batch operations" style for rendering
|
||||||
|
:param imports: sequence of import symbols to add
|
||||||
|
:param render_item: callable to render items
|
||||||
|
:param migration_context: optional :class:`.MigrationContext`
|
||||||
|
:param user_module_prefix: optional string prefix for user-defined types
|
||||||
|
|
||||||
|
.. versionadded:: 1.11.0
|
||||||
|
|
||||||
|
"""
|
||||||
|
opts = {
|
||||||
|
"sqlalchemy_module_prefix": sqlalchemy_module_prefix,
|
||||||
|
"alembic_module_prefix": alembic_module_prefix,
|
||||||
|
"render_item": render_item,
|
||||||
|
"render_as_batch": render_as_batch,
|
||||||
|
"user_module_prefix": user_module_prefix,
|
||||||
|
}
|
||||||
|
|
||||||
|
if migration_context is None:
|
||||||
|
from ..runtime.migration import MigrationContext
|
||||||
|
from sqlalchemy.engine.default import DefaultDialect
|
||||||
|
|
||||||
|
migration_context = MigrationContext.configure(
|
||||||
|
dialect=DefaultDialect()
|
||||||
|
)
|
||||||
|
|
||||||
|
autogen_context = AutogenContext(migration_context, opts=opts)
|
||||||
|
autogen_context.imports = set(imports)
|
||||||
|
return render._indent(
|
||||||
|
render._render_cmd_body(up_or_down_op, autogen_context)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _render_migration_diffs(
|
||||||
|
context: MigrationContext, template_args: Dict[Any, Any]
|
||||||
|
) -> None:
|
||||||
|
"""legacy, used by test_autogen_composition at the moment"""
|
||||||
|
|
||||||
|
autogen_context = AutogenContext(context)
|
||||||
|
|
||||||
|
upgrade_ops = ops.UpgradeOps([])
|
||||||
|
compare._produce_net_changes(autogen_context, upgrade_ops)
|
||||||
|
|
||||||
|
migration_script = ops.MigrationScript(
|
||||||
|
rev_id=None,
|
||||||
|
upgrade_ops=upgrade_ops,
|
||||||
|
downgrade_ops=upgrade_ops.reverse(),
|
||||||
|
)
|
||||||
|
|
||||||
|
render._render_python_into_templatevars(
|
||||||
|
autogen_context, migration_script, template_args
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class AutogenContext:
|
||||||
|
"""Maintains configuration and state that's specific to an
|
||||||
|
autogenerate operation."""
|
||||||
|
|
||||||
|
metadata: Optional[MetaData] = None
|
||||||
|
"""The :class:`~sqlalchemy.schema.MetaData` object
|
||||||
|
representing the destination.
|
||||||
|
|
||||||
|
This object is the one that is passed within ``env.py``
|
||||||
|
to the :paramref:`.EnvironmentContext.configure.target_metadata`
|
||||||
|
parameter. It represents the structure of :class:`.Table` and other
|
||||||
|
objects as stated in the current database model, and represents the
|
||||||
|
destination structure for the database being examined.
|
||||||
|
|
||||||
|
While the :class:`~sqlalchemy.schema.MetaData` object is primarily
|
||||||
|
known as a collection of :class:`~sqlalchemy.schema.Table` objects,
|
||||||
|
it also has an :attr:`~sqlalchemy.schema.MetaData.info` dictionary
|
||||||
|
that may be used by end-user schemes to store additional schema-level
|
||||||
|
objects that are to be compared in custom autogeneration schemes.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
connection: Optional[Connection] = None
|
||||||
|
"""The :class:`~sqlalchemy.engine.base.Connection` object currently
|
||||||
|
connected to the database backend being compared.
|
||||||
|
|
||||||
|
This is obtained from the :attr:`.MigrationContext.bind` and is
|
||||||
|
ultimately set up in the ``env.py`` script.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
dialect: Optional[Dialect] = None
|
||||||
|
"""The :class:`~sqlalchemy.engine.Dialect` object currently in use.
|
||||||
|
|
||||||
|
This is normally obtained from the
|
||||||
|
:attr:`~sqlalchemy.engine.base.Connection.dialect` attribute.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
imports: Set[str] = None # type: ignore[assignment]
|
||||||
|
"""A ``set()`` which contains string Python import directives.
|
||||||
|
|
||||||
|
The directives are to be rendered into the ``${imports}`` section
|
||||||
|
of a script template. The set is normally empty and can be modified
|
||||||
|
within hooks such as the
|
||||||
|
:paramref:`.EnvironmentContext.configure.render_item` hook.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogen_render_types`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
migration_context: MigrationContext = None # type: ignore[assignment]
|
||||||
|
"""The :class:`.MigrationContext` established by the ``env.py`` script."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
migration_context: MigrationContext,
|
||||||
|
metadata: Optional[MetaData] = None,
|
||||||
|
opts: Optional[Dict[str, Any]] = None,
|
||||||
|
autogenerate: bool = True,
|
||||||
|
) -> None:
|
||||||
|
if (
|
||||||
|
autogenerate
|
||||||
|
and migration_context is not None
|
||||||
|
and migration_context.as_sql
|
||||||
|
):
|
||||||
|
raise util.CommandError(
|
||||||
|
"autogenerate can't use as_sql=True as it prevents querying "
|
||||||
|
"the database for schema information"
|
||||||
|
)
|
||||||
|
|
||||||
|
if opts is None:
|
||||||
|
opts = migration_context.opts
|
||||||
|
|
||||||
|
self.metadata = metadata = (
|
||||||
|
opts.get("target_metadata", None) if metadata is None else metadata
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
autogenerate
|
||||||
|
and metadata is None
|
||||||
|
and migration_context is not None
|
||||||
|
and migration_context.script is not None
|
||||||
|
):
|
||||||
|
raise util.CommandError(
|
||||||
|
"Can't proceed with --autogenerate option; environment "
|
||||||
|
"script %s does not provide "
|
||||||
|
"a MetaData object or sequence of objects to the context."
|
||||||
|
% (migration_context.script.env_py_location)
|
||||||
|
)
|
||||||
|
|
||||||
|
include_object = opts.get("include_object", None)
|
||||||
|
include_name = opts.get("include_name", None)
|
||||||
|
|
||||||
|
object_filters = []
|
||||||
|
name_filters = []
|
||||||
|
if include_object:
|
||||||
|
object_filters.append(include_object)
|
||||||
|
if include_name:
|
||||||
|
name_filters.append(include_name)
|
||||||
|
|
||||||
|
self._object_filters = object_filters
|
||||||
|
self._name_filters = name_filters
|
||||||
|
|
||||||
|
self.migration_context = migration_context
|
||||||
|
if self.migration_context is not None:
|
||||||
|
self.connection = self.migration_context.bind
|
||||||
|
self.dialect = self.migration_context.dialect
|
||||||
|
|
||||||
|
self.imports = set()
|
||||||
|
self.opts: Dict[str, Any] = opts
|
||||||
|
self._has_batch: bool = False
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def inspector(self) -> Inspector:
|
||||||
|
if self.connection is None:
|
||||||
|
raise TypeError(
|
||||||
|
"can't return inspector as this "
|
||||||
|
"AutogenContext has no database connection"
|
||||||
|
)
|
||||||
|
return inspect(self.connection)
|
||||||
|
|
||||||
|
@contextlib.contextmanager
|
||||||
|
def _within_batch(self) -> Iterator[None]:
|
||||||
|
self._has_batch = True
|
||||||
|
yield
|
||||||
|
self._has_batch = False
|
||||||
|
|
||||||
|
def run_name_filters(
|
||||||
|
self,
|
||||||
|
name: Optional[str],
|
||||||
|
type_: NameFilterType,
|
||||||
|
parent_names: NameFilterParentNames,
|
||||||
|
) -> bool:
|
||||||
|
"""Run the context's name filters and return True if the targets
|
||||||
|
should be part of the autogenerate operation.
|
||||||
|
|
||||||
|
This method should be run for every kind of name encountered within the
|
||||||
|
reflection side of an autogenerate operation, giving the environment
|
||||||
|
the chance to filter what names should be reflected as database
|
||||||
|
objects. The filters here are produced directly via the
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_name` parameter.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if "schema_name" in parent_names:
|
||||||
|
if type_ == "table":
|
||||||
|
table_name = name
|
||||||
|
else:
|
||||||
|
table_name = parent_names.get("table_name", None)
|
||||||
|
if table_name:
|
||||||
|
schema_name = parent_names["schema_name"]
|
||||||
|
if schema_name:
|
||||||
|
parent_names["schema_qualified_table_name"] = "%s.%s" % (
|
||||||
|
schema_name,
|
||||||
|
table_name,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
parent_names["schema_qualified_table_name"] = table_name
|
||||||
|
|
||||||
|
for fn in self._name_filters:
|
||||||
|
if not fn(name, type_, parent_names):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def run_object_filters(
|
||||||
|
self,
|
||||||
|
object_: SchemaItem,
|
||||||
|
name: sqla_compat._ConstraintName,
|
||||||
|
type_: NameFilterType,
|
||||||
|
reflected: bool,
|
||||||
|
compare_to: Optional[SchemaItem],
|
||||||
|
) -> bool:
|
||||||
|
"""Run the context's object filters and return True if the targets
|
||||||
|
should be part of the autogenerate operation.
|
||||||
|
|
||||||
|
This method should be run for every kind of object encountered within
|
||||||
|
an autogenerate operation, giving the environment the chance
|
||||||
|
to filter what objects should be included in the comparison.
|
||||||
|
The filters here are produced directly via the
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_object` parameter.
|
||||||
|
|
||||||
|
"""
|
||||||
|
for fn in self._object_filters:
|
||||||
|
if not fn(object_, name, type_, reflected, compare_to):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
run_filters = run_object_filters
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def sorted_tables(self) -> List[Table]:
|
||||||
|
"""Return an aggregate of the :attr:`.MetaData.sorted_tables`
|
||||||
|
collection(s).
|
||||||
|
|
||||||
|
For a sequence of :class:`.MetaData` objects, this
|
||||||
|
concatenates the :attr:`.MetaData.sorted_tables` collection
|
||||||
|
for each individual :class:`.MetaData` in the order of the
|
||||||
|
sequence. It does **not** collate the sorted tables collections.
|
||||||
|
|
||||||
|
"""
|
||||||
|
result = []
|
||||||
|
for m in util.to_list(self.metadata):
|
||||||
|
result.extend(m.sorted_tables)
|
||||||
|
return result
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def table_key_to_table(self) -> Dict[str, Table]:
|
||||||
|
"""Return an aggregate of the :attr:`.MetaData.tables` dictionaries.
|
||||||
|
|
||||||
|
The :attr:`.MetaData.tables` collection is a dictionary of table key
|
||||||
|
to :class:`.Table`; this method aggregates the dictionary across
|
||||||
|
multiple :class:`.MetaData` objects into one dictionary.
|
||||||
|
|
||||||
|
Duplicate table keys are **not** supported; if two :class:`.MetaData`
|
||||||
|
objects contain the same table key, an exception is raised.
|
||||||
|
|
||||||
|
"""
|
||||||
|
result: Dict[str, Table] = {}
|
||||||
|
for m in util.to_list(self.metadata):
|
||||||
|
intersect = set(result).intersection(set(m.tables))
|
||||||
|
if intersect:
|
||||||
|
raise ValueError(
|
||||||
|
"Duplicate table keys across multiple "
|
||||||
|
"MetaData objects: %s"
|
||||||
|
% (", ".join('"%s"' % key for key in sorted(intersect)))
|
||||||
|
)
|
||||||
|
|
||||||
|
result.update(m.tables)
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
class RevisionContext:
|
||||||
|
"""Maintains configuration and state that's specific to a revision
|
||||||
|
file generation operation."""
|
||||||
|
|
||||||
|
generated_revisions: List[MigrationScript]
|
||||||
|
process_revision_directives: Optional[ProcessRevisionDirectiveFn]
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
config: Config,
|
||||||
|
script_directory: ScriptDirectory,
|
||||||
|
command_args: Dict[str, Any],
|
||||||
|
process_revision_directives: Optional[
|
||||||
|
ProcessRevisionDirectiveFn
|
||||||
|
] = None,
|
||||||
|
) -> None:
|
||||||
|
self.config = config
|
||||||
|
self.script_directory = script_directory
|
||||||
|
self.command_args = command_args
|
||||||
|
self.process_revision_directives = process_revision_directives
|
||||||
|
self.template_args = {
|
||||||
|
"config": config # Let templates use config for
|
||||||
|
# e.g. multiple databases
|
||||||
|
}
|
||||||
|
self.generated_revisions = [self._default_revision()]
|
||||||
|
|
||||||
|
def _to_script(
|
||||||
|
self, migration_script: MigrationScript
|
||||||
|
) -> Optional[Script]:
|
||||||
|
template_args: Dict[str, Any] = self.template_args.copy()
|
||||||
|
|
||||||
|
if getattr(migration_script, "_needs_render", False):
|
||||||
|
autogen_context = self._last_autogen_context
|
||||||
|
|
||||||
|
# clear out existing imports if we are doing multiple
|
||||||
|
# renders
|
||||||
|
autogen_context.imports = set()
|
||||||
|
if migration_script.imports:
|
||||||
|
autogen_context.imports.update(migration_script.imports)
|
||||||
|
render._render_python_into_templatevars(
|
||||||
|
autogen_context, migration_script, template_args
|
||||||
|
)
|
||||||
|
|
||||||
|
assert migration_script.rev_id is not None
|
||||||
|
return self.script_directory.generate_revision(
|
||||||
|
migration_script.rev_id,
|
||||||
|
migration_script.message,
|
||||||
|
refresh=True,
|
||||||
|
head=migration_script.head,
|
||||||
|
splice=migration_script.splice,
|
||||||
|
branch_labels=migration_script.branch_label,
|
||||||
|
version_path=migration_script.version_path,
|
||||||
|
depends_on=migration_script.depends_on,
|
||||||
|
**template_args,
|
||||||
|
)
|
||||||
|
|
||||||
|
def run_autogenerate(
|
||||||
|
self, rev: _GetRevArg, migration_context: MigrationContext
|
||||||
|
) -> None:
|
||||||
|
self._run_environment(rev, migration_context, True)
|
||||||
|
|
||||||
|
def run_no_autogenerate(
|
||||||
|
self, rev: _GetRevArg, migration_context: MigrationContext
|
||||||
|
) -> None:
|
||||||
|
self._run_environment(rev, migration_context, False)
|
||||||
|
|
||||||
|
def _run_environment(
|
||||||
|
self,
|
||||||
|
rev: _GetRevArg,
|
||||||
|
migration_context: MigrationContext,
|
||||||
|
autogenerate: bool,
|
||||||
|
) -> None:
|
||||||
|
if autogenerate:
|
||||||
|
if self.command_args["sql"]:
|
||||||
|
raise util.CommandError(
|
||||||
|
"Using --sql with --autogenerate does not make any sense"
|
||||||
|
)
|
||||||
|
if set(self.script_directory.get_revisions(rev)) != set(
|
||||||
|
self.script_directory.get_revisions("heads")
|
||||||
|
):
|
||||||
|
raise util.CommandError("Target database is not up to date.")
|
||||||
|
|
||||||
|
upgrade_token = migration_context.opts["upgrade_token"]
|
||||||
|
downgrade_token = migration_context.opts["downgrade_token"]
|
||||||
|
|
||||||
|
migration_script = self.generated_revisions[-1]
|
||||||
|
if not getattr(migration_script, "_needs_render", False):
|
||||||
|
migration_script.upgrade_ops_list[-1].upgrade_token = upgrade_token
|
||||||
|
migration_script.downgrade_ops_list[-1].downgrade_token = (
|
||||||
|
downgrade_token
|
||||||
|
)
|
||||||
|
migration_script._needs_render = True
|
||||||
|
else:
|
||||||
|
migration_script._upgrade_ops.append(
|
||||||
|
ops.UpgradeOps([], upgrade_token=upgrade_token)
|
||||||
|
)
|
||||||
|
migration_script._downgrade_ops.append(
|
||||||
|
ops.DowngradeOps([], downgrade_token=downgrade_token)
|
||||||
|
)
|
||||||
|
|
||||||
|
autogen_context = AutogenContext(
|
||||||
|
migration_context, autogenerate=autogenerate
|
||||||
|
)
|
||||||
|
self._last_autogen_context: AutogenContext = autogen_context
|
||||||
|
|
||||||
|
if autogenerate:
|
||||||
|
compare._populate_migration_script(
|
||||||
|
autogen_context, migration_script
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.process_revision_directives:
|
||||||
|
self.process_revision_directives(
|
||||||
|
migration_context, rev, self.generated_revisions
|
||||||
|
)
|
||||||
|
|
||||||
|
hook = migration_context.opts["process_revision_directives"]
|
||||||
|
if hook:
|
||||||
|
hook(migration_context, rev, self.generated_revisions)
|
||||||
|
|
||||||
|
for migration_script in self.generated_revisions:
|
||||||
|
migration_script._needs_render = True
|
||||||
|
|
||||||
|
def _default_revision(self) -> MigrationScript:
|
||||||
|
command_args: Dict[str, Any] = self.command_args
|
||||||
|
op = ops.MigrationScript(
|
||||||
|
rev_id=command_args["rev_id"] or util.rev_id(),
|
||||||
|
message=command_args["message"],
|
||||||
|
upgrade_ops=ops.UpgradeOps([]),
|
||||||
|
downgrade_ops=ops.DowngradeOps([]),
|
||||||
|
head=command_args["head"],
|
||||||
|
splice=command_args["splice"],
|
||||||
|
branch_label=command_args["branch_label"],
|
||||||
|
version_path=command_args["version_path"],
|
||||||
|
depends_on=command_args["depends_on"],
|
||||||
|
)
|
||||||
|
return op
|
||||||
|
|
||||||
|
def generate_scripts(self) -> Iterator[Optional[Script]]:
|
||||||
|
for generated_revision in self.generated_revisions:
|
||||||
|
yield self._to_script(generated_revision)
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,240 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Iterator
|
||||||
|
from typing import List
|
||||||
|
from typing import Tuple
|
||||||
|
from typing import Type
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from .. import util
|
||||||
|
from ..operations import ops
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from ..operations.ops import AddColumnOp
|
||||||
|
from ..operations.ops import AlterColumnOp
|
||||||
|
from ..operations.ops import CreateTableOp
|
||||||
|
from ..operations.ops import DowngradeOps
|
||||||
|
from ..operations.ops import MigrateOperation
|
||||||
|
from ..operations.ops import MigrationScript
|
||||||
|
from ..operations.ops import ModifyTableOps
|
||||||
|
from ..operations.ops import OpContainer
|
||||||
|
from ..operations.ops import UpgradeOps
|
||||||
|
from ..runtime.migration import MigrationContext
|
||||||
|
from ..script.revision import _GetRevArg
|
||||||
|
|
||||||
|
ProcessRevisionDirectiveFn = Callable[
|
||||||
|
["MigrationContext", "_GetRevArg", List["MigrationScript"]], None
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Rewriter:
|
||||||
|
"""A helper object that allows easy 'rewriting' of ops streams.
|
||||||
|
|
||||||
|
The :class:`.Rewriter` object is intended to be passed along
|
||||||
|
to the
|
||||||
|
:paramref:`.EnvironmentContext.configure.process_revision_directives`
|
||||||
|
parameter in an ``env.py`` script. Once constructed, any number
|
||||||
|
of "rewrites" functions can be associated with it, which will be given
|
||||||
|
the opportunity to modify the structure without having to have explicit
|
||||||
|
knowledge of the overall structure.
|
||||||
|
|
||||||
|
The function is passed the :class:`.MigrationContext` object and
|
||||||
|
``revision`` tuple that are passed to the :paramref:`.Environment
|
||||||
|
Context.configure.process_revision_directives` function normally,
|
||||||
|
and the third argument is an individual directive of the type
|
||||||
|
noted in the decorator. The function has the choice of returning
|
||||||
|
a single op directive, which normally can be the directive that
|
||||||
|
was actually passed, or a new directive to replace it, or a list
|
||||||
|
of zero or more directives to replace it.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogen_rewriter` - usage example
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
_traverse = util.Dispatcher()
|
||||||
|
|
||||||
|
_chained: Tuple[Union[ProcessRevisionDirectiveFn, Rewriter], ...] = ()
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.dispatch = util.Dispatcher()
|
||||||
|
|
||||||
|
def chain(
|
||||||
|
self,
|
||||||
|
other: Union[
|
||||||
|
ProcessRevisionDirectiveFn,
|
||||||
|
Rewriter,
|
||||||
|
],
|
||||||
|
) -> Rewriter:
|
||||||
|
"""Produce a "chain" of this :class:`.Rewriter` to another.
|
||||||
|
|
||||||
|
This allows two or more rewriters to operate serially on a stream,
|
||||||
|
e.g.::
|
||||||
|
|
||||||
|
writer1 = autogenerate.Rewriter()
|
||||||
|
writer2 = autogenerate.Rewriter()
|
||||||
|
|
||||||
|
|
||||||
|
@writer1.rewrites(ops.AddColumnOp)
|
||||||
|
def add_column_nullable(context, revision, op):
|
||||||
|
op.column.nullable = True
|
||||||
|
return op
|
||||||
|
|
||||||
|
|
||||||
|
@writer2.rewrites(ops.AddColumnOp)
|
||||||
|
def add_column_idx(context, revision, op):
|
||||||
|
idx_op = ops.CreateIndexOp(
|
||||||
|
"ixc", op.table_name, [op.column.name]
|
||||||
|
)
|
||||||
|
return [op, idx_op]
|
||||||
|
|
||||||
|
writer = writer1.chain(writer2)
|
||||||
|
|
||||||
|
:param other: a :class:`.Rewriter` instance
|
||||||
|
:return: a new :class:`.Rewriter` that will run the operations
|
||||||
|
of this writer, then the "other" writer, in succession.
|
||||||
|
|
||||||
|
"""
|
||||||
|
wr = self.__class__.__new__(self.__class__)
|
||||||
|
wr.__dict__.update(self.__dict__)
|
||||||
|
wr._chained += (other,)
|
||||||
|
return wr
|
||||||
|
|
||||||
|
def rewrites(
|
||||||
|
self,
|
||||||
|
operator: Union[
|
||||||
|
Type[AddColumnOp],
|
||||||
|
Type[MigrateOperation],
|
||||||
|
Type[AlterColumnOp],
|
||||||
|
Type[CreateTableOp],
|
||||||
|
Type[ModifyTableOps],
|
||||||
|
],
|
||||||
|
) -> Callable[..., Any]:
|
||||||
|
"""Register a function as rewriter for a given type.
|
||||||
|
|
||||||
|
The function should receive three arguments, which are
|
||||||
|
the :class:`.MigrationContext`, a ``revision`` tuple, and
|
||||||
|
an op directive of the type indicated. E.g.::
|
||||||
|
|
||||||
|
@writer1.rewrites(ops.AddColumnOp)
|
||||||
|
def add_column_nullable(context, revision, op):
|
||||||
|
op.column.nullable = True
|
||||||
|
return op
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.dispatch.dispatch_for(operator)
|
||||||
|
|
||||||
|
def _rewrite(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directive: MigrateOperation,
|
||||||
|
) -> Iterator[MigrateOperation]:
|
||||||
|
try:
|
||||||
|
_rewriter = self.dispatch.dispatch(directive)
|
||||||
|
except ValueError:
|
||||||
|
_rewriter = None
|
||||||
|
yield directive
|
||||||
|
else:
|
||||||
|
if self in directive._mutations:
|
||||||
|
yield directive
|
||||||
|
else:
|
||||||
|
for r_directive in util.to_list(
|
||||||
|
_rewriter(context, revision, directive), []
|
||||||
|
):
|
||||||
|
r_directive._mutations = r_directive._mutations.union(
|
||||||
|
[self]
|
||||||
|
)
|
||||||
|
yield r_directive
|
||||||
|
|
||||||
|
def __call__(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directives: List[MigrationScript],
|
||||||
|
) -> None:
|
||||||
|
self.process_revision_directives(context, revision, directives)
|
||||||
|
for process_revision_directives in self._chained:
|
||||||
|
process_revision_directives(context, revision, directives)
|
||||||
|
|
||||||
|
@_traverse.dispatch_for(ops.MigrationScript)
|
||||||
|
def _traverse_script(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directive: MigrationScript,
|
||||||
|
) -> None:
|
||||||
|
upgrade_ops_list: List[UpgradeOps] = []
|
||||||
|
for upgrade_ops in directive.upgrade_ops_list:
|
||||||
|
ret = self._traverse_for(context, revision, upgrade_ops)
|
||||||
|
if len(ret) != 1:
|
||||||
|
raise ValueError(
|
||||||
|
"Can only return single object for UpgradeOps traverse"
|
||||||
|
)
|
||||||
|
upgrade_ops_list.append(ret[0])
|
||||||
|
|
||||||
|
directive.upgrade_ops = upgrade_ops_list # type: ignore
|
||||||
|
|
||||||
|
downgrade_ops_list: List[DowngradeOps] = []
|
||||||
|
for downgrade_ops in directive.downgrade_ops_list:
|
||||||
|
ret = self._traverse_for(context, revision, downgrade_ops)
|
||||||
|
if len(ret) != 1:
|
||||||
|
raise ValueError(
|
||||||
|
"Can only return single object for DowngradeOps traverse"
|
||||||
|
)
|
||||||
|
downgrade_ops_list.append(ret[0])
|
||||||
|
directive.downgrade_ops = downgrade_ops_list # type: ignore
|
||||||
|
|
||||||
|
@_traverse.dispatch_for(ops.OpContainer)
|
||||||
|
def _traverse_op_container(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directive: OpContainer,
|
||||||
|
) -> None:
|
||||||
|
self._traverse_list(context, revision, directive.ops)
|
||||||
|
|
||||||
|
@_traverse.dispatch_for(ops.MigrateOperation)
|
||||||
|
def _traverse_any_directive(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directive: MigrateOperation,
|
||||||
|
) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _traverse_for(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directive: MigrateOperation,
|
||||||
|
) -> Any:
|
||||||
|
directives = list(self._rewrite(context, revision, directive))
|
||||||
|
for directive in directives:
|
||||||
|
traverser = self._traverse.dispatch(directive)
|
||||||
|
traverser(self, context, revision, directive)
|
||||||
|
return directives
|
||||||
|
|
||||||
|
def _traverse_list(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directives: Any,
|
||||||
|
) -> None:
|
||||||
|
dest = []
|
||||||
|
for directive in directives:
|
||||||
|
dest.extend(self._traverse_for(context, revision, directive))
|
||||||
|
|
||||||
|
directives[:] = dest
|
||||||
|
|
||||||
|
def process_revision_directives(
|
||||||
|
self,
|
||||||
|
context: MigrationContext,
|
||||||
|
revision: _GetRevArg,
|
||||||
|
directives: List[MigrationScript],
|
||||||
|
) -> None:
|
||||||
|
self._traverse_list(context, revision, directives)
|
||||||
@@ -0,0 +1,758 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-untyped-calls
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from typing import List
|
||||||
|
from typing import Optional
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from . import autogenerate as autogen
|
||||||
|
from . import util
|
||||||
|
from .runtime.environment import EnvironmentContext
|
||||||
|
from .script import ScriptDirectory
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from alembic.config import Config
|
||||||
|
from alembic.script.base import Script
|
||||||
|
from alembic.script.revision import _RevIdType
|
||||||
|
from .runtime.environment import ProcessRevisionDirectiveFn
|
||||||
|
|
||||||
|
|
||||||
|
def list_templates(config: Config) -> None:
|
||||||
|
"""List available templates.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` object.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
config.print_stdout("Available templates:\n")
|
||||||
|
for tempname in os.listdir(config.get_template_directory()):
|
||||||
|
with open(
|
||||||
|
os.path.join(config.get_template_directory(), tempname, "README")
|
||||||
|
) as readme:
|
||||||
|
synopsis = next(readme).rstrip()
|
||||||
|
config.print_stdout("%s - %s", tempname, synopsis)
|
||||||
|
|
||||||
|
config.print_stdout("\nTemplates are used via the 'init' command, e.g.:")
|
||||||
|
config.print_stdout("\n alembic init --template generic ./scripts")
|
||||||
|
|
||||||
|
|
||||||
|
def init(
|
||||||
|
config: Config,
|
||||||
|
directory: str,
|
||||||
|
template: str = "generic",
|
||||||
|
package: bool = False,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize a new scripts directory.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` object.
|
||||||
|
|
||||||
|
:param directory: string path of the target directory.
|
||||||
|
|
||||||
|
:param template: string name of the migration environment template to
|
||||||
|
use.
|
||||||
|
|
||||||
|
:param package: when True, write ``__init__.py`` files into the
|
||||||
|
environment location as well as the versions/ location.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if os.access(directory, os.F_OK) and os.listdir(directory):
|
||||||
|
raise util.CommandError(
|
||||||
|
"Directory %s already exists and is not empty" % directory
|
||||||
|
)
|
||||||
|
|
||||||
|
template_dir = os.path.join(config.get_template_directory(), template)
|
||||||
|
if not os.access(template_dir, os.F_OK):
|
||||||
|
raise util.CommandError("No such template %r" % template)
|
||||||
|
|
||||||
|
if not os.access(directory, os.F_OK):
|
||||||
|
with util.status(
|
||||||
|
f"Creating directory {os.path.abspath(directory)!r}",
|
||||||
|
**config.messaging_opts,
|
||||||
|
):
|
||||||
|
os.makedirs(directory)
|
||||||
|
|
||||||
|
versions = os.path.join(directory, "versions")
|
||||||
|
with util.status(
|
||||||
|
f"Creating directory {os.path.abspath(versions)!r}",
|
||||||
|
**config.messaging_opts,
|
||||||
|
):
|
||||||
|
os.makedirs(versions)
|
||||||
|
|
||||||
|
script = ScriptDirectory(directory)
|
||||||
|
|
||||||
|
config_file: str | None = None
|
||||||
|
for file_ in os.listdir(template_dir):
|
||||||
|
file_path = os.path.join(template_dir, file_)
|
||||||
|
if file_ == "alembic.ini.mako":
|
||||||
|
assert config.config_file_name is not None
|
||||||
|
config_file = os.path.abspath(config.config_file_name)
|
||||||
|
if os.access(config_file, os.F_OK):
|
||||||
|
util.msg(
|
||||||
|
f"File {config_file!r} already exists, skipping",
|
||||||
|
**config.messaging_opts,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
script._generate_template(
|
||||||
|
file_path, config_file, script_location=directory
|
||||||
|
)
|
||||||
|
elif os.path.isfile(file_path):
|
||||||
|
output_file = os.path.join(directory, file_)
|
||||||
|
script._copy_file(file_path, output_file)
|
||||||
|
|
||||||
|
if package:
|
||||||
|
for path in [
|
||||||
|
os.path.join(os.path.abspath(directory), "__init__.py"),
|
||||||
|
os.path.join(os.path.abspath(versions), "__init__.py"),
|
||||||
|
]:
|
||||||
|
with util.status(f"Adding {path!r}", **config.messaging_opts):
|
||||||
|
with open(path, "w"):
|
||||||
|
pass
|
||||||
|
|
||||||
|
assert config_file is not None
|
||||||
|
util.msg(
|
||||||
|
"Please edit configuration/connection/logging "
|
||||||
|
f"settings in {config_file!r} before proceeding.",
|
||||||
|
**config.messaging_opts,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def revision(
|
||||||
|
config: Config,
|
||||||
|
message: Optional[str] = None,
|
||||||
|
autogenerate: bool = False,
|
||||||
|
sql: bool = False,
|
||||||
|
head: str = "head",
|
||||||
|
splice: bool = False,
|
||||||
|
branch_label: Optional[_RevIdType] = None,
|
||||||
|
version_path: Optional[str] = None,
|
||||||
|
rev_id: Optional[str] = None,
|
||||||
|
depends_on: Optional[str] = None,
|
||||||
|
process_revision_directives: Optional[ProcessRevisionDirectiveFn] = None,
|
||||||
|
) -> Union[Optional[Script], List[Optional[Script]]]:
|
||||||
|
"""Create a new revision file.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` object.
|
||||||
|
|
||||||
|
:param message: string message to apply to the revision; this is the
|
||||||
|
``-m`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param autogenerate: whether or not to autogenerate the script from
|
||||||
|
the database; this is the ``--autogenerate`` option to
|
||||||
|
``alembic revision``.
|
||||||
|
|
||||||
|
:param sql: whether to dump the script out as a SQL string; when specified,
|
||||||
|
the script is dumped to stdout. This is the ``--sql`` option to
|
||||||
|
``alembic revision``.
|
||||||
|
|
||||||
|
:param head: head revision to build the new revision upon as a parent;
|
||||||
|
this is the ``--head`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param splice: whether or not the new revision should be made into a
|
||||||
|
new head of its own; is required when the given ``head`` is not itself
|
||||||
|
a head. This is the ``--splice`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param branch_label: string label to apply to the branch; this is the
|
||||||
|
``--branch-label`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param version_path: string symbol identifying a specific version path
|
||||||
|
from the configuration; this is the ``--version-path`` option to
|
||||||
|
``alembic revision``.
|
||||||
|
|
||||||
|
:param rev_id: optional revision identifier to use instead of having
|
||||||
|
one generated; this is the ``--rev-id`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param depends_on: optional list of "depends on" identifiers; this is the
|
||||||
|
``--depends-on`` option to ``alembic revision``.
|
||||||
|
|
||||||
|
:param process_revision_directives: this is a callable that takes the
|
||||||
|
same form as the callable described at
|
||||||
|
:paramref:`.EnvironmentContext.configure.process_revision_directives`;
|
||||||
|
will be applied to the structure generated by the revision process
|
||||||
|
where it can be altered programmatically. Note that unlike all
|
||||||
|
the other parameters, this option is only available via programmatic
|
||||||
|
use of :func:`.command.revision`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script_directory = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
command_args = dict(
|
||||||
|
message=message,
|
||||||
|
autogenerate=autogenerate,
|
||||||
|
sql=sql,
|
||||||
|
head=head,
|
||||||
|
splice=splice,
|
||||||
|
branch_label=branch_label,
|
||||||
|
version_path=version_path,
|
||||||
|
rev_id=rev_id,
|
||||||
|
depends_on=depends_on,
|
||||||
|
)
|
||||||
|
revision_context = autogen.RevisionContext(
|
||||||
|
config,
|
||||||
|
script_directory,
|
||||||
|
command_args,
|
||||||
|
process_revision_directives=process_revision_directives,
|
||||||
|
)
|
||||||
|
|
||||||
|
environment = util.asbool(config.get_main_option("revision_environment"))
|
||||||
|
|
||||||
|
if autogenerate:
|
||||||
|
environment = True
|
||||||
|
|
||||||
|
if sql:
|
||||||
|
raise util.CommandError(
|
||||||
|
"Using --sql with --autogenerate does not make any sense"
|
||||||
|
)
|
||||||
|
|
||||||
|
def retrieve_migrations(rev, context):
|
||||||
|
revision_context.run_autogenerate(rev, context)
|
||||||
|
return []
|
||||||
|
|
||||||
|
elif environment:
|
||||||
|
|
||||||
|
def retrieve_migrations(rev, context):
|
||||||
|
revision_context.run_no_autogenerate(rev, context)
|
||||||
|
return []
|
||||||
|
|
||||||
|
elif sql:
|
||||||
|
raise util.CommandError(
|
||||||
|
"Using --sql with the revision command when "
|
||||||
|
"revision_environment is not configured does not make any sense"
|
||||||
|
)
|
||||||
|
|
||||||
|
if environment:
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script_directory,
|
||||||
|
fn=retrieve_migrations,
|
||||||
|
as_sql=sql,
|
||||||
|
template_args=revision_context.template_args,
|
||||||
|
revision_context=revision_context,
|
||||||
|
):
|
||||||
|
script_directory.run_env()
|
||||||
|
|
||||||
|
# the revision_context now has MigrationScript structure(s) present.
|
||||||
|
# these could theoretically be further processed / rewritten *here*,
|
||||||
|
# in addition to the hooks present within each run_migrations() call,
|
||||||
|
# or at the end of env.py run_migrations_online().
|
||||||
|
|
||||||
|
scripts = [script for script in revision_context.generate_scripts()]
|
||||||
|
if len(scripts) == 1:
|
||||||
|
return scripts[0]
|
||||||
|
else:
|
||||||
|
return scripts
|
||||||
|
|
||||||
|
|
||||||
|
def check(config: "Config") -> None:
|
||||||
|
"""Check if revision command with autogenerate has pending upgrade ops.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` object.
|
||||||
|
|
||||||
|
.. versionadded:: 1.9.0
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script_directory = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
command_args = dict(
|
||||||
|
message=None,
|
||||||
|
autogenerate=True,
|
||||||
|
sql=False,
|
||||||
|
head="head",
|
||||||
|
splice=False,
|
||||||
|
branch_label=None,
|
||||||
|
version_path=None,
|
||||||
|
rev_id=None,
|
||||||
|
depends_on=None,
|
||||||
|
)
|
||||||
|
revision_context = autogen.RevisionContext(
|
||||||
|
config,
|
||||||
|
script_directory,
|
||||||
|
command_args,
|
||||||
|
)
|
||||||
|
|
||||||
|
def retrieve_migrations(rev, context):
|
||||||
|
revision_context.run_autogenerate(rev, context)
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script_directory,
|
||||||
|
fn=retrieve_migrations,
|
||||||
|
as_sql=False,
|
||||||
|
template_args=revision_context.template_args,
|
||||||
|
revision_context=revision_context,
|
||||||
|
):
|
||||||
|
script_directory.run_env()
|
||||||
|
|
||||||
|
# the revision_context now has MigrationScript structure(s) present.
|
||||||
|
|
||||||
|
migration_script = revision_context.generated_revisions[-1]
|
||||||
|
diffs = []
|
||||||
|
for upgrade_ops in migration_script.upgrade_ops_list:
|
||||||
|
diffs.extend(upgrade_ops.as_diffs())
|
||||||
|
|
||||||
|
if diffs:
|
||||||
|
raise util.AutogenerateDiffsDetected(
|
||||||
|
f"New upgrade operations detected: {diffs}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
config.print_stdout("No new upgrade operations detected.")
|
||||||
|
|
||||||
|
|
||||||
|
def merge(
|
||||||
|
config: Config,
|
||||||
|
revisions: _RevIdType,
|
||||||
|
message: Optional[str] = None,
|
||||||
|
branch_label: Optional[_RevIdType] = None,
|
||||||
|
rev_id: Optional[str] = None,
|
||||||
|
) -> Optional[Script]:
|
||||||
|
"""Merge two revisions together. Creates a new migration file.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance
|
||||||
|
|
||||||
|
:param revisions: The revisions to merge.
|
||||||
|
|
||||||
|
:param message: string message to apply to the revision.
|
||||||
|
|
||||||
|
:param branch_label: string label name to apply to the new revision.
|
||||||
|
|
||||||
|
:param rev_id: hardcoded revision identifier instead of generating a new
|
||||||
|
one.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`branches`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
template_args = {
|
||||||
|
"config": config # Let templates use config for
|
||||||
|
# e.g. multiple databases
|
||||||
|
}
|
||||||
|
|
||||||
|
environment = util.asbool(config.get_main_option("revision_environment"))
|
||||||
|
|
||||||
|
if environment:
|
||||||
|
|
||||||
|
def nothing(rev, context):
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script,
|
||||||
|
fn=nothing,
|
||||||
|
as_sql=False,
|
||||||
|
template_args=template_args,
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
return script.generate_revision(
|
||||||
|
rev_id or util.rev_id(),
|
||||||
|
message,
|
||||||
|
refresh=True,
|
||||||
|
head=revisions,
|
||||||
|
branch_labels=branch_label,
|
||||||
|
**template_args, # type:ignore[arg-type]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade(
|
||||||
|
config: Config,
|
||||||
|
revision: str,
|
||||||
|
sql: bool = False,
|
||||||
|
tag: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Upgrade to a later version.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param revision: string revision target or range for --sql mode. May be
|
||||||
|
``"heads"`` to target the most recent revision(s).
|
||||||
|
|
||||||
|
:param sql: if True, use ``--sql`` mode.
|
||||||
|
|
||||||
|
:param tag: an arbitrary "tag" that can be intercepted by custom
|
||||||
|
``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument`
|
||||||
|
method.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
starting_rev = None
|
||||||
|
if ":" in revision:
|
||||||
|
if not sql:
|
||||||
|
raise util.CommandError("Range revision not allowed")
|
||||||
|
starting_rev, revision = revision.split(":", 2)
|
||||||
|
|
||||||
|
def upgrade(rev, context):
|
||||||
|
return script._upgrade_revs(revision, rev)
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script,
|
||||||
|
fn=upgrade,
|
||||||
|
as_sql=sql,
|
||||||
|
starting_rev=starting_rev,
|
||||||
|
destination_rev=revision,
|
||||||
|
tag=tag,
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade(
|
||||||
|
config: Config,
|
||||||
|
revision: str,
|
||||||
|
sql: bool = False,
|
||||||
|
tag: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Revert to a previous version.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param revision: string revision target or range for --sql mode. May
|
||||||
|
be ``"base"`` to target the first revision.
|
||||||
|
|
||||||
|
:param sql: if True, use ``--sql`` mode.
|
||||||
|
|
||||||
|
:param tag: an arbitrary "tag" that can be intercepted by custom
|
||||||
|
``env.py`` scripts via the :meth:`.EnvironmentContext.get_tag_argument`
|
||||||
|
method.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
starting_rev = None
|
||||||
|
if ":" in revision:
|
||||||
|
if not sql:
|
||||||
|
raise util.CommandError("Range revision not allowed")
|
||||||
|
starting_rev, revision = revision.split(":", 2)
|
||||||
|
elif sql:
|
||||||
|
raise util.CommandError(
|
||||||
|
"downgrade with --sql requires <fromrev>:<torev>"
|
||||||
|
)
|
||||||
|
|
||||||
|
def downgrade(rev, context):
|
||||||
|
return script._downgrade_revs(revision, rev)
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script,
|
||||||
|
fn=downgrade,
|
||||||
|
as_sql=sql,
|
||||||
|
starting_rev=starting_rev,
|
||||||
|
destination_rev=revision,
|
||||||
|
tag=tag,
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
|
||||||
|
def show(config: Config, rev: str) -> None:
|
||||||
|
"""Show the revision(s) denoted by the given symbol.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param rev: string revision target. May be ``"current"`` to show the
|
||||||
|
revision(s) currently applied in the database.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
if rev == "current":
|
||||||
|
|
||||||
|
def show_current(rev, context):
|
||||||
|
for sc in script.get_revisions(rev):
|
||||||
|
config.print_stdout(sc.log_entry)
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(config, script, fn=show_current):
|
||||||
|
script.run_env()
|
||||||
|
else:
|
||||||
|
for sc in script.get_revisions(rev):
|
||||||
|
config.print_stdout(sc.log_entry)
|
||||||
|
|
||||||
|
|
||||||
|
def history(
|
||||||
|
config: Config,
|
||||||
|
rev_range: Optional[str] = None,
|
||||||
|
verbose: bool = False,
|
||||||
|
indicate_current: bool = False,
|
||||||
|
) -> None:
|
||||||
|
"""List changeset scripts in chronological order.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param rev_range: string revision range.
|
||||||
|
|
||||||
|
:param verbose: output in verbose mode.
|
||||||
|
|
||||||
|
:param indicate_current: indicate current revision.
|
||||||
|
|
||||||
|
"""
|
||||||
|
base: Optional[str]
|
||||||
|
head: Optional[str]
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
if rev_range is not None:
|
||||||
|
if ":" not in rev_range:
|
||||||
|
raise util.CommandError(
|
||||||
|
"History range requires [start]:[end], " "[start]:, or :[end]"
|
||||||
|
)
|
||||||
|
base, head = rev_range.strip().split(":")
|
||||||
|
else:
|
||||||
|
base = head = None
|
||||||
|
|
||||||
|
environment = (
|
||||||
|
util.asbool(config.get_main_option("revision_environment"))
|
||||||
|
or indicate_current
|
||||||
|
)
|
||||||
|
|
||||||
|
def _display_history(config, script, base, head, currents=()):
|
||||||
|
for sc in script.walk_revisions(
|
||||||
|
base=base or "base", head=head or "heads"
|
||||||
|
):
|
||||||
|
if indicate_current:
|
||||||
|
sc._db_current_indicator = sc.revision in currents
|
||||||
|
|
||||||
|
config.print_stdout(
|
||||||
|
sc.cmd_format(
|
||||||
|
verbose=verbose,
|
||||||
|
include_branches=True,
|
||||||
|
include_doc=True,
|
||||||
|
include_parents=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _display_history_w_current(config, script, base, head):
|
||||||
|
def _display_current_history(rev, context):
|
||||||
|
if head == "current":
|
||||||
|
_display_history(config, script, base, rev, rev)
|
||||||
|
elif base == "current":
|
||||||
|
_display_history(config, script, rev, head, rev)
|
||||||
|
else:
|
||||||
|
_display_history(config, script, base, head, rev)
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(config, script, fn=_display_current_history):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
if base == "current" or head == "current" or environment:
|
||||||
|
_display_history_w_current(config, script, base, head)
|
||||||
|
else:
|
||||||
|
_display_history(config, script, base, head)
|
||||||
|
|
||||||
|
|
||||||
|
def heads(
|
||||||
|
config: Config, verbose: bool = False, resolve_dependencies: bool = False
|
||||||
|
) -> None:
|
||||||
|
"""Show current available heads in the script directory.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param verbose: output in verbose mode.
|
||||||
|
|
||||||
|
:param resolve_dependencies: treat dependency version as down revisions.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
if resolve_dependencies:
|
||||||
|
heads = script.get_revisions("heads")
|
||||||
|
else:
|
||||||
|
heads = script.get_revisions(script.get_heads())
|
||||||
|
|
||||||
|
for rev in heads:
|
||||||
|
config.print_stdout(
|
||||||
|
rev.cmd_format(
|
||||||
|
verbose, include_branches=True, tree_indicators=False
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def branches(config: Config, verbose: bool = False) -> None:
|
||||||
|
"""Show current branch points.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param verbose: output in verbose mode.
|
||||||
|
|
||||||
|
"""
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
for sc in script.walk_revisions():
|
||||||
|
if sc.is_branch_point:
|
||||||
|
config.print_stdout(
|
||||||
|
"%s\n%s\n",
|
||||||
|
sc.cmd_format(verbose, include_branches=True),
|
||||||
|
"\n".join(
|
||||||
|
"%s -> %s"
|
||||||
|
% (
|
||||||
|
" " * len(str(sc.revision)),
|
||||||
|
rev_obj.cmd_format(
|
||||||
|
False, include_branches=True, include_doc=verbose
|
||||||
|
),
|
||||||
|
)
|
||||||
|
for rev_obj in (
|
||||||
|
script.get_revision(rev) for rev in sc.nextrev
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def current(config: Config, verbose: bool = False) -> None:
|
||||||
|
"""Display the current revision for a database.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param verbose: output in verbose mode.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
def display_version(rev, context):
|
||||||
|
if verbose:
|
||||||
|
config.print_stdout(
|
||||||
|
"Current revision(s) for %s:",
|
||||||
|
util.obfuscate_url_pw(context.connection.engine.url),
|
||||||
|
)
|
||||||
|
for rev in script.get_all_current(rev):
|
||||||
|
config.print_stdout(rev.cmd_format(verbose))
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config, script, fn=display_version, dont_mutate=True
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
|
||||||
|
def stamp(
|
||||||
|
config: Config,
|
||||||
|
revision: _RevIdType,
|
||||||
|
sql: bool = False,
|
||||||
|
tag: Optional[str] = None,
|
||||||
|
purge: bool = False,
|
||||||
|
) -> None:
|
||||||
|
"""'stamp' the revision table with the given revision; don't
|
||||||
|
run any migrations.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param revision: target revision or list of revisions. May be a list
|
||||||
|
to indicate stamping of multiple branch heads; may be ``"base"``
|
||||||
|
to remove all revisions from the table or ``"heads"`` to stamp the
|
||||||
|
most recent revision(s).
|
||||||
|
|
||||||
|
.. note:: this parameter is called "revisions" in the command line
|
||||||
|
interface.
|
||||||
|
|
||||||
|
:param sql: use ``--sql`` mode
|
||||||
|
|
||||||
|
:param tag: an arbitrary "tag" that can be intercepted by custom
|
||||||
|
``env.py`` scripts via the :class:`.EnvironmentContext.get_tag_argument`
|
||||||
|
method.
|
||||||
|
|
||||||
|
:param purge: delete all entries in the version table before stamping.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
if sql:
|
||||||
|
destination_revs = []
|
||||||
|
starting_rev = None
|
||||||
|
for _revision in util.to_list(revision):
|
||||||
|
if ":" in _revision:
|
||||||
|
srev, _revision = _revision.split(":", 2)
|
||||||
|
|
||||||
|
if starting_rev != srev:
|
||||||
|
if starting_rev is None:
|
||||||
|
starting_rev = srev
|
||||||
|
else:
|
||||||
|
raise util.CommandError(
|
||||||
|
"Stamp operation with --sql only supports a "
|
||||||
|
"single starting revision at a time"
|
||||||
|
)
|
||||||
|
destination_revs.append(_revision)
|
||||||
|
else:
|
||||||
|
destination_revs = util.to_list(revision)
|
||||||
|
|
||||||
|
def do_stamp(rev, context):
|
||||||
|
return script._stamp_revs(util.to_tuple(destination_revs), rev)
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script,
|
||||||
|
fn=do_stamp,
|
||||||
|
as_sql=sql,
|
||||||
|
starting_rev=starting_rev if sql else None,
|
||||||
|
destination_rev=util.to_tuple(destination_revs),
|
||||||
|
tag=tag,
|
||||||
|
purge=purge,
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
|
|
||||||
|
|
||||||
|
def edit(config: Config, rev: str) -> None:
|
||||||
|
"""Edit revision script(s) using $EDITOR.
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param rev: target revision.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
if rev == "current":
|
||||||
|
|
||||||
|
def edit_current(rev, context):
|
||||||
|
if not rev:
|
||||||
|
raise util.CommandError("No current revisions")
|
||||||
|
for sc in script.get_revisions(rev):
|
||||||
|
util.open_in_editor(sc.path)
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(config, script, fn=edit_current):
|
||||||
|
script.run_env()
|
||||||
|
else:
|
||||||
|
revs = script.get_revisions(rev)
|
||||||
|
if not revs:
|
||||||
|
raise util.CommandError(
|
||||||
|
"No revision files indicated by symbol '%s'" % rev
|
||||||
|
)
|
||||||
|
for sc in revs:
|
||||||
|
assert sc
|
||||||
|
util.open_in_editor(sc.path)
|
||||||
|
|
||||||
|
|
||||||
|
def ensure_version(config: Config, sql: bool = False) -> None:
|
||||||
|
"""Create the alembic version table if it doesn't exist already .
|
||||||
|
|
||||||
|
:param config: a :class:`.Config` instance.
|
||||||
|
|
||||||
|
:param sql: use ``--sql`` mode.
|
||||||
|
|
||||||
|
.. versionadded:: 1.7.6
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script = ScriptDirectory.from_config(config)
|
||||||
|
|
||||||
|
def do_ensure_version(rev, context):
|
||||||
|
context._ensure_version_table()
|
||||||
|
return []
|
||||||
|
|
||||||
|
with EnvironmentContext(
|
||||||
|
config,
|
||||||
|
script,
|
||||||
|
fn=do_ensure_version,
|
||||||
|
as_sql=sql,
|
||||||
|
):
|
||||||
|
script.run_env()
|
||||||
@@ -0,0 +1,640 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from argparse import Namespace
|
||||||
|
from configparser import ConfigParser
|
||||||
|
import inspect
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from typing import Any
|
||||||
|
from typing import cast
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Mapping
|
||||||
|
from typing import Optional
|
||||||
|
from typing import overload
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import TextIO
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from typing_extensions import TypedDict
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
from . import command
|
||||||
|
from . import util
|
||||||
|
from .util import compat
|
||||||
|
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
r"""Represent an Alembic configuration.
|
||||||
|
|
||||||
|
Within an ``env.py`` script, this is available
|
||||||
|
via the :attr:`.EnvironmentContext.config` attribute,
|
||||||
|
which in turn is available at ``alembic.context``::
|
||||||
|
|
||||||
|
from alembic import context
|
||||||
|
|
||||||
|
some_param = context.config.get_main_option("my option")
|
||||||
|
|
||||||
|
When invoking Alembic programmatically, a new
|
||||||
|
:class:`.Config` can be created by passing
|
||||||
|
the name of an .ini file to the constructor::
|
||||||
|
|
||||||
|
from alembic.config import Config
|
||||||
|
alembic_cfg = Config("/path/to/yourapp/alembic.ini")
|
||||||
|
|
||||||
|
With a :class:`.Config` object, you can then
|
||||||
|
run Alembic commands programmatically using the directives
|
||||||
|
in :mod:`alembic.command`.
|
||||||
|
|
||||||
|
The :class:`.Config` object can also be constructed without
|
||||||
|
a filename. Values can be set programmatically, and
|
||||||
|
new sections will be created as needed::
|
||||||
|
|
||||||
|
from alembic.config import Config
|
||||||
|
alembic_cfg = Config()
|
||||||
|
alembic_cfg.set_main_option("script_location", "myapp:migrations")
|
||||||
|
alembic_cfg.set_main_option("sqlalchemy.url", "postgresql://foo/bar")
|
||||||
|
alembic_cfg.set_section_option("mysection", "foo", "bar")
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
When using programmatic configuration, make sure the
|
||||||
|
``env.py`` file in use is compatible with the target configuration;
|
||||||
|
including that the call to Python ``logging.fileConfig()`` is
|
||||||
|
omitted if the programmatic configuration doesn't actually include
|
||||||
|
logging directives.
|
||||||
|
|
||||||
|
For passing non-string values to environments, such as connections and
|
||||||
|
engines, use the :attr:`.Config.attributes` dictionary::
|
||||||
|
|
||||||
|
with engine.begin() as connection:
|
||||||
|
alembic_cfg.attributes['connection'] = connection
|
||||||
|
command.upgrade(alembic_cfg, "head")
|
||||||
|
|
||||||
|
:param file\_: name of the .ini file to open.
|
||||||
|
:param ini_section: name of the main Alembic section within the
|
||||||
|
.ini file
|
||||||
|
:param output_buffer: optional file-like input buffer which
|
||||||
|
will be passed to the :class:`.MigrationContext` - used to redirect
|
||||||
|
the output of "offline generation" when using Alembic programmatically.
|
||||||
|
:param stdout: buffer where the "print" output of commands will be sent.
|
||||||
|
Defaults to ``sys.stdout``.
|
||||||
|
|
||||||
|
:param config_args: A dictionary of keys and values that will be used
|
||||||
|
for substitution in the alembic config file. The dictionary as given
|
||||||
|
is **copied** to a new one, stored locally as the attribute
|
||||||
|
``.config_args``. When the :attr:`.Config.file_config` attribute is
|
||||||
|
first invoked, the replacement variable ``here`` will be added to this
|
||||||
|
dictionary before the dictionary is passed to ``ConfigParser()``
|
||||||
|
to parse the .ini file.
|
||||||
|
|
||||||
|
:param attributes: optional dictionary of arbitrary Python keys/values,
|
||||||
|
which will be populated into the :attr:`.Config.attributes` dictionary.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`connection_sharing`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
file_: Union[str, os.PathLike[str], None] = None,
|
||||||
|
ini_section: str = "alembic",
|
||||||
|
output_buffer: Optional[TextIO] = None,
|
||||||
|
stdout: TextIO = sys.stdout,
|
||||||
|
cmd_opts: Optional[Namespace] = None,
|
||||||
|
config_args: Mapping[str, Any] = util.immutabledict(),
|
||||||
|
attributes: Optional[Dict[str, Any]] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Construct a new :class:`.Config`"""
|
||||||
|
self.config_file_name = file_
|
||||||
|
self.config_ini_section = ini_section
|
||||||
|
self.output_buffer = output_buffer
|
||||||
|
self.stdout = stdout
|
||||||
|
self.cmd_opts = cmd_opts
|
||||||
|
self.config_args = dict(config_args)
|
||||||
|
if attributes:
|
||||||
|
self.attributes.update(attributes)
|
||||||
|
|
||||||
|
cmd_opts: Optional[Namespace] = None
|
||||||
|
"""The command-line options passed to the ``alembic`` script.
|
||||||
|
|
||||||
|
Within an ``env.py`` script this can be accessed via the
|
||||||
|
:attr:`.EnvironmentContext.config` attribute.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:meth:`.EnvironmentContext.get_x_argument`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
config_file_name: Union[str, os.PathLike[str], None] = None
|
||||||
|
"""Filesystem path to the .ini file in use."""
|
||||||
|
|
||||||
|
config_ini_section: str = None # type:ignore[assignment]
|
||||||
|
"""Name of the config file section to read basic configuration
|
||||||
|
from. Defaults to ``alembic``, that is the ``[alembic]`` section
|
||||||
|
of the .ini file. This value is modified using the ``-n/--name``
|
||||||
|
option to the Alembic runner.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def attributes(self) -> Dict[str, Any]:
|
||||||
|
"""A Python dictionary for storage of additional state.
|
||||||
|
|
||||||
|
|
||||||
|
This is a utility dictionary which can include not just strings but
|
||||||
|
engines, connections, schema objects, or anything else.
|
||||||
|
Use this to pass objects into an env.py script, such as passing
|
||||||
|
a :class:`sqlalchemy.engine.base.Connection` when calling
|
||||||
|
commands from :mod:`alembic.command` programmatically.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`connection_sharing`
|
||||||
|
|
||||||
|
:paramref:`.Config.attributes`
|
||||||
|
|
||||||
|
"""
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def print_stdout(self, text: str, *arg: Any) -> None:
|
||||||
|
"""Render a message to standard out.
|
||||||
|
|
||||||
|
When :meth:`.Config.print_stdout` is called with additional args
|
||||||
|
those arguments will formatted against the provided text,
|
||||||
|
otherwise we simply output the provided text verbatim.
|
||||||
|
|
||||||
|
This is a no-op when the``quiet`` messaging option is enabled.
|
||||||
|
|
||||||
|
e.g.::
|
||||||
|
|
||||||
|
>>> config.print_stdout('Some text %s', 'arg')
|
||||||
|
Some Text arg
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if arg:
|
||||||
|
output = str(text) % arg
|
||||||
|
else:
|
||||||
|
output = str(text)
|
||||||
|
|
||||||
|
util.write_outstream(self.stdout, output, "\n", **self.messaging_opts)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def file_config(self) -> ConfigParser:
|
||||||
|
"""Return the underlying ``ConfigParser`` object.
|
||||||
|
|
||||||
|
Direct access to the .ini file is available here,
|
||||||
|
though the :meth:`.Config.get_section` and
|
||||||
|
:meth:`.Config.get_main_option`
|
||||||
|
methods provide a possibly simpler interface.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if self.config_file_name:
|
||||||
|
here = os.path.abspath(os.path.dirname(self.config_file_name))
|
||||||
|
else:
|
||||||
|
here = ""
|
||||||
|
self.config_args["here"] = here
|
||||||
|
file_config = ConfigParser(self.config_args)
|
||||||
|
if self.config_file_name:
|
||||||
|
compat.read_config_parser(file_config, [self.config_file_name])
|
||||||
|
else:
|
||||||
|
file_config.add_section(self.config_ini_section)
|
||||||
|
return file_config
|
||||||
|
|
||||||
|
def get_template_directory(self) -> str:
|
||||||
|
"""Return the directory where Alembic setup templates are found.
|
||||||
|
|
||||||
|
This method is used by the alembic ``init`` and ``list_templates``
|
||||||
|
commands.
|
||||||
|
|
||||||
|
"""
|
||||||
|
import alembic
|
||||||
|
|
||||||
|
package_dir = os.path.abspath(os.path.dirname(alembic.__file__))
|
||||||
|
return os.path.join(package_dir, "templates")
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_section(
|
||||||
|
self, name: str, default: None = ...
|
||||||
|
) -> Optional[Dict[str, str]]: ...
|
||||||
|
|
||||||
|
# "default" here could also be a TypeVar
|
||||||
|
# _MT = TypeVar("_MT", bound=Mapping[str, str]),
|
||||||
|
# however mypy wasn't handling that correctly (pyright was)
|
||||||
|
@overload
|
||||||
|
def get_section(
|
||||||
|
self, name: str, default: Dict[str, str]
|
||||||
|
) -> Dict[str, str]: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_section(
|
||||||
|
self, name: str, default: Mapping[str, str]
|
||||||
|
) -> Union[Dict[str, str], Mapping[str, str]]: ...
|
||||||
|
|
||||||
|
def get_section(
|
||||||
|
self, name: str, default: Optional[Mapping[str, str]] = None
|
||||||
|
) -> Optional[Mapping[str, str]]:
|
||||||
|
"""Return all the configuration options from a given .ini file section
|
||||||
|
as a dictionary.
|
||||||
|
|
||||||
|
If the given section does not exist, the value of ``default``
|
||||||
|
is returned, which is expected to be a dictionary or other mapping.
|
||||||
|
|
||||||
|
"""
|
||||||
|
if not self.file_config.has_section(name):
|
||||||
|
return default
|
||||||
|
|
||||||
|
return dict(self.file_config.items(name))
|
||||||
|
|
||||||
|
def set_main_option(self, name: str, value: str) -> None:
|
||||||
|
"""Set an option programmatically within the 'main' section.
|
||||||
|
|
||||||
|
This overrides whatever was in the .ini file.
|
||||||
|
|
||||||
|
:param name: name of the value
|
||||||
|
|
||||||
|
:param value: the value. Note that this value is passed to
|
||||||
|
``ConfigParser.set``, which supports variable interpolation using
|
||||||
|
pyformat (e.g. ``%(some_value)s``). A raw percent sign not part of
|
||||||
|
an interpolation symbol must therefore be escaped, e.g. ``%%``.
|
||||||
|
The given value may refer to another value already in the file
|
||||||
|
using the interpolation format.
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.set_section_option(self.config_ini_section, name, value)
|
||||||
|
|
||||||
|
def remove_main_option(self, name: str) -> None:
|
||||||
|
self.file_config.remove_option(self.config_ini_section, name)
|
||||||
|
|
||||||
|
def set_section_option(self, section: str, name: str, value: str) -> None:
|
||||||
|
"""Set an option programmatically within the given section.
|
||||||
|
|
||||||
|
The section is created if it doesn't exist already.
|
||||||
|
The value here will override whatever was in the .ini
|
||||||
|
file.
|
||||||
|
|
||||||
|
:param section: name of the section
|
||||||
|
|
||||||
|
:param name: name of the value
|
||||||
|
|
||||||
|
:param value: the value. Note that this value is passed to
|
||||||
|
``ConfigParser.set``, which supports variable interpolation using
|
||||||
|
pyformat (e.g. ``%(some_value)s``). A raw percent sign not part of
|
||||||
|
an interpolation symbol must therefore be escaped, e.g. ``%%``.
|
||||||
|
The given value may refer to another value already in the file
|
||||||
|
using the interpolation format.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not self.file_config.has_section(section):
|
||||||
|
self.file_config.add_section(section)
|
||||||
|
self.file_config.set(section, name, value)
|
||||||
|
|
||||||
|
def get_section_option(
|
||||||
|
self, section: str, name: str, default: Optional[str] = None
|
||||||
|
) -> Optional[str]:
|
||||||
|
"""Return an option from the given section of the .ini file."""
|
||||||
|
if not self.file_config.has_section(section):
|
||||||
|
raise util.CommandError(
|
||||||
|
"No config file %r found, or file has no "
|
||||||
|
"'[%s]' section" % (self.config_file_name, section)
|
||||||
|
)
|
||||||
|
if self.file_config.has_option(section, name):
|
||||||
|
return self.file_config.get(section, name)
|
||||||
|
else:
|
||||||
|
return default
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_main_option(self, name: str, default: str) -> str: ...
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_main_option(
|
||||||
|
self, name: str, default: Optional[str] = None
|
||||||
|
) -> Optional[str]: ...
|
||||||
|
|
||||||
|
def get_main_option(
|
||||||
|
self, name: str, default: Optional[str] = None
|
||||||
|
) -> Optional[str]:
|
||||||
|
"""Return an option from the 'main' section of the .ini file.
|
||||||
|
|
||||||
|
This defaults to being a key from the ``[alembic]``
|
||||||
|
section, unless the ``-n/--name`` flag were used to
|
||||||
|
indicate a different section.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return self.get_section_option(self.config_ini_section, name, default)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def messaging_opts(self) -> MessagingOptions:
|
||||||
|
"""The messaging options."""
|
||||||
|
return cast(
|
||||||
|
MessagingOptions,
|
||||||
|
util.immutabledict(
|
||||||
|
{"quiet": getattr(self.cmd_opts, "quiet", False)}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MessagingOptions(TypedDict, total=False):
|
||||||
|
quiet: bool
|
||||||
|
|
||||||
|
|
||||||
|
class CommandLine:
|
||||||
|
def __init__(self, prog: Optional[str] = None) -> None:
|
||||||
|
self._generate_args(prog)
|
||||||
|
|
||||||
|
def _generate_args(self, prog: Optional[str]) -> None:
|
||||||
|
def add_options(
|
||||||
|
fn: Any, parser: Any, positional: Any, kwargs: Any
|
||||||
|
) -> None:
|
||||||
|
kwargs_opts = {
|
||||||
|
"template": (
|
||||||
|
"-t",
|
||||||
|
"--template",
|
||||||
|
dict(
|
||||||
|
default="generic",
|
||||||
|
type=str,
|
||||||
|
help="Setup template for use with 'init'",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"message": (
|
||||||
|
"-m",
|
||||||
|
"--message",
|
||||||
|
dict(
|
||||||
|
type=str, help="Message string to use with 'revision'"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"sql": (
|
||||||
|
"--sql",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Don't emit SQL to database - dump to "
|
||||||
|
"standard output/file instead. See docs on "
|
||||||
|
"offline mode.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"tag": (
|
||||||
|
"--tag",
|
||||||
|
dict(
|
||||||
|
type=str,
|
||||||
|
help="Arbitrary 'tag' name - can be used by "
|
||||||
|
"custom env.py scripts.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"head": (
|
||||||
|
"--head",
|
||||||
|
dict(
|
||||||
|
type=str,
|
||||||
|
help="Specify head revision or <branchname>@head "
|
||||||
|
"to base new revision on.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"splice": (
|
||||||
|
"--splice",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Allow a non-head revision as the "
|
||||||
|
"'head' to splice onto",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"depends_on": (
|
||||||
|
"--depends-on",
|
||||||
|
dict(
|
||||||
|
action="append",
|
||||||
|
help="Specify one or more revision identifiers "
|
||||||
|
"which this revision should depend on.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"rev_id": (
|
||||||
|
"--rev-id",
|
||||||
|
dict(
|
||||||
|
type=str,
|
||||||
|
help="Specify a hardcoded revision id instead of "
|
||||||
|
"generating one",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"version_path": (
|
||||||
|
"--version-path",
|
||||||
|
dict(
|
||||||
|
type=str,
|
||||||
|
help="Specify specific path from config for "
|
||||||
|
"version file",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"branch_label": (
|
||||||
|
"--branch-label",
|
||||||
|
dict(
|
||||||
|
type=str,
|
||||||
|
help="Specify a branch label to apply to the "
|
||||||
|
"new revision",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"verbose": (
|
||||||
|
"-v",
|
||||||
|
"--verbose",
|
||||||
|
dict(action="store_true", help="Use more verbose output"),
|
||||||
|
),
|
||||||
|
"resolve_dependencies": (
|
||||||
|
"--resolve-dependencies",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Treat dependency versions as down revisions",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"autogenerate": (
|
||||||
|
"--autogenerate",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Populate revision script with candidate "
|
||||||
|
"migration operations, based on comparison "
|
||||||
|
"of database to model.",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"rev_range": (
|
||||||
|
"-r",
|
||||||
|
"--rev-range",
|
||||||
|
dict(
|
||||||
|
action="store",
|
||||||
|
help="Specify a revision range; "
|
||||||
|
"format is [start]:[end]",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"indicate_current": (
|
||||||
|
"-i",
|
||||||
|
"--indicate-current",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Indicate the current revision",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"purge": (
|
||||||
|
"--purge",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Unconditionally erase the version table "
|
||||||
|
"before stamping",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
"package": (
|
||||||
|
"--package",
|
||||||
|
dict(
|
||||||
|
action="store_true",
|
||||||
|
help="Write empty __init__.py files to the "
|
||||||
|
"environment and version locations",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
}
|
||||||
|
positional_help = {
|
||||||
|
"directory": "location of scripts directory",
|
||||||
|
"revision": "revision identifier",
|
||||||
|
"revisions": "one or more revisions, or 'heads' for all heads",
|
||||||
|
}
|
||||||
|
for arg in kwargs:
|
||||||
|
if arg in kwargs_opts:
|
||||||
|
args = kwargs_opts[arg]
|
||||||
|
args, kw = args[0:-1], args[-1]
|
||||||
|
parser.add_argument(*args, **kw)
|
||||||
|
|
||||||
|
for arg in positional:
|
||||||
|
if (
|
||||||
|
arg == "revisions"
|
||||||
|
or fn in positional_translations
|
||||||
|
and positional_translations[fn][arg] == "revisions"
|
||||||
|
):
|
||||||
|
subparser.add_argument(
|
||||||
|
"revisions",
|
||||||
|
nargs="+",
|
||||||
|
help=positional_help.get("revisions"),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
subparser.add_argument(arg, help=positional_help.get(arg))
|
||||||
|
|
||||||
|
parser = ArgumentParser(prog=prog)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--version", action="version", version="%%(prog)s %s" % __version__
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-c",
|
||||||
|
"--config",
|
||||||
|
type=str,
|
||||||
|
default=os.environ.get("ALEMBIC_CONFIG", "alembic.ini"),
|
||||||
|
help="Alternate config file; defaults to value of "
|
||||||
|
'ALEMBIC_CONFIG environment variable, or "alembic.ini"',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-n",
|
||||||
|
"--name",
|
||||||
|
type=str,
|
||||||
|
default="alembic",
|
||||||
|
help="Name of section in .ini file to " "use for Alembic config",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-x",
|
||||||
|
action="append",
|
||||||
|
help="Additional arguments consumed by "
|
||||||
|
"custom env.py scripts, e.g. -x "
|
||||||
|
"setting1=somesetting -x setting2=somesetting",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--raiseerr",
|
||||||
|
action="store_true",
|
||||||
|
help="Raise a full stack trace on error",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-q",
|
||||||
|
"--quiet",
|
||||||
|
action="store_true",
|
||||||
|
help="Do not log to std output.",
|
||||||
|
)
|
||||||
|
subparsers = parser.add_subparsers()
|
||||||
|
|
||||||
|
positional_translations: Dict[Any, Any] = {
|
||||||
|
command.stamp: {"revision": "revisions"}
|
||||||
|
}
|
||||||
|
|
||||||
|
for fn in [getattr(command, n) for n in dir(command)]:
|
||||||
|
if (
|
||||||
|
inspect.isfunction(fn)
|
||||||
|
and fn.__name__[0] != "_"
|
||||||
|
and fn.__module__ == "alembic.command"
|
||||||
|
):
|
||||||
|
spec = compat.inspect_getfullargspec(fn)
|
||||||
|
if spec[3] is not None:
|
||||||
|
positional = spec[0][1 : -len(spec[3])]
|
||||||
|
kwarg = spec[0][-len(spec[3]) :]
|
||||||
|
else:
|
||||||
|
positional = spec[0][1:]
|
||||||
|
kwarg = []
|
||||||
|
|
||||||
|
if fn in positional_translations:
|
||||||
|
positional = [
|
||||||
|
positional_translations[fn].get(name, name)
|
||||||
|
for name in positional
|
||||||
|
]
|
||||||
|
|
||||||
|
# parse first line(s) of helptext without a line break
|
||||||
|
help_ = fn.__doc__
|
||||||
|
if help_:
|
||||||
|
help_text = []
|
||||||
|
for line in help_.split("\n"):
|
||||||
|
if not line.strip():
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
help_text.append(line.strip())
|
||||||
|
else:
|
||||||
|
help_text = []
|
||||||
|
subparser = subparsers.add_parser(
|
||||||
|
fn.__name__, help=" ".join(help_text)
|
||||||
|
)
|
||||||
|
add_options(fn, subparser, positional, kwarg)
|
||||||
|
subparser.set_defaults(cmd=(fn, positional, kwarg))
|
||||||
|
self.parser = parser
|
||||||
|
|
||||||
|
def run_cmd(self, config: Config, options: Namespace) -> None:
|
||||||
|
fn, positional, kwarg = options.cmd
|
||||||
|
|
||||||
|
try:
|
||||||
|
fn(
|
||||||
|
config,
|
||||||
|
*[getattr(options, k, None) for k in positional],
|
||||||
|
**{k: getattr(options, k, None) for k in kwarg},
|
||||||
|
)
|
||||||
|
except util.CommandError as e:
|
||||||
|
if options.raiseerr:
|
||||||
|
raise
|
||||||
|
else:
|
||||||
|
util.err(str(e), **config.messaging_opts)
|
||||||
|
|
||||||
|
def main(self, argv: Optional[Sequence[str]] = None) -> None:
|
||||||
|
options = self.parser.parse_args(argv)
|
||||||
|
if not hasattr(options, "cmd"):
|
||||||
|
# see http://bugs.python.org/issue9253, argparse
|
||||||
|
# behavior changed incompatibly in py3.3
|
||||||
|
self.parser.error("too few arguments")
|
||||||
|
else:
|
||||||
|
cfg = Config(
|
||||||
|
file_=options.config,
|
||||||
|
ini_section=options.name,
|
||||||
|
cmd_opts=options,
|
||||||
|
)
|
||||||
|
self.run_cmd(cfg, options)
|
||||||
|
|
||||||
|
|
||||||
|
def main(
|
||||||
|
argv: Optional[Sequence[str]] = None,
|
||||||
|
prog: Optional[str] = None,
|
||||||
|
**kwargs: Any,
|
||||||
|
) -> None:
|
||||||
|
"""The console runner function for Alembic."""
|
||||||
|
|
||||||
|
CommandLine(prog=prog).main(argv=argv)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
from .runtime.environment import EnvironmentContext
|
||||||
|
|
||||||
|
# create proxy functions for
|
||||||
|
# each method on the EnvironmentContext class.
|
||||||
|
EnvironmentContext.create_module_class_proxy(globals(), locals())
|
||||||
@@ -0,0 +1,853 @@
|
|||||||
|
# ### this file stubs are generated by tools/write_pyi.py - do not edit ###
|
||||||
|
# ### imports are manually managed
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Collection
|
||||||
|
from typing import ContextManager
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Iterable
|
||||||
|
from typing import List
|
||||||
|
from typing import Literal
|
||||||
|
from typing import Mapping
|
||||||
|
from typing import MutableMapping
|
||||||
|
from typing import Optional
|
||||||
|
from typing import overload
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import TextIO
|
||||||
|
from typing import Tuple
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from sqlalchemy.engine.base import Connection
|
||||||
|
from sqlalchemy.engine.url import URL
|
||||||
|
from sqlalchemy.sql import Executable
|
||||||
|
from sqlalchemy.sql.schema import Column
|
||||||
|
from sqlalchemy.sql.schema import FetchedValue
|
||||||
|
from sqlalchemy.sql.schema import MetaData
|
||||||
|
from sqlalchemy.sql.schema import SchemaItem
|
||||||
|
from sqlalchemy.sql.type_api import TypeEngine
|
||||||
|
|
||||||
|
from .autogenerate.api import AutogenContext
|
||||||
|
from .config import Config
|
||||||
|
from .operations.ops import MigrationScript
|
||||||
|
from .runtime.migration import _ProxyTransaction
|
||||||
|
from .runtime.migration import MigrationContext
|
||||||
|
from .runtime.migration import MigrationInfo
|
||||||
|
from .script import ScriptDirectory
|
||||||
|
|
||||||
|
### end imports ###
|
||||||
|
|
||||||
|
def begin_transaction() -> Union[_ProxyTransaction, ContextManager[None]]:
|
||||||
|
"""Return a context manager that will
|
||||||
|
enclose an operation within a "transaction",
|
||||||
|
as defined by the environment's offline
|
||||||
|
and transactional DDL settings.
|
||||||
|
|
||||||
|
e.g.::
|
||||||
|
|
||||||
|
with context.begin_transaction():
|
||||||
|
context.run_migrations()
|
||||||
|
|
||||||
|
:meth:`.begin_transaction` is intended to
|
||||||
|
"do the right thing" regardless of
|
||||||
|
calling context:
|
||||||
|
|
||||||
|
* If :meth:`.is_transactional_ddl` is ``False``,
|
||||||
|
returns a "do nothing" context manager
|
||||||
|
which otherwise produces no transactional
|
||||||
|
state or directives.
|
||||||
|
* If :meth:`.is_offline_mode` is ``True``,
|
||||||
|
returns a context manager that will
|
||||||
|
invoke the :meth:`.DefaultImpl.emit_begin`
|
||||||
|
and :meth:`.DefaultImpl.emit_commit`
|
||||||
|
methods, which will produce the string
|
||||||
|
directives ``BEGIN`` and ``COMMIT`` on
|
||||||
|
the output stream, as rendered by the
|
||||||
|
target backend (e.g. SQL Server would
|
||||||
|
emit ``BEGIN TRANSACTION``).
|
||||||
|
* Otherwise, calls :meth:`sqlalchemy.engine.Connection.begin`
|
||||||
|
on the current online connection, which
|
||||||
|
returns a :class:`sqlalchemy.engine.Transaction`
|
||||||
|
object. This object demarcates a real
|
||||||
|
transaction and is itself a context manager,
|
||||||
|
which will roll back if an exception
|
||||||
|
is raised.
|
||||||
|
|
||||||
|
Note that a custom ``env.py`` script which
|
||||||
|
has more specific transactional needs can of course
|
||||||
|
manipulate the :class:`~sqlalchemy.engine.Connection`
|
||||||
|
directly to produce transactional state in "online"
|
||||||
|
mode.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
config: Config
|
||||||
|
|
||||||
|
def configure(
|
||||||
|
connection: Optional[Connection] = None,
|
||||||
|
url: Union[str, URL, None] = None,
|
||||||
|
dialect_name: Optional[str] = None,
|
||||||
|
dialect_opts: Optional[Dict[str, Any]] = None,
|
||||||
|
transactional_ddl: Optional[bool] = None,
|
||||||
|
transaction_per_migration: bool = False,
|
||||||
|
output_buffer: Optional[TextIO] = None,
|
||||||
|
starting_rev: Optional[str] = None,
|
||||||
|
tag: Optional[str] = None,
|
||||||
|
template_args: Optional[Dict[str, Any]] = None,
|
||||||
|
render_as_batch: bool = False,
|
||||||
|
target_metadata: Union[MetaData, Sequence[MetaData], None] = None,
|
||||||
|
include_name: Optional[
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
Optional[str],
|
||||||
|
Literal[
|
||||||
|
"schema",
|
||||||
|
"table",
|
||||||
|
"column",
|
||||||
|
"index",
|
||||||
|
"unique_constraint",
|
||||||
|
"foreign_key_constraint",
|
||||||
|
],
|
||||||
|
MutableMapping[
|
||||||
|
Literal[
|
||||||
|
"schema_name",
|
||||||
|
"table_name",
|
||||||
|
"schema_qualified_table_name",
|
||||||
|
],
|
||||||
|
Optional[str],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
bool,
|
||||||
|
]
|
||||||
|
] = None,
|
||||||
|
include_object: Optional[
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
SchemaItem,
|
||||||
|
Optional[str],
|
||||||
|
Literal[
|
||||||
|
"schema",
|
||||||
|
"table",
|
||||||
|
"column",
|
||||||
|
"index",
|
||||||
|
"unique_constraint",
|
||||||
|
"foreign_key_constraint",
|
||||||
|
],
|
||||||
|
bool,
|
||||||
|
Optional[SchemaItem],
|
||||||
|
],
|
||||||
|
bool,
|
||||||
|
]
|
||||||
|
] = None,
|
||||||
|
include_schemas: bool = False,
|
||||||
|
process_revision_directives: Optional[
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
MigrationContext,
|
||||||
|
Union[str, Iterable[Optional[str]], Iterable[str]],
|
||||||
|
List[MigrationScript],
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
]
|
||||||
|
] = None,
|
||||||
|
compare_type: Union[
|
||||||
|
bool,
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
MigrationContext,
|
||||||
|
Column[Any],
|
||||||
|
Column[Any],
|
||||||
|
TypeEngine[Any],
|
||||||
|
TypeEngine[Any],
|
||||||
|
],
|
||||||
|
Optional[bool],
|
||||||
|
],
|
||||||
|
] = True,
|
||||||
|
compare_server_default: Union[
|
||||||
|
bool,
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
MigrationContext,
|
||||||
|
Column[Any],
|
||||||
|
Column[Any],
|
||||||
|
Optional[str],
|
||||||
|
Optional[FetchedValue],
|
||||||
|
Optional[str],
|
||||||
|
],
|
||||||
|
Optional[bool],
|
||||||
|
],
|
||||||
|
] = False,
|
||||||
|
render_item: Optional[
|
||||||
|
Callable[[str, Any, AutogenContext], Union[str, Literal[False]]]
|
||||||
|
] = None,
|
||||||
|
literal_binds: bool = False,
|
||||||
|
upgrade_token: str = "upgrades",
|
||||||
|
downgrade_token: str = "downgrades",
|
||||||
|
alembic_module_prefix: str = "op.",
|
||||||
|
sqlalchemy_module_prefix: str = "sa.",
|
||||||
|
user_module_prefix: Optional[str] = None,
|
||||||
|
on_version_apply: Optional[
|
||||||
|
Callable[
|
||||||
|
[
|
||||||
|
MigrationContext,
|
||||||
|
MigrationInfo,
|
||||||
|
Collection[Any],
|
||||||
|
Mapping[str, Any],
|
||||||
|
],
|
||||||
|
None,
|
||||||
|
]
|
||||||
|
] = None,
|
||||||
|
**kw: Any,
|
||||||
|
) -> None:
|
||||||
|
"""Configure a :class:`.MigrationContext` within this
|
||||||
|
:class:`.EnvironmentContext` which will provide database
|
||||||
|
connectivity and other configuration to a series of
|
||||||
|
migration scripts.
|
||||||
|
|
||||||
|
Many methods on :class:`.EnvironmentContext` require that
|
||||||
|
this method has been called in order to function, as they
|
||||||
|
ultimately need to have database access or at least access
|
||||||
|
to the dialect in use. Those which do are documented as such.
|
||||||
|
|
||||||
|
The important thing needed by :meth:`.configure` is a
|
||||||
|
means to determine what kind of database dialect is in use.
|
||||||
|
An actual connection to that database is needed only if
|
||||||
|
the :class:`.MigrationContext` is to be used in
|
||||||
|
"online" mode.
|
||||||
|
|
||||||
|
If the :meth:`.is_offline_mode` function returns ``True``,
|
||||||
|
then no connection is needed here. Otherwise, the
|
||||||
|
``connection`` parameter should be present as an
|
||||||
|
instance of :class:`sqlalchemy.engine.Connection`.
|
||||||
|
|
||||||
|
This function is typically called from the ``env.py``
|
||||||
|
script within a migration environment. It can be called
|
||||||
|
multiple times for an invocation. The most recent
|
||||||
|
:class:`~sqlalchemy.engine.Connection`
|
||||||
|
for which it was called is the one that will be operated upon
|
||||||
|
by the next call to :meth:`.run_migrations`.
|
||||||
|
|
||||||
|
General parameters:
|
||||||
|
|
||||||
|
:param connection: a :class:`~sqlalchemy.engine.Connection`
|
||||||
|
to use
|
||||||
|
for SQL execution in "online" mode. When present, is also
|
||||||
|
used to determine the type of dialect in use.
|
||||||
|
:param url: a string database url, or a
|
||||||
|
:class:`sqlalchemy.engine.url.URL` object.
|
||||||
|
The type of dialect to be used will be derived from this if
|
||||||
|
``connection`` is not passed.
|
||||||
|
:param dialect_name: string name of a dialect, such as
|
||||||
|
"postgresql", "mssql", etc.
|
||||||
|
The type of dialect to be used will be derived from this if
|
||||||
|
``connection`` and ``url`` are not passed.
|
||||||
|
:param dialect_opts: dictionary of options to be passed to dialect
|
||||||
|
constructor.
|
||||||
|
:param transactional_ddl: Force the usage of "transactional"
|
||||||
|
DDL on or off;
|
||||||
|
this otherwise defaults to whether or not the dialect in
|
||||||
|
use supports it.
|
||||||
|
:param transaction_per_migration: if True, nest each migration script
|
||||||
|
in a transaction rather than the full series of migrations to
|
||||||
|
run.
|
||||||
|
:param output_buffer: a file-like object that will be used
|
||||||
|
for textual output
|
||||||
|
when the ``--sql`` option is used to generate SQL scripts.
|
||||||
|
Defaults to
|
||||||
|
``sys.stdout`` if not passed here and also not present on
|
||||||
|
the :class:`.Config`
|
||||||
|
object. The value here overrides that of the :class:`.Config`
|
||||||
|
object.
|
||||||
|
:param output_encoding: when using ``--sql`` to generate SQL
|
||||||
|
scripts, apply this encoding to the string output.
|
||||||
|
:param literal_binds: when using ``--sql`` to generate SQL
|
||||||
|
scripts, pass through the ``literal_binds`` flag to the compiler
|
||||||
|
so that any literal values that would ordinarily be bound
|
||||||
|
parameters are converted to plain strings.
|
||||||
|
|
||||||
|
.. warning:: Dialects can typically only handle simple datatypes
|
||||||
|
like strings and numbers for auto-literal generation. Datatypes
|
||||||
|
like dates, intervals, and others may still require manual
|
||||||
|
formatting, typically using :meth:`.Operations.inline_literal`.
|
||||||
|
|
||||||
|
.. note:: the ``literal_binds`` flag is ignored on SQLAlchemy
|
||||||
|
versions prior to 0.8 where this feature is not supported.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:meth:`.Operations.inline_literal`
|
||||||
|
|
||||||
|
:param starting_rev: Override the "starting revision" argument
|
||||||
|
when using ``--sql`` mode.
|
||||||
|
:param tag: a string tag for usage by custom ``env.py`` scripts.
|
||||||
|
Set via the ``--tag`` option, can be overridden here.
|
||||||
|
:param template_args: dictionary of template arguments which
|
||||||
|
will be added to the template argument environment when
|
||||||
|
running the "revision" command. Note that the script environment
|
||||||
|
is only run within the "revision" command if the --autogenerate
|
||||||
|
option is used, or if the option "revision_environment=true"
|
||||||
|
is present in the alembic.ini file.
|
||||||
|
|
||||||
|
:param version_table: The name of the Alembic version table.
|
||||||
|
The default is ``'alembic_version'``.
|
||||||
|
:param version_table_schema: Optional schema to place version
|
||||||
|
table within.
|
||||||
|
:param version_table_pk: boolean, whether the Alembic version table
|
||||||
|
should use a primary key constraint for the "value" column; this
|
||||||
|
only takes effect when the table is first created.
|
||||||
|
Defaults to True; setting to False should not be necessary and is
|
||||||
|
here for backwards compatibility reasons.
|
||||||
|
:param on_version_apply: a callable or collection of callables to be
|
||||||
|
run for each migration step.
|
||||||
|
The callables will be run in the order they are given, once for
|
||||||
|
each migration step, after the respective operation has been
|
||||||
|
applied but before its transaction is finalized.
|
||||||
|
Each callable accepts no positional arguments and the following
|
||||||
|
keyword arguments:
|
||||||
|
|
||||||
|
* ``ctx``: the :class:`.MigrationContext` running the migration,
|
||||||
|
* ``step``: a :class:`.MigrationInfo` representing the
|
||||||
|
step currently being applied,
|
||||||
|
* ``heads``: a collection of version strings representing the
|
||||||
|
current heads,
|
||||||
|
* ``run_args``: the ``**kwargs`` passed to :meth:`.run_migrations`.
|
||||||
|
|
||||||
|
Parameters specific to the autogenerate feature, when
|
||||||
|
``alembic revision`` is run with the ``--autogenerate`` feature:
|
||||||
|
|
||||||
|
:param target_metadata: a :class:`sqlalchemy.schema.MetaData`
|
||||||
|
object, or a sequence of :class:`~sqlalchemy.schema.MetaData`
|
||||||
|
objects, that will be consulted during autogeneration.
|
||||||
|
The tables present in each :class:`~sqlalchemy.schema.MetaData`
|
||||||
|
will be compared against
|
||||||
|
what is locally available on the target
|
||||||
|
:class:`~sqlalchemy.engine.Connection`
|
||||||
|
to produce candidate upgrade/downgrade operations.
|
||||||
|
:param compare_type: Indicates type comparison behavior during
|
||||||
|
an autogenerate
|
||||||
|
operation. Defaults to ``True`` turning on type comparison, which
|
||||||
|
has good accuracy on most backends. See :ref:`compare_types`
|
||||||
|
for an example as well as information on other type
|
||||||
|
comparison options. Set to ``False`` which disables type
|
||||||
|
comparison. A callable can also be passed to provide custom type
|
||||||
|
comparison, see :ref:`compare_types` for additional details.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.12.0 The default value of
|
||||||
|
:paramref:`.EnvironmentContext.configure.compare_type` has been
|
||||||
|
changed to ``True``.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`compare_types`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.compare_server_default`
|
||||||
|
|
||||||
|
:param compare_server_default: Indicates server default comparison
|
||||||
|
behavior during
|
||||||
|
an autogenerate operation. Defaults to ``False`` which disables
|
||||||
|
server default
|
||||||
|
comparison. Set to ``True`` to turn on server default comparison,
|
||||||
|
which has
|
||||||
|
varied accuracy depending on backend.
|
||||||
|
|
||||||
|
To customize server default comparison behavior, a callable may
|
||||||
|
be specified
|
||||||
|
which can filter server default comparisons during an
|
||||||
|
autogenerate operation.
|
||||||
|
defaults during an autogenerate operation. The format of this
|
||||||
|
callable is::
|
||||||
|
|
||||||
|
def my_compare_server_default(context, inspected_column,
|
||||||
|
metadata_column, inspected_default, metadata_default,
|
||||||
|
rendered_metadata_default):
|
||||||
|
# return True if the defaults are different,
|
||||||
|
# False if not, or None to allow the default implementation
|
||||||
|
# to compare these defaults
|
||||||
|
return None
|
||||||
|
|
||||||
|
context.configure(
|
||||||
|
# ...
|
||||||
|
compare_server_default = my_compare_server_default
|
||||||
|
)
|
||||||
|
|
||||||
|
``inspected_column`` is a dictionary structure as returned by
|
||||||
|
:meth:`sqlalchemy.engine.reflection.Inspector.get_columns`, whereas
|
||||||
|
``metadata_column`` is a :class:`sqlalchemy.schema.Column` from
|
||||||
|
the local model environment.
|
||||||
|
|
||||||
|
A return value of ``None`` indicates to allow default server default
|
||||||
|
comparison
|
||||||
|
to proceed. Note that some backends such as Postgresql actually
|
||||||
|
execute
|
||||||
|
the two defaults on the database side to compare for equivalence.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.compare_type`
|
||||||
|
|
||||||
|
:param include_name: A callable function which is given
|
||||||
|
the chance to return ``True`` or ``False`` for any database reflected
|
||||||
|
object based on its name, including database schema names when
|
||||||
|
the :paramref:`.EnvironmentContext.configure.include_schemas` flag
|
||||||
|
is set to ``True``.
|
||||||
|
|
||||||
|
The function accepts the following positional arguments:
|
||||||
|
|
||||||
|
* ``name``: the name of the object, such as schema name or table name.
|
||||||
|
Will be ``None`` when indicating the default schema name of the
|
||||||
|
database connection.
|
||||||
|
* ``type``: a string describing the type of object; currently
|
||||||
|
``"schema"``, ``"table"``, ``"column"``, ``"index"``,
|
||||||
|
``"unique_constraint"``, or ``"foreign_key_constraint"``
|
||||||
|
* ``parent_names``: a dictionary of "parent" object names, that are
|
||||||
|
relative to the name being given. Keys in this dictionary may
|
||||||
|
include: ``"schema_name"``, ``"table_name"`` or
|
||||||
|
``"schema_qualified_table_name"``.
|
||||||
|
|
||||||
|
E.g.::
|
||||||
|
|
||||||
|
def include_name(name, type_, parent_names):
|
||||||
|
if type_ == "schema":
|
||||||
|
return name in ["schema_one", "schema_two"]
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
context.configure(
|
||||||
|
# ...
|
||||||
|
include_schemas = True,
|
||||||
|
include_name = include_name
|
||||||
|
)
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogenerate_include_hooks`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_object`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_schemas`
|
||||||
|
|
||||||
|
|
||||||
|
:param include_object: A callable function which is given
|
||||||
|
the chance to return ``True`` or ``False`` for any object,
|
||||||
|
indicating if the given object should be considered in the
|
||||||
|
autogenerate sweep.
|
||||||
|
|
||||||
|
The function accepts the following positional arguments:
|
||||||
|
|
||||||
|
* ``object``: a :class:`~sqlalchemy.schema.SchemaItem` object such
|
||||||
|
as a :class:`~sqlalchemy.schema.Table`,
|
||||||
|
:class:`~sqlalchemy.schema.Column`,
|
||||||
|
:class:`~sqlalchemy.schema.Index`
|
||||||
|
:class:`~sqlalchemy.schema.UniqueConstraint`,
|
||||||
|
or :class:`~sqlalchemy.schema.ForeignKeyConstraint` object
|
||||||
|
* ``name``: the name of the object. This is typically available
|
||||||
|
via ``object.name``.
|
||||||
|
* ``type``: a string describing the type of object; currently
|
||||||
|
``"table"``, ``"column"``, ``"index"``, ``"unique_constraint"``,
|
||||||
|
or ``"foreign_key_constraint"``
|
||||||
|
* ``reflected``: ``True`` if the given object was produced based on
|
||||||
|
table reflection, ``False`` if it's from a local :class:`.MetaData`
|
||||||
|
object.
|
||||||
|
* ``compare_to``: the object being compared against, if available,
|
||||||
|
else ``None``.
|
||||||
|
|
||||||
|
E.g.::
|
||||||
|
|
||||||
|
def include_object(object, name, type_, reflected, compare_to):
|
||||||
|
if (type_ == "column" and
|
||||||
|
not reflected and
|
||||||
|
object.info.get("skip_autogenerate", False)):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
context.configure(
|
||||||
|
# ...
|
||||||
|
include_object = include_object
|
||||||
|
)
|
||||||
|
|
||||||
|
For the use case of omitting specific schemas from a target database
|
||||||
|
when :paramref:`.EnvironmentContext.configure.include_schemas` is
|
||||||
|
set to ``True``, the :attr:`~sqlalchemy.schema.Table.schema`
|
||||||
|
attribute can be checked for each :class:`~sqlalchemy.schema.Table`
|
||||||
|
object passed to the hook, however it is much more efficient
|
||||||
|
to filter on schemas before reflection of objects takes place
|
||||||
|
using the :paramref:`.EnvironmentContext.configure.include_name`
|
||||||
|
hook.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogenerate_include_hooks`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_name`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_schemas`
|
||||||
|
|
||||||
|
:param render_as_batch: if True, commands which alter elements
|
||||||
|
within a table will be placed under a ``with batch_alter_table():``
|
||||||
|
directive, so that batch migrations will take place.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`batch_migrations`
|
||||||
|
|
||||||
|
:param include_schemas: If True, autogenerate will scan across
|
||||||
|
all schemas located by the SQLAlchemy
|
||||||
|
:meth:`~sqlalchemy.engine.reflection.Inspector.get_schema_names`
|
||||||
|
method, and include all differences in tables found across all
|
||||||
|
those schemas. When using this option, you may want to also
|
||||||
|
use the :paramref:`.EnvironmentContext.configure.include_name`
|
||||||
|
parameter to specify a callable which
|
||||||
|
can filter the tables/schemas that get included.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogenerate_include_hooks`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_name`
|
||||||
|
|
||||||
|
:paramref:`.EnvironmentContext.configure.include_object`
|
||||||
|
|
||||||
|
:param render_item: Callable that can be used to override how
|
||||||
|
any schema item, i.e. column, constraint, type,
|
||||||
|
etc., is rendered for autogenerate. The callable receives a
|
||||||
|
string describing the type of object, the object, and
|
||||||
|
the autogen context. If it returns False, the
|
||||||
|
default rendering method will be used. If it returns None,
|
||||||
|
the item will not be rendered in the context of a Table
|
||||||
|
construct, that is, can be used to skip columns or constraints
|
||||||
|
within op.create_table()::
|
||||||
|
|
||||||
|
def my_render_column(type_, col, autogen_context):
|
||||||
|
if type_ == "column" and isinstance(col, MySpecialCol):
|
||||||
|
return repr(col)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
context.configure(
|
||||||
|
# ...
|
||||||
|
render_item = my_render_column
|
||||||
|
)
|
||||||
|
|
||||||
|
Available values for the type string include: ``"column"``,
|
||||||
|
``"primary_key"``, ``"foreign_key"``, ``"unique"``, ``"check"``,
|
||||||
|
``"type"``, ``"server_default"``.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogen_render_types`
|
||||||
|
|
||||||
|
:param upgrade_token: When autogenerate completes, the text of the
|
||||||
|
candidate upgrade operations will be present in this template
|
||||||
|
variable when ``script.py.mako`` is rendered. Defaults to
|
||||||
|
``upgrades``.
|
||||||
|
:param downgrade_token: When autogenerate completes, the text of the
|
||||||
|
candidate downgrade operations will be present in this
|
||||||
|
template variable when ``script.py.mako`` is rendered. Defaults to
|
||||||
|
``downgrades``.
|
||||||
|
|
||||||
|
:param alembic_module_prefix: When autogenerate refers to Alembic
|
||||||
|
:mod:`alembic.operations` constructs, this prefix will be used
|
||||||
|
(i.e. ``op.create_table``) Defaults to "``op.``".
|
||||||
|
Can be ``None`` to indicate no prefix.
|
||||||
|
|
||||||
|
:param sqlalchemy_module_prefix: When autogenerate refers to
|
||||||
|
SQLAlchemy
|
||||||
|
:class:`~sqlalchemy.schema.Column` or type classes, this prefix
|
||||||
|
will be used
|
||||||
|
(i.e. ``sa.Column("somename", sa.Integer)``) Defaults to "``sa.``".
|
||||||
|
Can be ``None`` to indicate no prefix.
|
||||||
|
Note that when dialect-specific types are rendered, autogenerate
|
||||||
|
will render them using the dialect module name, i.e. ``mssql.BIT()``,
|
||||||
|
``postgresql.UUID()``.
|
||||||
|
|
||||||
|
:param user_module_prefix: When autogenerate refers to a SQLAlchemy
|
||||||
|
type (e.g. :class:`.TypeEngine`) where the module name is not
|
||||||
|
under the ``sqlalchemy`` namespace, this prefix will be used
|
||||||
|
within autogenerate. If left at its default of
|
||||||
|
``None``, the ``__module__`` attribute of the type is used to
|
||||||
|
render the import module. It's a good practice to set this
|
||||||
|
and to have all custom types be available from a fixed module space,
|
||||||
|
in order to future-proof migration files against reorganizations
|
||||||
|
in modules.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`autogen_module_prefix`
|
||||||
|
|
||||||
|
:param process_revision_directives: a callable function that will
|
||||||
|
be passed a structure representing the end result of an autogenerate
|
||||||
|
or plain "revision" operation, which can be manipulated to affect
|
||||||
|
how the ``alembic revision`` command ultimately outputs new
|
||||||
|
revision scripts. The structure of the callable is::
|
||||||
|
|
||||||
|
def process_revision_directives(context, revision, directives):
|
||||||
|
pass
|
||||||
|
|
||||||
|
The ``directives`` parameter is a Python list containing
|
||||||
|
a single :class:`.MigrationScript` directive, which represents
|
||||||
|
the revision file to be generated. This list as well as its
|
||||||
|
contents may be freely modified to produce any set of commands.
|
||||||
|
The section :ref:`customizing_revision` shows an example of
|
||||||
|
doing this. The ``context`` parameter is the
|
||||||
|
:class:`.MigrationContext` in use,
|
||||||
|
and ``revision`` is a tuple of revision identifiers representing the
|
||||||
|
current revision of the database.
|
||||||
|
|
||||||
|
The callable is invoked at all times when the ``--autogenerate``
|
||||||
|
option is passed to ``alembic revision``. If ``--autogenerate``
|
||||||
|
is not passed, the callable is invoked only if the
|
||||||
|
``revision_environment`` variable is set to True in the Alembic
|
||||||
|
configuration, in which case the given ``directives`` collection
|
||||||
|
will contain empty :class:`.UpgradeOps` and :class:`.DowngradeOps`
|
||||||
|
collections for ``.upgrade_ops`` and ``.downgrade_ops``. The
|
||||||
|
``--autogenerate`` option itself can be inferred by inspecting
|
||||||
|
``context.config.cmd_opts.autogenerate``.
|
||||||
|
|
||||||
|
The callable function may optionally be an instance of
|
||||||
|
a :class:`.Rewriter` object. This is a helper object that
|
||||||
|
assists in the production of autogenerate-stream rewriter functions.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:ref:`customizing_revision`
|
||||||
|
|
||||||
|
:ref:`autogen_rewriter`
|
||||||
|
|
||||||
|
:paramref:`.command.revision.process_revision_directives`
|
||||||
|
|
||||||
|
Parameters specific to individual backends:
|
||||||
|
|
||||||
|
:param mssql_batch_separator: The "batch separator" which will
|
||||||
|
be placed between each statement when generating offline SQL Server
|
||||||
|
migrations. Defaults to ``GO``. Note this is in addition to the
|
||||||
|
customary semicolon ``;`` at the end of each statement; SQL Server
|
||||||
|
considers the "batch separator" to denote the end of an
|
||||||
|
individual statement execution, and cannot group certain
|
||||||
|
dependent operations in one step.
|
||||||
|
:param oracle_batch_separator: The "batch separator" which will
|
||||||
|
be placed between each statement when generating offline
|
||||||
|
Oracle migrations. Defaults to ``/``. Oracle doesn't add a
|
||||||
|
semicolon between statements like most other backends.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
sql: Union[Executable, str],
|
||||||
|
execution_options: Optional[Dict[str, Any]] = None,
|
||||||
|
) -> None:
|
||||||
|
"""Execute the given SQL using the current change context.
|
||||||
|
|
||||||
|
The behavior of :meth:`.execute` is the same
|
||||||
|
as that of :meth:`.Operations.execute`. Please see that
|
||||||
|
function's documentation for full detail including
|
||||||
|
caveats and limitations.
|
||||||
|
|
||||||
|
This function requires that a :class:`.MigrationContext` has
|
||||||
|
first been made available via :meth:`.configure`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_bind() -> Connection:
|
||||||
|
"""Return the current 'bind'.
|
||||||
|
|
||||||
|
In "online" mode, this is the
|
||||||
|
:class:`sqlalchemy.engine.Connection` currently being used
|
||||||
|
to emit SQL to the database.
|
||||||
|
|
||||||
|
This function requires that a :class:`.MigrationContext`
|
||||||
|
has first been made available via :meth:`.configure`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_context() -> MigrationContext:
|
||||||
|
"""Return the current :class:`.MigrationContext` object.
|
||||||
|
|
||||||
|
If :meth:`.EnvironmentContext.configure` has not been
|
||||||
|
called yet, raises an exception.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_head_revision() -> Union[str, Tuple[str, ...], None]:
|
||||||
|
"""Return the hex identifier of the 'head' script revision.
|
||||||
|
|
||||||
|
If the script directory has multiple heads, this
|
||||||
|
method raises a :class:`.CommandError`;
|
||||||
|
:meth:`.EnvironmentContext.get_head_revisions` should be preferred.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
.. seealso:: :meth:`.EnvironmentContext.get_head_revisions`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_head_revisions() -> Union[str, Tuple[str, ...], None]:
|
||||||
|
"""Return the hex identifier of the 'heads' script revision(s).
|
||||||
|
|
||||||
|
This returns a tuple containing the version number of all
|
||||||
|
heads in the script directory.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_revision_argument() -> Union[str, Tuple[str, ...], None]:
|
||||||
|
"""Get the 'destination' revision argument.
|
||||||
|
|
||||||
|
This is typically the argument passed to the
|
||||||
|
``upgrade`` or ``downgrade`` command.
|
||||||
|
|
||||||
|
If it was specified as ``head``, the actual
|
||||||
|
version number is returned; if specified
|
||||||
|
as ``base``, ``None`` is returned.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_starting_revision_argument() -> Union[str, Tuple[str, ...], None]:
|
||||||
|
"""Return the 'starting revision' argument,
|
||||||
|
if the revision was passed using ``start:end``.
|
||||||
|
|
||||||
|
This is only meaningful in "offline" mode.
|
||||||
|
Returns ``None`` if no value is available
|
||||||
|
or was configured.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_tag_argument() -> Optional[str]:
|
||||||
|
"""Return the value passed for the ``--tag`` argument, if any.
|
||||||
|
|
||||||
|
The ``--tag`` argument is not used directly by Alembic,
|
||||||
|
but is available for custom ``env.py`` configurations that
|
||||||
|
wish to use it; particularly for offline generation scripts
|
||||||
|
that wish to generate tagged filenames.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:meth:`.EnvironmentContext.get_x_argument` - a newer and more
|
||||||
|
open ended system of extending ``env.py`` scripts via the command
|
||||||
|
line.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
@overload
|
||||||
|
def get_x_argument(as_dictionary: Literal[False]) -> List[str]: ...
|
||||||
|
@overload
|
||||||
|
def get_x_argument(as_dictionary: Literal[True]) -> Dict[str, str]: ...
|
||||||
|
@overload
|
||||||
|
def get_x_argument(
|
||||||
|
as_dictionary: bool = ...,
|
||||||
|
) -> Union[List[str], Dict[str, str]]:
|
||||||
|
"""Return the value(s) passed for the ``-x`` argument, if any.
|
||||||
|
|
||||||
|
The ``-x`` argument is an open ended flag that allows any user-defined
|
||||||
|
value or values to be passed on the command line, then available
|
||||||
|
here for consumption by a custom ``env.py`` script.
|
||||||
|
|
||||||
|
The return value is a list, returned directly from the ``argparse``
|
||||||
|
structure. If ``as_dictionary=True`` is passed, the ``x`` arguments
|
||||||
|
are parsed using ``key=value`` format into a dictionary that is
|
||||||
|
then returned. If there is no ``=`` in the argument, value is an empty
|
||||||
|
string.
|
||||||
|
|
||||||
|
.. versionchanged:: 1.13.1 Support ``as_dictionary=True`` when
|
||||||
|
arguments are passed without the ``=`` symbol.
|
||||||
|
|
||||||
|
For example, to support passing a database URL on the command line,
|
||||||
|
the standard ``env.py`` script can be modified like this::
|
||||||
|
|
||||||
|
cmd_line_url = context.get_x_argument(
|
||||||
|
as_dictionary=True).get('dbname')
|
||||||
|
if cmd_line_url:
|
||||||
|
engine = create_engine(cmd_line_url)
|
||||||
|
else:
|
||||||
|
engine = engine_from_config(
|
||||||
|
config.get_section(config.config_ini_section),
|
||||||
|
prefix='sqlalchemy.',
|
||||||
|
poolclass=pool.NullPool)
|
||||||
|
|
||||||
|
This then takes effect by running the ``alembic`` script as::
|
||||||
|
|
||||||
|
alembic -x dbname=postgresql://user:pass@host/dbname upgrade head
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
.. seealso::
|
||||||
|
|
||||||
|
:meth:`.EnvironmentContext.get_tag_argument`
|
||||||
|
|
||||||
|
:attr:`.Config.cmd_opts`
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def is_offline_mode() -> bool:
|
||||||
|
"""Return True if the current migrations environment
|
||||||
|
is running in "offline mode".
|
||||||
|
|
||||||
|
This is ``True`` or ``False`` depending
|
||||||
|
on the ``--sql`` flag passed.
|
||||||
|
|
||||||
|
This function does not require that the :class:`.MigrationContext`
|
||||||
|
has been configured.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def is_transactional_ddl() -> bool:
|
||||||
|
"""Return True if the context is configured to expect a
|
||||||
|
transactional DDL capable backend.
|
||||||
|
|
||||||
|
This defaults to the type of database in use, and
|
||||||
|
can be overridden by the ``transactional_ddl`` argument
|
||||||
|
to :meth:`.configure`
|
||||||
|
|
||||||
|
This function requires that a :class:`.MigrationContext`
|
||||||
|
has first been made available via :meth:`.configure`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def run_migrations(**kw: Any) -> None:
|
||||||
|
"""Run migrations as determined by the current command line
|
||||||
|
configuration
|
||||||
|
as well as versioning information present (or not) in the current
|
||||||
|
database connection (if one is present).
|
||||||
|
|
||||||
|
The function accepts optional ``**kw`` arguments. If these are
|
||||||
|
passed, they are sent directly to the ``upgrade()`` and
|
||||||
|
``downgrade()``
|
||||||
|
functions within each target revision file. By modifying the
|
||||||
|
``script.py.mako`` file so that the ``upgrade()`` and ``downgrade()``
|
||||||
|
functions accept arguments, parameters can be passed here so that
|
||||||
|
contextual information, usually information to identify a particular
|
||||||
|
database in use, can be passed from a custom ``env.py`` script
|
||||||
|
to the migration functions.
|
||||||
|
|
||||||
|
This function requires that a :class:`.MigrationContext` has
|
||||||
|
first been made available via :meth:`.configure`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
script: ScriptDirectory
|
||||||
|
|
||||||
|
def static_output(text: str) -> None:
|
||||||
|
"""Emit text directly to the "offline" SQL stream.
|
||||||
|
|
||||||
|
Typically this is for emitting comments that
|
||||||
|
start with --. The statement is not treated
|
||||||
|
as a SQL execution, no ; or batch separator
|
||||||
|
is added, etc.
|
||||||
|
|
||||||
|
"""
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
from . import mssql
|
||||||
|
from . import mysql
|
||||||
|
from . import oracle
|
||||||
|
from . import postgresql
|
||||||
|
from . import sqlite
|
||||||
|
from .impl import DefaultImpl as DefaultImpl
|
||||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,329 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
||||||
|
# mypy: no-warn-return-any, allow-any-generics
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any
|
||||||
|
from typing import ClassVar
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Generic
|
||||||
|
from typing import NamedTuple
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import Tuple
|
||||||
|
from typing import Type
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import TypeVar
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy.sql.schema import Constraint
|
||||||
|
from sqlalchemy.sql.schema import ForeignKeyConstraint
|
||||||
|
from sqlalchemy.sql.schema import Index
|
||||||
|
from sqlalchemy.sql.schema import UniqueConstraint
|
||||||
|
from typing_extensions import TypeGuard
|
||||||
|
|
||||||
|
from .. import util
|
||||||
|
from ..util import sqla_compat
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
from alembic.autogenerate.api import AutogenContext
|
||||||
|
from alembic.ddl.impl import DefaultImpl
|
||||||
|
|
||||||
|
CompareConstraintType = Union[Constraint, Index]
|
||||||
|
|
||||||
|
_C = TypeVar("_C", bound=CompareConstraintType)
|
||||||
|
|
||||||
|
_clsreg: Dict[str, Type[_constraint_sig]] = {}
|
||||||
|
|
||||||
|
|
||||||
|
class ComparisonResult(NamedTuple):
|
||||||
|
status: Literal["equal", "different", "skip"]
|
||||||
|
message: str
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_equal(self) -> bool:
|
||||||
|
return self.status == "equal"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_different(self) -> bool:
|
||||||
|
return self.status == "different"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_skip(self) -> bool:
|
||||||
|
return self.status == "skip"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def Equal(cls) -> ComparisonResult:
|
||||||
|
"""the constraints are equal."""
|
||||||
|
return cls("equal", "The two constraints are equal")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def Different(cls, reason: Union[str, Sequence[str]]) -> ComparisonResult:
|
||||||
|
"""the constraints are different for the provided reason(s)."""
|
||||||
|
return cls("different", ", ".join(util.to_list(reason)))
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def Skip(cls, reason: Union[str, Sequence[str]]) -> ComparisonResult:
|
||||||
|
"""the constraint cannot be compared for the provided reason(s).
|
||||||
|
|
||||||
|
The message is logged, but the constraints will be otherwise
|
||||||
|
considered equal, meaning that no migration command will be
|
||||||
|
generated.
|
||||||
|
"""
|
||||||
|
return cls("skip", ", ".join(util.to_list(reason)))
|
||||||
|
|
||||||
|
|
||||||
|
class _constraint_sig(Generic[_C]):
|
||||||
|
const: _C
|
||||||
|
|
||||||
|
_sig: Tuple[Any, ...]
|
||||||
|
name: Optional[sqla_compat._ConstraintNameDefined]
|
||||||
|
|
||||||
|
impl: DefaultImpl
|
||||||
|
|
||||||
|
_is_index: ClassVar[bool] = False
|
||||||
|
_is_fk: ClassVar[bool] = False
|
||||||
|
_is_uq: ClassVar[bool] = False
|
||||||
|
|
||||||
|
_is_metadata: bool
|
||||||
|
|
||||||
|
def __init_subclass__(cls) -> None:
|
||||||
|
cls._register()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _register(cls):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, is_metadata: bool, impl: DefaultImpl, const: _C
|
||||||
|
) -> None:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def compare_to_reflected(
|
||||||
|
self, other: _constraint_sig[Any]
|
||||||
|
) -> ComparisonResult:
|
||||||
|
assert self.impl is other.impl
|
||||||
|
assert self._is_metadata
|
||||||
|
assert not other._is_metadata
|
||||||
|
|
||||||
|
return self._compare_to_reflected(other)
|
||||||
|
|
||||||
|
def _compare_to_reflected(
|
||||||
|
self, other: _constraint_sig[_C]
|
||||||
|
) -> ComparisonResult:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_constraint(
|
||||||
|
cls, is_metadata: bool, impl: DefaultImpl, constraint: _C
|
||||||
|
) -> _constraint_sig[_C]:
|
||||||
|
# these could be cached by constraint/impl, however, if the
|
||||||
|
# constraint is modified in place, then the sig is wrong. the mysql
|
||||||
|
# impl currently does this, and if we fixed that we can't be sure
|
||||||
|
# someone else might do it too, so play it safe.
|
||||||
|
sig = _clsreg[constraint.__visit_name__](is_metadata, impl, constraint)
|
||||||
|
return sig
|
||||||
|
|
||||||
|
def md_name_to_sql_name(self, context: AutogenContext) -> Optional[str]:
|
||||||
|
return sqla_compat._get_constraint_final_name(
|
||||||
|
self.const, context.dialect
|
||||||
|
)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def is_named(self):
|
||||||
|
return sqla_compat._constraint_is_named(self.const, self.impl.dialect)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def unnamed(self) -> Tuple[Any, ...]:
|
||||||
|
return self._sig
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def unnamed_no_options(self) -> Tuple[Any, ...]:
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def _full_sig(self) -> Tuple[Any, ...]:
|
||||||
|
return (self.name,) + self.unnamed
|
||||||
|
|
||||||
|
def __eq__(self, other) -> bool:
|
||||||
|
return self._full_sig == other._full_sig
|
||||||
|
|
||||||
|
def __ne__(self, other) -> bool:
|
||||||
|
return self._full_sig != other._full_sig
|
||||||
|
|
||||||
|
def __hash__(self) -> int:
|
||||||
|
return hash(self._full_sig)
|
||||||
|
|
||||||
|
|
||||||
|
class _uq_constraint_sig(_constraint_sig[UniqueConstraint]):
|
||||||
|
_is_uq = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _register(cls) -> None:
|
||||||
|
_clsreg["unique_constraint"] = cls
|
||||||
|
|
||||||
|
is_unique = True
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
is_metadata: bool,
|
||||||
|
impl: DefaultImpl,
|
||||||
|
const: UniqueConstraint,
|
||||||
|
) -> None:
|
||||||
|
self.impl = impl
|
||||||
|
self.const = const
|
||||||
|
self.name = sqla_compat.constraint_name_or_none(const.name)
|
||||||
|
self._sig = tuple(sorted([col.name for col in const.columns]))
|
||||||
|
self._is_metadata = is_metadata
|
||||||
|
|
||||||
|
@property
|
||||||
|
def column_names(self) -> Tuple[str, ...]:
|
||||||
|
return tuple([col.name for col in self.const.columns])
|
||||||
|
|
||||||
|
def _compare_to_reflected(
|
||||||
|
self, other: _constraint_sig[_C]
|
||||||
|
) -> ComparisonResult:
|
||||||
|
assert self._is_metadata
|
||||||
|
metadata_obj = self
|
||||||
|
conn_obj = other
|
||||||
|
|
||||||
|
assert is_uq_sig(conn_obj)
|
||||||
|
return self.impl.compare_unique_constraint(
|
||||||
|
metadata_obj.const, conn_obj.const
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class _ix_constraint_sig(_constraint_sig[Index]):
|
||||||
|
_is_index = True
|
||||||
|
|
||||||
|
name: sqla_compat._ConstraintName
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _register(cls) -> None:
|
||||||
|
_clsreg["index"] = cls
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, is_metadata: bool, impl: DefaultImpl, const: Index
|
||||||
|
) -> None:
|
||||||
|
self.impl = impl
|
||||||
|
self.const = const
|
||||||
|
self.name = const.name
|
||||||
|
self.is_unique = bool(const.unique)
|
||||||
|
self._is_metadata = is_metadata
|
||||||
|
|
||||||
|
def _compare_to_reflected(
|
||||||
|
self, other: _constraint_sig[_C]
|
||||||
|
) -> ComparisonResult:
|
||||||
|
assert self._is_metadata
|
||||||
|
metadata_obj = self
|
||||||
|
conn_obj = other
|
||||||
|
|
||||||
|
assert is_index_sig(conn_obj)
|
||||||
|
return self.impl.compare_indexes(metadata_obj.const, conn_obj.const)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def has_expressions(self):
|
||||||
|
return sqla_compat.is_expression_index(self.const)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def column_names(self) -> Tuple[str, ...]:
|
||||||
|
return tuple([col.name for col in self.const.columns])
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def column_names_optional(self) -> Tuple[Optional[str], ...]:
|
||||||
|
return tuple(
|
||||||
|
[getattr(col, "name", None) for col in self.const.expressions]
|
||||||
|
)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def is_named(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def unnamed(self):
|
||||||
|
return (self.is_unique,) + self.column_names_optional
|
||||||
|
|
||||||
|
|
||||||
|
class _fk_constraint_sig(_constraint_sig[ForeignKeyConstraint]):
|
||||||
|
_is_fk = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _register(cls) -> None:
|
||||||
|
_clsreg["foreign_key_constraint"] = cls
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
is_metadata: bool,
|
||||||
|
impl: DefaultImpl,
|
||||||
|
const: ForeignKeyConstraint,
|
||||||
|
) -> None:
|
||||||
|
self._is_metadata = is_metadata
|
||||||
|
|
||||||
|
self.impl = impl
|
||||||
|
self.const = const
|
||||||
|
|
||||||
|
self.name = sqla_compat.constraint_name_or_none(const.name)
|
||||||
|
|
||||||
|
(
|
||||||
|
self.source_schema,
|
||||||
|
self.source_table,
|
||||||
|
self.source_columns,
|
||||||
|
self.target_schema,
|
||||||
|
self.target_table,
|
||||||
|
self.target_columns,
|
||||||
|
onupdate,
|
||||||
|
ondelete,
|
||||||
|
deferrable,
|
||||||
|
initially,
|
||||||
|
) = sqla_compat._fk_spec(const)
|
||||||
|
|
||||||
|
self._sig: Tuple[Any, ...] = (
|
||||||
|
self.source_schema,
|
||||||
|
self.source_table,
|
||||||
|
tuple(self.source_columns),
|
||||||
|
self.target_schema,
|
||||||
|
self.target_table,
|
||||||
|
tuple(self.target_columns),
|
||||||
|
) + (
|
||||||
|
(
|
||||||
|
(None if onupdate.lower() == "no action" else onupdate.lower())
|
||||||
|
if onupdate
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
(
|
||||||
|
(None if ondelete.lower() == "no action" else ondelete.lower())
|
||||||
|
if ondelete
|
||||||
|
else None
|
||||||
|
),
|
||||||
|
# convert initially + deferrable into one three-state value
|
||||||
|
(
|
||||||
|
"initially_deferrable"
|
||||||
|
if initially and initially.lower() == "deferred"
|
||||||
|
else "deferrable" if deferrable else "not deferrable"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
@util.memoized_property
|
||||||
|
def unnamed_no_options(self):
|
||||||
|
return (
|
||||||
|
self.source_schema,
|
||||||
|
self.source_table,
|
||||||
|
tuple(self.source_columns),
|
||||||
|
self.target_schema,
|
||||||
|
self.target_table,
|
||||||
|
tuple(self.target_columns),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_index_sig(sig: _constraint_sig) -> TypeGuard[_ix_constraint_sig]:
|
||||||
|
return sig._is_index
|
||||||
|
|
||||||
|
|
||||||
|
def is_uq_sig(sig: _constraint_sig) -> TypeGuard[_uq_constraint_sig]:
|
||||||
|
return sig._is_uq
|
||||||
|
|
||||||
|
|
||||||
|
def is_fk_sig(sig: _constraint_sig) -> TypeGuard[_fk_constraint_sig]:
|
||||||
|
return sig._is_fk
|
||||||
@@ -0,0 +1,336 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
||||||
|
# mypy: no-warn-return-any, allow-any-generics
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import functools
|
||||||
|
from typing import Optional
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy import exc
|
||||||
|
from sqlalchemy import Integer
|
||||||
|
from sqlalchemy import types as sqltypes
|
||||||
|
from sqlalchemy.ext.compiler import compiles
|
||||||
|
from sqlalchemy.schema import Column
|
||||||
|
from sqlalchemy.schema import DDLElement
|
||||||
|
from sqlalchemy.sql.elements import quoted_name
|
||||||
|
|
||||||
|
from ..util.sqla_compat import _columns_for_constraint # noqa
|
||||||
|
from ..util.sqla_compat import _find_columns # noqa
|
||||||
|
from ..util.sqla_compat import _fk_spec # noqa
|
||||||
|
from ..util.sqla_compat import _is_type_bound # noqa
|
||||||
|
from ..util.sqla_compat import _table_for_constraint # noqa
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
from sqlalchemy.sql.compiler import Compiled
|
||||||
|
from sqlalchemy.sql.compiler import DDLCompiler
|
||||||
|
from sqlalchemy.sql.elements import TextClause
|
||||||
|
from sqlalchemy.sql.functions import Function
|
||||||
|
from sqlalchemy.sql.schema import FetchedValue
|
||||||
|
from sqlalchemy.sql.type_api import TypeEngine
|
||||||
|
|
||||||
|
from .impl import DefaultImpl
|
||||||
|
from ..util.sqla_compat import Computed
|
||||||
|
from ..util.sqla_compat import Identity
|
||||||
|
|
||||||
|
_ServerDefault = Union["TextClause", "FetchedValue", "Function[Any]", str]
|
||||||
|
|
||||||
|
|
||||||
|
class AlterTable(DDLElement):
|
||||||
|
"""Represent an ALTER TABLE statement.
|
||||||
|
|
||||||
|
Only the string name and optional schema name of the table
|
||||||
|
is required, not a full Table object.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
schema: Optional[Union[quoted_name, str]] = None,
|
||||||
|
) -> None:
|
||||||
|
self.table_name = table_name
|
||||||
|
self.schema = schema
|
||||||
|
|
||||||
|
|
||||||
|
class RenameTable(AlterTable):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
old_table_name: str,
|
||||||
|
new_table_name: Union[quoted_name, str],
|
||||||
|
schema: Optional[Union[quoted_name, str]] = None,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(old_table_name, schema=schema)
|
||||||
|
self.new_table_name = new_table_name
|
||||||
|
|
||||||
|
|
||||||
|
class AlterColumn(AlterTable):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column_name: str,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
existing_type: Optional[TypeEngine] = None,
|
||||||
|
existing_nullable: Optional[bool] = None,
|
||||||
|
existing_server_default: Optional[_ServerDefault] = None,
|
||||||
|
existing_comment: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, schema=schema)
|
||||||
|
self.column_name = column_name
|
||||||
|
self.existing_type = (
|
||||||
|
sqltypes.to_instance(existing_type)
|
||||||
|
if existing_type is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
self.existing_nullable = existing_nullable
|
||||||
|
self.existing_server_default = existing_server_default
|
||||||
|
self.existing_comment = existing_comment
|
||||||
|
|
||||||
|
|
||||||
|
class ColumnNullable(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column_name: str, nullable: bool, **kw
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.nullable = nullable
|
||||||
|
|
||||||
|
|
||||||
|
class ColumnType(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column_name: str, type_: TypeEngine, **kw
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.type_ = sqltypes.to_instance(type_)
|
||||||
|
|
||||||
|
|
||||||
|
class ColumnName(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column_name: str, newname: str, **kw
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.newname = newname
|
||||||
|
|
||||||
|
|
||||||
|
class ColumnDefault(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column_name: str,
|
||||||
|
default: Optional[_ServerDefault],
|
||||||
|
**kw,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
|
||||||
|
class ComputedColumnDefault(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column_name: str, default: Optional[Computed], **kw
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
|
||||||
|
class IdentityColumnDefault(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column_name: str,
|
||||||
|
default: Optional[Identity],
|
||||||
|
impl: DefaultImpl,
|
||||||
|
**kw,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.default = default
|
||||||
|
self.impl = impl
|
||||||
|
|
||||||
|
|
||||||
|
class AddColumn(AlterTable):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column: Column[Any],
|
||||||
|
schema: Optional[Union[quoted_name, str]] = None,
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, schema=schema)
|
||||||
|
self.column = column
|
||||||
|
|
||||||
|
|
||||||
|
class DropColumn(AlterTable):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column: Column[Any], schema: Optional[str] = None
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, schema=schema)
|
||||||
|
self.column = column
|
||||||
|
|
||||||
|
|
||||||
|
class ColumnComment(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self, name: str, column_name: str, comment: Optional[str], **kw
|
||||||
|
) -> None:
|
||||||
|
super().__init__(name, column_name, **kw)
|
||||||
|
self.comment = comment
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(RenameTable) # type: ignore[misc]
|
||||||
|
def visit_rename_table(
|
||||||
|
element: RenameTable, compiler: DDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s RENAME TO %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_table_name(compiler, element.new_table_name, element.schema),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(AddColumn) # type: ignore[misc]
|
||||||
|
def visit_add_column(element: AddColumn, compiler: DDLCompiler, **kw) -> str:
|
||||||
|
return "%s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
add_column(compiler, element.column, **kw),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(DropColumn) # type: ignore[misc]
|
||||||
|
def visit_drop_column(element: DropColumn, compiler: DDLCompiler, **kw) -> str:
|
||||||
|
return "%s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
drop_column(compiler, element.column.name, **kw),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnNullable) # type: ignore[misc]
|
||||||
|
def visit_column_nullable(
|
||||||
|
element: ColumnNullable, compiler: DDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
alter_column(compiler, element.column_name),
|
||||||
|
"DROP NOT NULL" if element.nullable else "SET NOT NULL",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnType) # type: ignore[misc]
|
||||||
|
def visit_column_type(element: ColumnType, compiler: DDLCompiler, **kw) -> str:
|
||||||
|
return "%s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
alter_column(compiler, element.column_name),
|
||||||
|
"TYPE %s" % format_type(compiler, element.type_),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnName) # type: ignore[misc]
|
||||||
|
def visit_column_name(element: ColumnName, compiler: DDLCompiler, **kw) -> str:
|
||||||
|
return "%s RENAME %s TO %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
format_column_name(compiler, element.newname),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnDefault) # type: ignore[misc]
|
||||||
|
def visit_column_default(
|
||||||
|
element: ColumnDefault, compiler: DDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
alter_column(compiler, element.column_name),
|
||||||
|
(
|
||||||
|
"SET DEFAULT %s" % format_server_default(compiler, element.default)
|
||||||
|
if element.default is not None
|
||||||
|
else "DROP DEFAULT"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ComputedColumnDefault) # type: ignore[misc]
|
||||||
|
def visit_computed_column(
|
||||||
|
element: ComputedColumnDefault, compiler: DDLCompiler, **kw
|
||||||
|
):
|
||||||
|
raise exc.CompileError(
|
||||||
|
'Adding or removing a "computed" construct, e.g. GENERATED '
|
||||||
|
"ALWAYS AS, to or from an existing column is not supported."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(IdentityColumnDefault) # type: ignore[misc]
|
||||||
|
def visit_identity_column(
|
||||||
|
element: IdentityColumnDefault, compiler: DDLCompiler, **kw
|
||||||
|
):
|
||||||
|
raise exc.CompileError(
|
||||||
|
'Adding, removing or modifying an "identity" construct, '
|
||||||
|
"e.g. GENERATED AS IDENTITY, to or from an existing "
|
||||||
|
"column is not supported in this dialect."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def quote_dotted(
|
||||||
|
name: Union[quoted_name, str], quote: functools.partial
|
||||||
|
) -> Union[quoted_name, str]:
|
||||||
|
"""quote the elements of a dotted name"""
|
||||||
|
|
||||||
|
if isinstance(name, quoted_name):
|
||||||
|
return quote(name)
|
||||||
|
result = ".".join([quote(x) for x in name.split(".")])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def format_table_name(
|
||||||
|
compiler: Compiled,
|
||||||
|
name: Union[quoted_name, str],
|
||||||
|
schema: Optional[Union[quoted_name, str]],
|
||||||
|
) -> Union[quoted_name, str]:
|
||||||
|
quote = functools.partial(compiler.preparer.quote)
|
||||||
|
if schema:
|
||||||
|
return quote_dotted(schema, quote) + "." + quote(name)
|
||||||
|
else:
|
||||||
|
return quote(name)
|
||||||
|
|
||||||
|
|
||||||
|
def format_column_name(
|
||||||
|
compiler: DDLCompiler, name: Optional[Union[quoted_name, str]]
|
||||||
|
) -> Union[quoted_name, str]:
|
||||||
|
return compiler.preparer.quote(name) # type: ignore[arg-type]
|
||||||
|
|
||||||
|
|
||||||
|
def format_server_default(
|
||||||
|
compiler: DDLCompiler,
|
||||||
|
default: Optional[_ServerDefault],
|
||||||
|
) -> str:
|
||||||
|
return compiler.get_column_default_string(
|
||||||
|
Column("x", Integer, server_default=default)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def format_type(compiler: DDLCompiler, type_: TypeEngine) -> str:
|
||||||
|
return compiler.dialect.type_compiler.process(type_)
|
||||||
|
|
||||||
|
|
||||||
|
def alter_table(
|
||||||
|
compiler: DDLCompiler,
|
||||||
|
name: str,
|
||||||
|
schema: Optional[str],
|
||||||
|
) -> str:
|
||||||
|
return "ALTER TABLE %s" % format_table_name(compiler, name, schema)
|
||||||
|
|
||||||
|
|
||||||
|
def drop_column(compiler: DDLCompiler, name: str, **kw) -> str:
|
||||||
|
return "DROP COLUMN %s" % format_column_name(compiler, name)
|
||||||
|
|
||||||
|
|
||||||
|
def alter_column(compiler: DDLCompiler, name: str) -> str:
|
||||||
|
return "ALTER COLUMN %s" % format_column_name(compiler, name)
|
||||||
|
|
||||||
|
|
||||||
|
def add_column(compiler: DDLCompiler, column: Column[Any], **kw) -> str:
|
||||||
|
text = "ADD COLUMN %s" % compiler.get_column_specification(column, **kw)
|
||||||
|
|
||||||
|
const = " ".join(
|
||||||
|
compiler.process(constraint) for constraint in column.constraints
|
||||||
|
)
|
||||||
|
if const:
|
||||||
|
text += " " + const
|
||||||
|
|
||||||
|
return text
|
||||||
@@ -0,0 +1,849 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
||||||
|
# mypy: no-warn-return-any, allow-any-generics
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
from typing import Callable
|
||||||
|
from typing import Dict
|
||||||
|
from typing import Iterable
|
||||||
|
from typing import List
|
||||||
|
from typing import Mapping
|
||||||
|
from typing import NamedTuple
|
||||||
|
from typing import Optional
|
||||||
|
from typing import Sequence
|
||||||
|
from typing import Set
|
||||||
|
from typing import Tuple
|
||||||
|
from typing import Type
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy import cast
|
||||||
|
from sqlalchemy import schema
|
||||||
|
from sqlalchemy import text
|
||||||
|
|
||||||
|
from . import _autogen
|
||||||
|
from . import base
|
||||||
|
from ._autogen import _constraint_sig as _constraint_sig
|
||||||
|
from ._autogen import ComparisonResult as ComparisonResult
|
||||||
|
from .. import util
|
||||||
|
from ..util import sqla_compat
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Literal
|
||||||
|
from typing import TextIO
|
||||||
|
|
||||||
|
from sqlalchemy.engine import Connection
|
||||||
|
from sqlalchemy.engine import Dialect
|
||||||
|
from sqlalchemy.engine.cursor import CursorResult
|
||||||
|
from sqlalchemy.engine.reflection import Inspector
|
||||||
|
from sqlalchemy.sql import ClauseElement
|
||||||
|
from sqlalchemy.sql import Executable
|
||||||
|
from sqlalchemy.sql.elements import ColumnElement
|
||||||
|
from sqlalchemy.sql.elements import quoted_name
|
||||||
|
from sqlalchemy.sql.schema import Column
|
||||||
|
from sqlalchemy.sql.schema import Constraint
|
||||||
|
from sqlalchemy.sql.schema import ForeignKeyConstraint
|
||||||
|
from sqlalchemy.sql.schema import Index
|
||||||
|
from sqlalchemy.sql.schema import Table
|
||||||
|
from sqlalchemy.sql.schema import UniqueConstraint
|
||||||
|
from sqlalchemy.sql.selectable import TableClause
|
||||||
|
from sqlalchemy.sql.type_api import TypeEngine
|
||||||
|
|
||||||
|
from .base import _ServerDefault
|
||||||
|
from ..autogenerate.api import AutogenContext
|
||||||
|
from ..operations.batch import ApplyBatchImpl
|
||||||
|
from ..operations.batch import BatchOperationsImpl
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ImplMeta(type):
|
||||||
|
def __init__(
|
||||||
|
cls,
|
||||||
|
classname: str,
|
||||||
|
bases: Tuple[Type[DefaultImpl]],
|
||||||
|
dict_: Dict[str, Any],
|
||||||
|
):
|
||||||
|
newtype = type.__init__(cls, classname, bases, dict_)
|
||||||
|
if "__dialect__" in dict_:
|
||||||
|
_impls[dict_["__dialect__"]] = cls # type: ignore[assignment]
|
||||||
|
return newtype
|
||||||
|
|
||||||
|
|
||||||
|
_impls: Dict[str, Type[DefaultImpl]] = {}
|
||||||
|
|
||||||
|
|
||||||
|
class DefaultImpl(metaclass=ImplMeta):
|
||||||
|
"""Provide the entrypoint for major migration operations,
|
||||||
|
including database-specific behavioral variances.
|
||||||
|
|
||||||
|
While individual SQL/DDL constructs already provide
|
||||||
|
for database-specific implementations, variances here
|
||||||
|
allow for entirely different sequences of operations
|
||||||
|
to take place for a particular migration, such as
|
||||||
|
SQL Server's special 'IDENTITY INSERT' step for
|
||||||
|
bulk inserts.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
__dialect__ = "default"
|
||||||
|
|
||||||
|
transactional_ddl = False
|
||||||
|
command_terminator = ";"
|
||||||
|
type_synonyms: Tuple[Set[str], ...] = ({"NUMERIC", "DECIMAL"},)
|
||||||
|
type_arg_extract: Sequence[str] = ()
|
||||||
|
# These attributes are deprecated in SQLAlchemy via #10247. They need to
|
||||||
|
# be ignored to support older version that did not use dialect kwargs.
|
||||||
|
# They only apply to Oracle and are replaced by oracle_order,
|
||||||
|
# oracle_on_null
|
||||||
|
identity_attrs_ignore: Tuple[str, ...] = ("order", "on_null")
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
dialect: Dialect,
|
||||||
|
connection: Optional[Connection],
|
||||||
|
as_sql: bool,
|
||||||
|
transactional_ddl: Optional[bool],
|
||||||
|
output_buffer: Optional[TextIO],
|
||||||
|
context_opts: Dict[str, Any],
|
||||||
|
) -> None:
|
||||||
|
self.dialect = dialect
|
||||||
|
self.connection = connection
|
||||||
|
self.as_sql = as_sql
|
||||||
|
self.literal_binds = context_opts.get("literal_binds", False)
|
||||||
|
|
||||||
|
self.output_buffer = output_buffer
|
||||||
|
self.memo: dict = {}
|
||||||
|
self.context_opts = context_opts
|
||||||
|
if transactional_ddl is not None:
|
||||||
|
self.transactional_ddl = transactional_ddl
|
||||||
|
|
||||||
|
if self.literal_binds:
|
||||||
|
if not self.as_sql:
|
||||||
|
raise util.CommandError(
|
||||||
|
"Can't use literal_binds setting without as_sql mode"
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_by_dialect(cls, dialect: Dialect) -> Type[DefaultImpl]:
|
||||||
|
return _impls[dialect.name]
|
||||||
|
|
||||||
|
def static_output(self, text: str) -> None:
|
||||||
|
assert self.output_buffer is not None
|
||||||
|
self.output_buffer.write(text + "\n\n")
|
||||||
|
self.output_buffer.flush()
|
||||||
|
|
||||||
|
def requires_recreate_in_batch(
|
||||||
|
self, batch_op: BatchOperationsImpl
|
||||||
|
) -> bool:
|
||||||
|
"""Return True if the given :class:`.BatchOperationsImpl`
|
||||||
|
would need the table to be recreated and copied in order to
|
||||||
|
proceed.
|
||||||
|
|
||||||
|
Normally, only returns True on SQLite when operations other
|
||||||
|
than add_column are present.
|
||||||
|
|
||||||
|
"""
|
||||||
|
return False
|
||||||
|
|
||||||
|
def prep_table_for_batch(
|
||||||
|
self, batch_impl: ApplyBatchImpl, table: Table
|
||||||
|
) -> None:
|
||||||
|
"""perform any operations needed on a table before a new
|
||||||
|
one is created to replace it in batch mode.
|
||||||
|
|
||||||
|
the PG dialect uses this to drop constraints on the table
|
||||||
|
before the new one uses those same names.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def bind(self) -> Optional[Connection]:
|
||||||
|
return self.connection
|
||||||
|
|
||||||
|
def _exec(
|
||||||
|
self,
|
||||||
|
construct: Union[Executable, str],
|
||||||
|
execution_options: Optional[Mapping[str, Any]] = None,
|
||||||
|
multiparams: Optional[Sequence[Mapping[str, Any]]] = None,
|
||||||
|
params: Mapping[str, Any] = util.immutabledict(),
|
||||||
|
) -> Optional[CursorResult]:
|
||||||
|
if isinstance(construct, str):
|
||||||
|
construct = text(construct)
|
||||||
|
if self.as_sql:
|
||||||
|
if multiparams is not None or params:
|
||||||
|
raise TypeError("SQL parameters not allowed with as_sql")
|
||||||
|
|
||||||
|
compile_kw: dict[str, Any]
|
||||||
|
if self.literal_binds and not isinstance(
|
||||||
|
construct, schema.DDLElement
|
||||||
|
):
|
||||||
|
compile_kw = dict(compile_kwargs={"literal_binds": True})
|
||||||
|
else:
|
||||||
|
compile_kw = {}
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert isinstance(construct, ClauseElement)
|
||||||
|
compiled = construct.compile(dialect=self.dialect, **compile_kw)
|
||||||
|
self.static_output(
|
||||||
|
str(compiled).replace("\t", " ").strip()
|
||||||
|
+ self.command_terminator
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
conn = self.connection
|
||||||
|
assert conn is not None
|
||||||
|
if execution_options:
|
||||||
|
conn = conn.execution_options(**execution_options)
|
||||||
|
|
||||||
|
if params and multiparams is not None:
|
||||||
|
raise TypeError(
|
||||||
|
"Can't send params and multiparams at the same time"
|
||||||
|
)
|
||||||
|
|
||||||
|
if multiparams:
|
||||||
|
return conn.execute(construct, multiparams)
|
||||||
|
else:
|
||||||
|
return conn.execute(construct, params)
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
self,
|
||||||
|
sql: Union[Executable, str],
|
||||||
|
execution_options: Optional[dict[str, Any]] = None,
|
||||||
|
) -> None:
|
||||||
|
self._exec(sql, execution_options)
|
||||||
|
|
||||||
|
def alter_column(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column_name: str,
|
||||||
|
nullable: Optional[bool] = None,
|
||||||
|
server_default: Union[_ServerDefault, Literal[False]] = False,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
type_: Optional[TypeEngine] = None,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
autoincrement: Optional[bool] = None,
|
||||||
|
comment: Optional[Union[str, Literal[False]]] = False,
|
||||||
|
existing_comment: Optional[str] = None,
|
||||||
|
existing_type: Optional[TypeEngine] = None,
|
||||||
|
existing_server_default: Optional[_ServerDefault] = None,
|
||||||
|
existing_nullable: Optional[bool] = None,
|
||||||
|
existing_autoincrement: Optional[bool] = None,
|
||||||
|
**kw: Any,
|
||||||
|
) -> None:
|
||||||
|
if autoincrement is not None or existing_autoincrement is not None:
|
||||||
|
util.warn(
|
||||||
|
"autoincrement and existing_autoincrement "
|
||||||
|
"only make sense for MySQL",
|
||||||
|
stacklevel=3,
|
||||||
|
)
|
||||||
|
if nullable is not None:
|
||||||
|
self._exec(
|
||||||
|
base.ColumnNullable(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
nullable,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
existing_comment=existing_comment,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if server_default is not False:
|
||||||
|
kw = {}
|
||||||
|
cls_: Type[
|
||||||
|
Union[
|
||||||
|
base.ComputedColumnDefault,
|
||||||
|
base.IdentityColumnDefault,
|
||||||
|
base.ColumnDefault,
|
||||||
|
]
|
||||||
|
]
|
||||||
|
if sqla_compat._server_default_is_computed(
|
||||||
|
server_default, existing_server_default
|
||||||
|
):
|
||||||
|
cls_ = base.ComputedColumnDefault
|
||||||
|
elif sqla_compat._server_default_is_identity(
|
||||||
|
server_default, existing_server_default
|
||||||
|
):
|
||||||
|
cls_ = base.IdentityColumnDefault
|
||||||
|
kw["impl"] = self
|
||||||
|
else:
|
||||||
|
cls_ = base.ColumnDefault
|
||||||
|
self._exec(
|
||||||
|
cls_(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
server_default, # type:ignore[arg-type]
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
existing_comment=existing_comment,
|
||||||
|
**kw,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if type_ is not None:
|
||||||
|
self._exec(
|
||||||
|
base.ColumnType(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
type_,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
existing_comment=existing_comment,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if comment is not False:
|
||||||
|
self._exec(
|
||||||
|
base.ColumnComment(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
comment,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
existing_comment=existing_comment,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# do the new name last ;)
|
||||||
|
if name is not None:
|
||||||
|
self._exec(
|
||||||
|
base.ColumnName(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
name,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_column(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column: Column[Any],
|
||||||
|
schema: Optional[Union[str, quoted_name]] = None,
|
||||||
|
) -> None:
|
||||||
|
self._exec(base.AddColumn(table_name, column, schema=schema))
|
||||||
|
|
||||||
|
def drop_column(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column: Column[Any],
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
**kw,
|
||||||
|
) -> None:
|
||||||
|
self._exec(base.DropColumn(table_name, column, schema=schema))
|
||||||
|
|
||||||
|
def add_constraint(self, const: Any) -> None:
|
||||||
|
if const._create_rule is None or const._create_rule(self):
|
||||||
|
self._exec(schema.AddConstraint(const))
|
||||||
|
|
||||||
|
def drop_constraint(self, const: Constraint) -> None:
|
||||||
|
self._exec(schema.DropConstraint(const))
|
||||||
|
|
||||||
|
def rename_table(
|
||||||
|
self,
|
||||||
|
old_table_name: str,
|
||||||
|
new_table_name: Union[str, quoted_name],
|
||||||
|
schema: Optional[Union[str, quoted_name]] = None,
|
||||||
|
) -> None:
|
||||||
|
self._exec(
|
||||||
|
base.RenameTable(old_table_name, new_table_name, schema=schema)
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_table(self, table: Table) -> None:
|
||||||
|
table.dispatch.before_create(
|
||||||
|
table, self.connection, checkfirst=False, _ddl_runner=self
|
||||||
|
)
|
||||||
|
self._exec(schema.CreateTable(table))
|
||||||
|
table.dispatch.after_create(
|
||||||
|
table, self.connection, checkfirst=False, _ddl_runner=self
|
||||||
|
)
|
||||||
|
for index in table.indexes:
|
||||||
|
self._exec(schema.CreateIndex(index))
|
||||||
|
|
||||||
|
with_comment = (
|
||||||
|
self.dialect.supports_comments and not self.dialect.inline_comments
|
||||||
|
)
|
||||||
|
comment = table.comment
|
||||||
|
if comment and with_comment:
|
||||||
|
self.create_table_comment(table)
|
||||||
|
|
||||||
|
for column in table.columns:
|
||||||
|
comment = column.comment
|
||||||
|
if comment and with_comment:
|
||||||
|
self.create_column_comment(column)
|
||||||
|
|
||||||
|
def drop_table(self, table: Table) -> None:
|
||||||
|
table.dispatch.before_drop(
|
||||||
|
table, self.connection, checkfirst=False, _ddl_runner=self
|
||||||
|
)
|
||||||
|
self._exec(schema.DropTable(table))
|
||||||
|
table.dispatch.after_drop(
|
||||||
|
table, self.connection, checkfirst=False, _ddl_runner=self
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_index(self, index: Index, **kw: Any) -> None:
|
||||||
|
self._exec(schema.CreateIndex(index, **kw))
|
||||||
|
|
||||||
|
def create_table_comment(self, table: Table) -> None:
|
||||||
|
self._exec(schema.SetTableComment(table))
|
||||||
|
|
||||||
|
def drop_table_comment(self, table: Table) -> None:
|
||||||
|
self._exec(schema.DropTableComment(table))
|
||||||
|
|
||||||
|
def create_column_comment(self, column: ColumnElement[Any]) -> None:
|
||||||
|
self._exec(schema.SetColumnComment(column))
|
||||||
|
|
||||||
|
def drop_index(self, index: Index, **kw: Any) -> None:
|
||||||
|
self._exec(schema.DropIndex(index, **kw))
|
||||||
|
|
||||||
|
def bulk_insert(
|
||||||
|
self,
|
||||||
|
table: Union[TableClause, Table],
|
||||||
|
rows: List[dict],
|
||||||
|
multiinsert: bool = True,
|
||||||
|
) -> None:
|
||||||
|
if not isinstance(rows, list):
|
||||||
|
raise TypeError("List expected")
|
||||||
|
elif rows and not isinstance(rows[0], dict):
|
||||||
|
raise TypeError("List of dictionaries expected")
|
||||||
|
if self.as_sql:
|
||||||
|
for row in rows:
|
||||||
|
self._exec(
|
||||||
|
sqla_compat._insert_inline(table).values(
|
||||||
|
**{
|
||||||
|
k: (
|
||||||
|
sqla_compat._literal_bindparam(
|
||||||
|
k, v, type_=table.c[k].type
|
||||||
|
)
|
||||||
|
if not isinstance(
|
||||||
|
v, sqla_compat._literal_bindparam
|
||||||
|
)
|
||||||
|
else v
|
||||||
|
)
|
||||||
|
for k, v in row.items()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if rows:
|
||||||
|
if multiinsert:
|
||||||
|
self._exec(
|
||||||
|
sqla_compat._insert_inline(table), multiparams=rows
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
for row in rows:
|
||||||
|
self._exec(
|
||||||
|
sqla_compat._insert_inline(table).values(**row)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _tokenize_column_type(self, column: Column) -> Params:
|
||||||
|
definition: str
|
||||||
|
definition = self.dialect.type_compiler.process(column.type).lower()
|
||||||
|
|
||||||
|
# tokenize the SQLAlchemy-generated version of a type, so that
|
||||||
|
# the two can be compared.
|
||||||
|
#
|
||||||
|
# examples:
|
||||||
|
# NUMERIC(10, 5)
|
||||||
|
# TIMESTAMP WITH TIMEZONE
|
||||||
|
# INTEGER UNSIGNED
|
||||||
|
# INTEGER (10) UNSIGNED
|
||||||
|
# INTEGER(10) UNSIGNED
|
||||||
|
# varchar character set utf8
|
||||||
|
#
|
||||||
|
|
||||||
|
tokens: List[str] = re.findall(r"[\w\-_]+|\(.+?\)", definition)
|
||||||
|
|
||||||
|
term_tokens: List[str] = []
|
||||||
|
paren_term = None
|
||||||
|
|
||||||
|
for token in tokens:
|
||||||
|
if re.match(r"^\(.*\)$", token):
|
||||||
|
paren_term = token
|
||||||
|
else:
|
||||||
|
term_tokens.append(token)
|
||||||
|
|
||||||
|
params = Params(term_tokens[0], term_tokens[1:], [], {})
|
||||||
|
|
||||||
|
if paren_term:
|
||||||
|
term: str
|
||||||
|
for term in re.findall("[^(),]+", paren_term):
|
||||||
|
if "=" in term:
|
||||||
|
key, val = term.split("=")
|
||||||
|
params.kwargs[key.strip()] = val.strip()
|
||||||
|
else:
|
||||||
|
params.args.append(term.strip())
|
||||||
|
|
||||||
|
return params
|
||||||
|
|
||||||
|
def _column_types_match(
|
||||||
|
self, inspector_params: Params, metadata_params: Params
|
||||||
|
) -> bool:
|
||||||
|
if inspector_params.token0 == metadata_params.token0:
|
||||||
|
return True
|
||||||
|
|
||||||
|
synonyms = [{t.lower() for t in batch} for batch in self.type_synonyms]
|
||||||
|
inspector_all_terms = " ".join(
|
||||||
|
[inspector_params.token0] + inspector_params.tokens
|
||||||
|
)
|
||||||
|
metadata_all_terms = " ".join(
|
||||||
|
[metadata_params.token0] + metadata_params.tokens
|
||||||
|
)
|
||||||
|
|
||||||
|
for batch in synonyms:
|
||||||
|
if {inspector_all_terms, metadata_all_terms}.issubset(batch) or {
|
||||||
|
inspector_params.token0,
|
||||||
|
metadata_params.token0,
|
||||||
|
}.issubset(batch):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _column_args_match(
|
||||||
|
self, inspected_params: Params, meta_params: Params
|
||||||
|
) -> bool:
|
||||||
|
"""We want to compare column parameters. However, we only want
|
||||||
|
to compare parameters that are set. If they both have `collation`,
|
||||||
|
we want to make sure they are the same. However, if only one
|
||||||
|
specifies it, dont flag it for being less specific
|
||||||
|
"""
|
||||||
|
|
||||||
|
if (
|
||||||
|
len(meta_params.tokens) == len(inspected_params.tokens)
|
||||||
|
and meta_params.tokens != inspected_params.tokens
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if (
|
||||||
|
len(meta_params.args) == len(inspected_params.args)
|
||||||
|
and meta_params.args != inspected_params.args
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
|
||||||
|
insp = " ".join(inspected_params.tokens).lower()
|
||||||
|
meta = " ".join(meta_params.tokens).lower()
|
||||||
|
|
||||||
|
for reg in self.type_arg_extract:
|
||||||
|
mi = re.search(reg, insp)
|
||||||
|
mm = re.search(reg, meta)
|
||||||
|
|
||||||
|
if mi and mm and mi.group(1) != mm.group(1):
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def compare_type(
|
||||||
|
self, inspector_column: Column[Any], metadata_column: Column
|
||||||
|
) -> bool:
|
||||||
|
"""Returns True if there ARE differences between the types of the two
|
||||||
|
columns. Takes impl.type_synonyms into account between retrospected
|
||||||
|
and metadata types
|
||||||
|
"""
|
||||||
|
inspector_params = self._tokenize_column_type(inspector_column)
|
||||||
|
metadata_params = self._tokenize_column_type(metadata_column)
|
||||||
|
|
||||||
|
if not self._column_types_match(inspector_params, metadata_params):
|
||||||
|
return True
|
||||||
|
if not self._column_args_match(inspector_params, metadata_params):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def compare_server_default(
|
||||||
|
self,
|
||||||
|
inspector_column,
|
||||||
|
metadata_column,
|
||||||
|
rendered_metadata_default,
|
||||||
|
rendered_inspector_default,
|
||||||
|
):
|
||||||
|
return rendered_inspector_default != rendered_metadata_default
|
||||||
|
|
||||||
|
def correct_for_autogen_constraints(
|
||||||
|
self,
|
||||||
|
conn_uniques: Set[UniqueConstraint],
|
||||||
|
conn_indexes: Set[Index],
|
||||||
|
metadata_unique_constraints: Set[UniqueConstraint],
|
||||||
|
metadata_indexes: Set[Index],
|
||||||
|
) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def cast_for_batch_migrate(self, existing, existing_transfer, new_type):
|
||||||
|
if existing.type._type_affinity is not new_type._type_affinity:
|
||||||
|
existing_transfer["expr"] = cast(
|
||||||
|
existing_transfer["expr"], new_type
|
||||||
|
)
|
||||||
|
|
||||||
|
def render_ddl_sql_expr(
|
||||||
|
self, expr: ClauseElement, is_server_default: bool = False, **kw: Any
|
||||||
|
) -> str:
|
||||||
|
"""Render a SQL expression that is typically a server default,
|
||||||
|
index expression, etc.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
compile_kw = {"literal_binds": True, "include_table": False}
|
||||||
|
|
||||||
|
return str(
|
||||||
|
expr.compile(dialect=self.dialect, compile_kwargs=compile_kw)
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compat_autogen_column_reflect(self, inspector: Inspector) -> Callable:
|
||||||
|
return self.autogen_column_reflect
|
||||||
|
|
||||||
|
def correct_for_autogen_foreignkeys(
|
||||||
|
self,
|
||||||
|
conn_fks: Set[ForeignKeyConstraint],
|
||||||
|
metadata_fks: Set[ForeignKeyConstraint],
|
||||||
|
) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def autogen_column_reflect(self, inspector, table, column_info):
|
||||||
|
"""A hook that is attached to the 'column_reflect' event for when
|
||||||
|
a Table is reflected from the database during the autogenerate
|
||||||
|
process.
|
||||||
|
|
||||||
|
Dialects can elect to modify the information gathered here.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def start_migrations(self) -> None:
|
||||||
|
"""A hook called when :meth:`.EnvironmentContext.run_migrations`
|
||||||
|
is called.
|
||||||
|
|
||||||
|
Implementations can set up per-migration-run state here.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def emit_begin(self) -> None:
|
||||||
|
"""Emit the string ``BEGIN``, or the backend-specific
|
||||||
|
equivalent, on the current connection context.
|
||||||
|
|
||||||
|
This is used in offline mode and typically
|
||||||
|
via :meth:`.EnvironmentContext.begin_transaction`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.static_output("BEGIN" + self.command_terminator)
|
||||||
|
|
||||||
|
def emit_commit(self) -> None:
|
||||||
|
"""Emit the string ``COMMIT``, or the backend-specific
|
||||||
|
equivalent, on the current connection context.
|
||||||
|
|
||||||
|
This is used in offline mode and typically
|
||||||
|
via :meth:`.EnvironmentContext.begin_transaction`.
|
||||||
|
|
||||||
|
"""
|
||||||
|
self.static_output("COMMIT" + self.command_terminator)
|
||||||
|
|
||||||
|
def render_type(
|
||||||
|
self, type_obj: TypeEngine, autogen_context: AutogenContext
|
||||||
|
) -> Union[str, Literal[False]]:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _compare_identity_default(self, metadata_identity, inspector_identity):
|
||||||
|
# ignored contains the attributes that were not considered
|
||||||
|
# because assumed to their default values in the db.
|
||||||
|
diff, ignored = _compare_identity_options(
|
||||||
|
metadata_identity,
|
||||||
|
inspector_identity,
|
||||||
|
sqla_compat.Identity(),
|
||||||
|
skip={"always"},
|
||||||
|
)
|
||||||
|
|
||||||
|
meta_always = getattr(metadata_identity, "always", None)
|
||||||
|
inspector_always = getattr(inspector_identity, "always", None)
|
||||||
|
# None and False are the same in this comparison
|
||||||
|
if bool(meta_always) != bool(inspector_always):
|
||||||
|
diff.add("always")
|
||||||
|
|
||||||
|
diff.difference_update(self.identity_attrs_ignore)
|
||||||
|
|
||||||
|
# returns 3 values:
|
||||||
|
return (
|
||||||
|
# different identity attributes
|
||||||
|
diff,
|
||||||
|
# ignored identity attributes
|
||||||
|
ignored,
|
||||||
|
# if the two identity should be considered different
|
||||||
|
bool(diff) or bool(metadata_identity) != bool(inspector_identity),
|
||||||
|
)
|
||||||
|
|
||||||
|
def _compare_index_unique(
|
||||||
|
self, metadata_index: Index, reflected_index: Index
|
||||||
|
) -> Optional[str]:
|
||||||
|
conn_unique = bool(reflected_index.unique)
|
||||||
|
meta_unique = bool(metadata_index.unique)
|
||||||
|
if conn_unique != meta_unique:
|
||||||
|
return f"unique={conn_unique} to unique={meta_unique}"
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _create_metadata_constraint_sig(
|
||||||
|
self, constraint: _autogen._C, **opts: Any
|
||||||
|
) -> _constraint_sig[_autogen._C]:
|
||||||
|
return _constraint_sig.from_constraint(True, self, constraint, **opts)
|
||||||
|
|
||||||
|
def _create_reflected_constraint_sig(
|
||||||
|
self, constraint: _autogen._C, **opts: Any
|
||||||
|
) -> _constraint_sig[_autogen._C]:
|
||||||
|
return _constraint_sig.from_constraint(False, self, constraint, **opts)
|
||||||
|
|
||||||
|
def compare_indexes(
|
||||||
|
self,
|
||||||
|
metadata_index: Index,
|
||||||
|
reflected_index: Index,
|
||||||
|
) -> ComparisonResult:
|
||||||
|
"""Compare two indexes by comparing the signature generated by
|
||||||
|
``create_index_sig``.
|
||||||
|
|
||||||
|
This method returns a ``ComparisonResult``.
|
||||||
|
"""
|
||||||
|
msg: List[str] = []
|
||||||
|
unique_msg = self._compare_index_unique(
|
||||||
|
metadata_index, reflected_index
|
||||||
|
)
|
||||||
|
if unique_msg:
|
||||||
|
msg.append(unique_msg)
|
||||||
|
m_sig = self._create_metadata_constraint_sig(metadata_index)
|
||||||
|
r_sig = self._create_reflected_constraint_sig(reflected_index)
|
||||||
|
|
||||||
|
assert _autogen.is_index_sig(m_sig)
|
||||||
|
assert _autogen.is_index_sig(r_sig)
|
||||||
|
|
||||||
|
# The assumption is that the index have no expression
|
||||||
|
for sig in m_sig, r_sig:
|
||||||
|
if sig.has_expressions:
|
||||||
|
log.warning(
|
||||||
|
"Generating approximate signature for index %s. "
|
||||||
|
"The dialect "
|
||||||
|
"implementation should either skip expression indexes "
|
||||||
|
"or provide a custom implementation.",
|
||||||
|
sig.const,
|
||||||
|
)
|
||||||
|
|
||||||
|
if m_sig.column_names != r_sig.column_names:
|
||||||
|
msg.append(
|
||||||
|
f"expression {r_sig.column_names} to {m_sig.column_names}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if msg:
|
||||||
|
return ComparisonResult.Different(msg)
|
||||||
|
else:
|
||||||
|
return ComparisonResult.Equal()
|
||||||
|
|
||||||
|
def compare_unique_constraint(
|
||||||
|
self,
|
||||||
|
metadata_constraint: UniqueConstraint,
|
||||||
|
reflected_constraint: UniqueConstraint,
|
||||||
|
) -> ComparisonResult:
|
||||||
|
"""Compare two unique constraints by comparing the two signatures.
|
||||||
|
|
||||||
|
The arguments are two tuples that contain the unique constraint and
|
||||||
|
the signatures generated by ``create_unique_constraint_sig``.
|
||||||
|
|
||||||
|
This method returns a ``ComparisonResult``.
|
||||||
|
"""
|
||||||
|
metadata_tup = self._create_metadata_constraint_sig(
|
||||||
|
metadata_constraint
|
||||||
|
)
|
||||||
|
reflected_tup = self._create_reflected_constraint_sig(
|
||||||
|
reflected_constraint
|
||||||
|
)
|
||||||
|
|
||||||
|
meta_sig = metadata_tup.unnamed
|
||||||
|
conn_sig = reflected_tup.unnamed
|
||||||
|
if conn_sig != meta_sig:
|
||||||
|
return ComparisonResult.Different(
|
||||||
|
f"expression {conn_sig} to {meta_sig}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return ComparisonResult.Equal()
|
||||||
|
|
||||||
|
def _skip_functional_indexes(self, metadata_indexes, conn_indexes):
|
||||||
|
conn_indexes_by_name = {c.name: c for c in conn_indexes}
|
||||||
|
|
||||||
|
for idx in list(metadata_indexes):
|
||||||
|
if idx.name in conn_indexes_by_name:
|
||||||
|
continue
|
||||||
|
iex = sqla_compat.is_expression_index(idx)
|
||||||
|
if iex:
|
||||||
|
util.warn(
|
||||||
|
"autogenerate skipping metadata-specified "
|
||||||
|
"expression-based index "
|
||||||
|
f"{idx.name!r}; dialect {self.__dialect__!r} under "
|
||||||
|
f"SQLAlchemy {sqla_compat.sqlalchemy_version} can't "
|
||||||
|
"reflect these indexes so they can't be compared"
|
||||||
|
)
|
||||||
|
metadata_indexes.discard(idx)
|
||||||
|
|
||||||
|
def adjust_reflected_dialect_options(
|
||||||
|
self, reflected_object: Dict[str, Any], kind: str
|
||||||
|
) -> Dict[str, Any]:
|
||||||
|
return reflected_object.get("dialect_options", {})
|
||||||
|
|
||||||
|
|
||||||
|
class Params(NamedTuple):
|
||||||
|
token0: str
|
||||||
|
tokens: List[str]
|
||||||
|
args: List[str]
|
||||||
|
kwargs: Dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
|
def _compare_identity_options(
|
||||||
|
metadata_io: Union[schema.Identity, schema.Sequence, None],
|
||||||
|
inspector_io: Union[schema.Identity, schema.Sequence, None],
|
||||||
|
default_io: Union[schema.Identity, schema.Sequence],
|
||||||
|
skip: Set[str],
|
||||||
|
):
|
||||||
|
# this can be used for identity or sequence compare.
|
||||||
|
# default_io is an instance of IdentityOption with all attributes to the
|
||||||
|
# default value.
|
||||||
|
meta_d = sqla_compat._get_identity_options_dict(metadata_io)
|
||||||
|
insp_d = sqla_compat._get_identity_options_dict(inspector_io)
|
||||||
|
|
||||||
|
diff = set()
|
||||||
|
ignored_attr = set()
|
||||||
|
|
||||||
|
def check_dicts(
|
||||||
|
meta_dict: Mapping[str, Any],
|
||||||
|
insp_dict: Mapping[str, Any],
|
||||||
|
default_dict: Mapping[str, Any],
|
||||||
|
attrs: Iterable[str],
|
||||||
|
):
|
||||||
|
for attr in set(attrs).difference(skip):
|
||||||
|
meta_value = meta_dict.get(attr)
|
||||||
|
insp_value = insp_dict.get(attr)
|
||||||
|
if insp_value != meta_value:
|
||||||
|
default_value = default_dict.get(attr)
|
||||||
|
if meta_value == default_value:
|
||||||
|
ignored_attr.add(attr)
|
||||||
|
else:
|
||||||
|
diff.add(attr)
|
||||||
|
|
||||||
|
check_dicts(
|
||||||
|
meta_d,
|
||||||
|
insp_d,
|
||||||
|
sqla_compat._get_identity_options_dict(default_io),
|
||||||
|
set(meta_d).union(insp_d),
|
||||||
|
)
|
||||||
|
if sqla_compat.identity_has_dialect_kwargs:
|
||||||
|
# use only the dialect kwargs in inspector_io since metadata_io
|
||||||
|
# can have options for many backends
|
||||||
|
check_dicts(
|
||||||
|
getattr(metadata_io, "dialect_kwargs", {}),
|
||||||
|
getattr(inspector_io, "dialect_kwargs", {}),
|
||||||
|
default_io.dialect_kwargs, # type: ignore[union-attr]
|
||||||
|
getattr(inspector_io, "dialect_kwargs", {}),
|
||||||
|
)
|
||||||
|
|
||||||
|
return diff, ignored_attr
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
||||||
|
# mypy: no-warn-return-any, allow-any-generics
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
from typing import Dict
|
||||||
|
from typing import List
|
||||||
|
from typing import Optional
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy import types as sqltypes
|
||||||
|
from sqlalchemy.schema import Column
|
||||||
|
from sqlalchemy.schema import CreateIndex
|
||||||
|
from sqlalchemy.sql.base import Executable
|
||||||
|
from sqlalchemy.sql.elements import ClauseElement
|
||||||
|
|
||||||
|
from .base import AddColumn
|
||||||
|
from .base import alter_column
|
||||||
|
from .base import alter_table
|
||||||
|
from .base import ColumnDefault
|
||||||
|
from .base import ColumnName
|
||||||
|
from .base import ColumnNullable
|
||||||
|
from .base import ColumnType
|
||||||
|
from .base import format_column_name
|
||||||
|
from .base import format_server_default
|
||||||
|
from .base import format_table_name
|
||||||
|
from .base import format_type
|
||||||
|
from .base import RenameTable
|
||||||
|
from .impl import DefaultImpl
|
||||||
|
from .. import util
|
||||||
|
from ..util import sqla_compat
|
||||||
|
from ..util.sqla_compat import compiles
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.mssql.base import MSDDLCompiler
|
||||||
|
from sqlalchemy.dialects.mssql.base import MSSQLCompiler
|
||||||
|
from sqlalchemy.engine.cursor import CursorResult
|
||||||
|
from sqlalchemy.sql.schema import Index
|
||||||
|
from sqlalchemy.sql.schema import Table
|
||||||
|
from sqlalchemy.sql.selectable import TableClause
|
||||||
|
from sqlalchemy.sql.type_api import TypeEngine
|
||||||
|
|
||||||
|
from .base import _ServerDefault
|
||||||
|
|
||||||
|
|
||||||
|
class MSSQLImpl(DefaultImpl):
|
||||||
|
__dialect__ = "mssql"
|
||||||
|
transactional_ddl = True
|
||||||
|
batch_separator = "GO"
|
||||||
|
|
||||||
|
type_synonyms = DefaultImpl.type_synonyms + ({"VARCHAR", "NVARCHAR"},)
|
||||||
|
identity_attrs_ignore = DefaultImpl.identity_attrs_ignore + (
|
||||||
|
"minvalue",
|
||||||
|
"maxvalue",
|
||||||
|
"nominvalue",
|
||||||
|
"nomaxvalue",
|
||||||
|
"cycle",
|
||||||
|
"cache",
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, *arg, **kw) -> None:
|
||||||
|
super().__init__(*arg, **kw)
|
||||||
|
self.batch_separator = self.context_opts.get(
|
||||||
|
"mssql_batch_separator", self.batch_separator
|
||||||
|
)
|
||||||
|
|
||||||
|
def _exec(self, construct: Any, *args, **kw) -> Optional[CursorResult]:
|
||||||
|
result = super()._exec(construct, *args, **kw)
|
||||||
|
if self.as_sql and self.batch_separator:
|
||||||
|
self.static_output(self.batch_separator)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def emit_begin(self) -> None:
|
||||||
|
self.static_output("BEGIN TRANSACTION" + self.command_terminator)
|
||||||
|
|
||||||
|
def emit_commit(self) -> None:
|
||||||
|
super().emit_commit()
|
||||||
|
if self.as_sql and self.batch_separator:
|
||||||
|
self.static_output(self.batch_separator)
|
||||||
|
|
||||||
|
def alter_column( # type:ignore[override]
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column_name: str,
|
||||||
|
nullable: Optional[bool] = None,
|
||||||
|
server_default: Optional[
|
||||||
|
Union[_ServerDefault, Literal[False]]
|
||||||
|
] = False,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
type_: Optional[TypeEngine] = None,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
existing_type: Optional[TypeEngine] = None,
|
||||||
|
existing_server_default: Optional[_ServerDefault] = None,
|
||||||
|
existing_nullable: Optional[bool] = None,
|
||||||
|
**kw: Any,
|
||||||
|
) -> None:
|
||||||
|
if nullable is not None:
|
||||||
|
if type_ is not None:
|
||||||
|
# the NULL/NOT NULL alter will handle
|
||||||
|
# the type alteration
|
||||||
|
existing_type = type_
|
||||||
|
type_ = None
|
||||||
|
elif existing_type is None:
|
||||||
|
raise util.CommandError(
|
||||||
|
"MS-SQL ALTER COLUMN operations "
|
||||||
|
"with NULL or NOT NULL require the "
|
||||||
|
"existing_type or a new type_ be passed."
|
||||||
|
)
|
||||||
|
elif existing_nullable is not None and type_ is not None:
|
||||||
|
nullable = existing_nullable
|
||||||
|
|
||||||
|
# the NULL/NOT NULL alter will handle
|
||||||
|
# the type alteration
|
||||||
|
existing_type = type_
|
||||||
|
type_ = None
|
||||||
|
|
||||||
|
elif type_ is not None:
|
||||||
|
util.warn(
|
||||||
|
"MS-SQL ALTER COLUMN operations that specify type_= "
|
||||||
|
"should also specify a nullable= or "
|
||||||
|
"existing_nullable= argument to avoid implicit conversion "
|
||||||
|
"of NOT NULL columns to NULL."
|
||||||
|
)
|
||||||
|
|
||||||
|
used_default = False
|
||||||
|
if sqla_compat._server_default_is_identity(
|
||||||
|
server_default, existing_server_default
|
||||||
|
) or sqla_compat._server_default_is_computed(
|
||||||
|
server_default, existing_server_default
|
||||||
|
):
|
||||||
|
used_default = True
|
||||||
|
kw["server_default"] = server_default
|
||||||
|
kw["existing_server_default"] = existing_server_default
|
||||||
|
|
||||||
|
super().alter_column(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
nullable=nullable,
|
||||||
|
type_=type_,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
**kw,
|
||||||
|
)
|
||||||
|
|
||||||
|
if server_default is not False and used_default is False:
|
||||||
|
if existing_server_default is not False or server_default is None:
|
||||||
|
self._exec(
|
||||||
|
_ExecDropConstraint(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
"sys.default_constraints",
|
||||||
|
schema,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if server_default is not None:
|
||||||
|
super().alter_column(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
schema=schema,
|
||||||
|
server_default=server_default,
|
||||||
|
)
|
||||||
|
|
||||||
|
if name is not None:
|
||||||
|
super().alter_column(
|
||||||
|
table_name, column_name, schema=schema, name=name
|
||||||
|
)
|
||||||
|
|
||||||
|
def create_index(self, index: Index, **kw: Any) -> None:
|
||||||
|
# this likely defaults to None if not present, so get()
|
||||||
|
# should normally not return the default value. being
|
||||||
|
# defensive in any case
|
||||||
|
mssql_include = index.kwargs.get("mssql_include", None) or ()
|
||||||
|
assert index.table is not None
|
||||||
|
for col in mssql_include:
|
||||||
|
if col not in index.table.c:
|
||||||
|
index.table.append_column(Column(col, sqltypes.NullType))
|
||||||
|
self._exec(CreateIndex(index, **kw))
|
||||||
|
|
||||||
|
def bulk_insert( # type:ignore[override]
|
||||||
|
self, table: Union[TableClause, Table], rows: List[dict], **kw: Any
|
||||||
|
) -> None:
|
||||||
|
if self.as_sql:
|
||||||
|
self._exec(
|
||||||
|
"SET IDENTITY_INSERT %s ON"
|
||||||
|
% self.dialect.identifier_preparer.format_table(table)
|
||||||
|
)
|
||||||
|
super().bulk_insert(table, rows, **kw)
|
||||||
|
self._exec(
|
||||||
|
"SET IDENTITY_INSERT %s OFF"
|
||||||
|
% self.dialect.identifier_preparer.format_table(table)
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
super().bulk_insert(table, rows, **kw)
|
||||||
|
|
||||||
|
def drop_column(
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column: Column[Any],
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
**kw,
|
||||||
|
) -> None:
|
||||||
|
drop_default = kw.pop("mssql_drop_default", False)
|
||||||
|
if drop_default:
|
||||||
|
self._exec(
|
||||||
|
_ExecDropConstraint(
|
||||||
|
table_name, column, "sys.default_constraints", schema
|
||||||
|
)
|
||||||
|
)
|
||||||
|
drop_check = kw.pop("mssql_drop_check", False)
|
||||||
|
if drop_check:
|
||||||
|
self._exec(
|
||||||
|
_ExecDropConstraint(
|
||||||
|
table_name, column, "sys.check_constraints", schema
|
||||||
|
)
|
||||||
|
)
|
||||||
|
drop_fks = kw.pop("mssql_drop_foreign_key", False)
|
||||||
|
if drop_fks:
|
||||||
|
self._exec(_ExecDropFKConstraint(table_name, column, schema))
|
||||||
|
super().drop_column(table_name, column, schema=schema, **kw)
|
||||||
|
|
||||||
|
def compare_server_default(
|
||||||
|
self,
|
||||||
|
inspector_column,
|
||||||
|
metadata_column,
|
||||||
|
rendered_metadata_default,
|
||||||
|
rendered_inspector_default,
|
||||||
|
):
|
||||||
|
if rendered_metadata_default is not None:
|
||||||
|
rendered_metadata_default = re.sub(
|
||||||
|
r"[\(\) \"\']", "", rendered_metadata_default
|
||||||
|
)
|
||||||
|
|
||||||
|
if rendered_inspector_default is not None:
|
||||||
|
# SQL Server collapses whitespace and adds arbitrary parenthesis
|
||||||
|
# within expressions. our only option is collapse all of it
|
||||||
|
|
||||||
|
rendered_inspector_default = re.sub(
|
||||||
|
r"[\(\) \"\']", "", rendered_inspector_default
|
||||||
|
)
|
||||||
|
|
||||||
|
return rendered_inspector_default != rendered_metadata_default
|
||||||
|
|
||||||
|
def _compare_identity_default(self, metadata_identity, inspector_identity):
|
||||||
|
diff, ignored, is_alter = super()._compare_identity_default(
|
||||||
|
metadata_identity, inspector_identity
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
metadata_identity is None
|
||||||
|
and inspector_identity is not None
|
||||||
|
and not diff
|
||||||
|
and inspector_identity.column is not None
|
||||||
|
and inspector_identity.column.primary_key
|
||||||
|
):
|
||||||
|
# mssql reflect primary keys with autoincrement as identity
|
||||||
|
# columns. if no different attributes are present ignore them
|
||||||
|
is_alter = False
|
||||||
|
|
||||||
|
return diff, ignored, is_alter
|
||||||
|
|
||||||
|
def adjust_reflected_dialect_options(
|
||||||
|
self, reflected_object: Dict[str, Any], kind: str
|
||||||
|
) -> Dict[str, Any]:
|
||||||
|
options: Dict[str, Any]
|
||||||
|
options = reflected_object.get("dialect_options", {}).copy()
|
||||||
|
if not options.get("mssql_include"):
|
||||||
|
options.pop("mssql_include", None)
|
||||||
|
if not options.get("mssql_clustered"):
|
||||||
|
options.pop("mssql_clustered", None)
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
|
class _ExecDropConstraint(Executable, ClauseElement):
|
||||||
|
inherit_cache = False
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
tname: str,
|
||||||
|
colname: Union[Column[Any], str],
|
||||||
|
type_: str,
|
||||||
|
schema: Optional[str],
|
||||||
|
) -> None:
|
||||||
|
self.tname = tname
|
||||||
|
self.colname = colname
|
||||||
|
self.type_ = type_
|
||||||
|
self.schema = schema
|
||||||
|
|
||||||
|
|
||||||
|
class _ExecDropFKConstraint(Executable, ClauseElement):
|
||||||
|
inherit_cache = False
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self, tname: str, colname: Column[Any], schema: Optional[str]
|
||||||
|
) -> None:
|
||||||
|
self.tname = tname
|
||||||
|
self.colname = colname
|
||||||
|
self.schema = schema
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(_ExecDropConstraint, "mssql")
|
||||||
|
def _exec_drop_col_constraint(
|
||||||
|
element: _ExecDropConstraint, compiler: MSSQLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
schema, tname, colname, type_ = (
|
||||||
|
element.schema,
|
||||||
|
element.tname,
|
||||||
|
element.colname,
|
||||||
|
element.type_,
|
||||||
|
)
|
||||||
|
# from http://www.mssqltips.com/sqlservertip/1425/\
|
||||||
|
# working-with-default-constraints-in-sql-server/
|
||||||
|
return """declare @const_name varchar(256)
|
||||||
|
select @const_name = QUOTENAME([name]) from %(type)s
|
||||||
|
where parent_object_id = object_id('%(schema_dot)s%(tname)s')
|
||||||
|
and col_name(parent_object_id, parent_column_id) = '%(colname)s'
|
||||||
|
exec('alter table %(tname_quoted)s drop constraint ' + @const_name)""" % {
|
||||||
|
"type": type_,
|
||||||
|
"tname": tname,
|
||||||
|
"colname": colname,
|
||||||
|
"tname_quoted": format_table_name(compiler, tname, schema),
|
||||||
|
"schema_dot": schema + "." if schema else "",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(_ExecDropFKConstraint, "mssql")
|
||||||
|
def _exec_drop_col_fk_constraint(
|
||||||
|
element: _ExecDropFKConstraint, compiler: MSSQLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
schema, tname, colname = element.schema, element.tname, element.colname
|
||||||
|
|
||||||
|
return """declare @const_name varchar(256)
|
||||||
|
select @const_name = QUOTENAME([name]) from
|
||||||
|
sys.foreign_keys fk join sys.foreign_key_columns fkc
|
||||||
|
on fk.object_id=fkc.constraint_object_id
|
||||||
|
where fkc.parent_object_id = object_id('%(schema_dot)s%(tname)s')
|
||||||
|
and col_name(fkc.parent_object_id, fkc.parent_column_id) = '%(colname)s'
|
||||||
|
exec('alter table %(tname_quoted)s drop constraint ' + @const_name)""" % {
|
||||||
|
"tname": tname,
|
||||||
|
"colname": colname,
|
||||||
|
"tname_quoted": format_table_name(compiler, tname, schema),
|
||||||
|
"schema_dot": schema + "." if schema else "",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(AddColumn, "mssql")
|
||||||
|
def visit_add_column(element: AddColumn, compiler: MSDDLCompiler, **kw) -> str:
|
||||||
|
return "%s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
mssql_add_column(compiler, element.column, **kw),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def mssql_add_column(
|
||||||
|
compiler: MSDDLCompiler, column: Column[Any], **kw
|
||||||
|
) -> str:
|
||||||
|
return "ADD %s" % compiler.get_column_specification(column, **kw)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnNullable, "mssql")
|
||||||
|
def visit_column_nullable(
|
||||||
|
element: ColumnNullable, compiler: MSDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s %s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
alter_column(compiler, element.column_name),
|
||||||
|
format_type(compiler, element.existing_type), # type: ignore[arg-type]
|
||||||
|
"NULL" if element.nullable else "NOT NULL",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnDefault, "mssql")
|
||||||
|
def visit_column_default(
|
||||||
|
element: ColumnDefault, compiler: MSDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
# TODO: there can also be a named constraint
|
||||||
|
# with ADD CONSTRAINT here
|
||||||
|
return "%s ADD DEFAULT %s FOR %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_server_default(compiler, element.default),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnName, "mssql")
|
||||||
|
def visit_rename_column(
|
||||||
|
element: ColumnName, compiler: MSDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "EXEC sp_rename '%s.%s', %s, 'COLUMN'" % (
|
||||||
|
format_table_name(compiler, element.table_name, element.schema),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
format_column_name(compiler, element.newname),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnType, "mssql")
|
||||||
|
def visit_column_type(
|
||||||
|
element: ColumnType, compiler: MSDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
alter_column(compiler, element.column_name),
|
||||||
|
format_type(compiler, element.type_),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(RenameTable, "mssql")
|
||||||
|
def visit_rename_table(
|
||||||
|
element: RenameTable, compiler: MSDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "EXEC sp_rename '%s', %s" % (
|
||||||
|
format_table_name(compiler, element.table_name, element.schema),
|
||||||
|
format_table_name(compiler, element.new_table_name, None),
|
||||||
|
)
|
||||||
@@ -0,0 +1,492 @@
|
|||||||
|
# mypy: allow-untyped-defs, allow-incomplete-defs, allow-untyped-calls
|
||||||
|
# mypy: no-warn-return-any, allow-any-generics
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
|
from typing import Any
|
||||||
|
from typing import Optional
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from sqlalchemy import schema
|
||||||
|
from sqlalchemy import types as sqltypes
|
||||||
|
|
||||||
|
from .base import alter_table
|
||||||
|
from .base import AlterColumn
|
||||||
|
from .base import ColumnDefault
|
||||||
|
from .base import ColumnName
|
||||||
|
from .base import ColumnNullable
|
||||||
|
from .base import ColumnType
|
||||||
|
from .base import format_column_name
|
||||||
|
from .base import format_server_default
|
||||||
|
from .impl import DefaultImpl
|
||||||
|
from .. import util
|
||||||
|
from ..util import sqla_compat
|
||||||
|
from ..util.sqla_compat import _is_mariadb
|
||||||
|
from ..util.sqla_compat import _is_type_bound
|
||||||
|
from ..util.sqla_compat import compiles
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
|
from sqlalchemy.dialects.mysql.base import MySQLDDLCompiler
|
||||||
|
from sqlalchemy.sql.ddl import DropConstraint
|
||||||
|
from sqlalchemy.sql.schema import Constraint
|
||||||
|
from sqlalchemy.sql.type_api import TypeEngine
|
||||||
|
|
||||||
|
from .base import _ServerDefault
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLImpl(DefaultImpl):
|
||||||
|
__dialect__ = "mysql"
|
||||||
|
|
||||||
|
transactional_ddl = False
|
||||||
|
type_synonyms = DefaultImpl.type_synonyms + (
|
||||||
|
{"BOOL", "TINYINT"},
|
||||||
|
{"JSON", "LONGTEXT"},
|
||||||
|
)
|
||||||
|
type_arg_extract = [r"character set ([\w\-_]+)", r"collate ([\w\-_]+)"]
|
||||||
|
|
||||||
|
def alter_column( # type:ignore[override]
|
||||||
|
self,
|
||||||
|
table_name: str,
|
||||||
|
column_name: str,
|
||||||
|
nullable: Optional[bool] = None,
|
||||||
|
server_default: Union[_ServerDefault, Literal[False]] = False,
|
||||||
|
name: Optional[str] = None,
|
||||||
|
type_: Optional[TypeEngine] = None,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
existing_type: Optional[TypeEngine] = None,
|
||||||
|
existing_server_default: Optional[_ServerDefault] = None,
|
||||||
|
existing_nullable: Optional[bool] = None,
|
||||||
|
autoincrement: Optional[bool] = None,
|
||||||
|
existing_autoincrement: Optional[bool] = None,
|
||||||
|
comment: Optional[Union[str, Literal[False]]] = False,
|
||||||
|
existing_comment: Optional[str] = None,
|
||||||
|
**kw: Any,
|
||||||
|
) -> None:
|
||||||
|
if sqla_compat._server_default_is_identity(
|
||||||
|
server_default, existing_server_default
|
||||||
|
) or sqla_compat._server_default_is_computed(
|
||||||
|
server_default, existing_server_default
|
||||||
|
):
|
||||||
|
# modifying computed or identity columns is not supported
|
||||||
|
# the default will raise
|
||||||
|
super().alter_column(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
nullable=nullable,
|
||||||
|
type_=type_,
|
||||||
|
schema=schema,
|
||||||
|
existing_type=existing_type,
|
||||||
|
existing_nullable=existing_nullable,
|
||||||
|
server_default=server_default,
|
||||||
|
existing_server_default=existing_server_default,
|
||||||
|
**kw,
|
||||||
|
)
|
||||||
|
if name is not None or self._is_mysql_allowed_functional_default(
|
||||||
|
type_ if type_ is not None else existing_type, server_default
|
||||||
|
):
|
||||||
|
self._exec(
|
||||||
|
MySQLChangeColumn(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
schema=schema,
|
||||||
|
newname=name if name is not None else column_name,
|
||||||
|
nullable=(
|
||||||
|
nullable
|
||||||
|
if nullable is not None
|
||||||
|
else (
|
||||||
|
existing_nullable
|
||||||
|
if existing_nullable is not None
|
||||||
|
else True
|
||||||
|
)
|
||||||
|
),
|
||||||
|
type_=type_ if type_ is not None else existing_type,
|
||||||
|
default=(
|
||||||
|
server_default
|
||||||
|
if server_default is not False
|
||||||
|
else existing_server_default
|
||||||
|
),
|
||||||
|
autoincrement=(
|
||||||
|
autoincrement
|
||||||
|
if autoincrement is not None
|
||||||
|
else existing_autoincrement
|
||||||
|
),
|
||||||
|
comment=(
|
||||||
|
comment if comment is not False else existing_comment
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif (
|
||||||
|
nullable is not None
|
||||||
|
or type_ is not None
|
||||||
|
or autoincrement is not None
|
||||||
|
or comment is not False
|
||||||
|
):
|
||||||
|
self._exec(
|
||||||
|
MySQLModifyColumn(
|
||||||
|
table_name,
|
||||||
|
column_name,
|
||||||
|
schema=schema,
|
||||||
|
newname=name if name is not None else column_name,
|
||||||
|
nullable=(
|
||||||
|
nullable
|
||||||
|
if nullable is not None
|
||||||
|
else (
|
||||||
|
existing_nullable
|
||||||
|
if existing_nullable is not None
|
||||||
|
else True
|
||||||
|
)
|
||||||
|
),
|
||||||
|
type_=type_ if type_ is not None else existing_type,
|
||||||
|
default=(
|
||||||
|
server_default
|
||||||
|
if server_default is not False
|
||||||
|
else existing_server_default
|
||||||
|
),
|
||||||
|
autoincrement=(
|
||||||
|
autoincrement
|
||||||
|
if autoincrement is not None
|
||||||
|
else existing_autoincrement
|
||||||
|
),
|
||||||
|
comment=(
|
||||||
|
comment if comment is not False else existing_comment
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif server_default is not False:
|
||||||
|
self._exec(
|
||||||
|
MySQLAlterDefault(
|
||||||
|
table_name, column_name, server_default, schema=schema
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def drop_constraint(
|
||||||
|
self,
|
||||||
|
const: Constraint,
|
||||||
|
) -> None:
|
||||||
|
if isinstance(const, schema.CheckConstraint) and _is_type_bound(const):
|
||||||
|
return
|
||||||
|
|
||||||
|
super().drop_constraint(const)
|
||||||
|
|
||||||
|
def _is_mysql_allowed_functional_default(
|
||||||
|
self,
|
||||||
|
type_: Optional[TypeEngine],
|
||||||
|
server_default: Union[_ServerDefault, Literal[False]],
|
||||||
|
) -> bool:
|
||||||
|
return (
|
||||||
|
type_ is not None
|
||||||
|
and type_._type_affinity is sqltypes.DateTime
|
||||||
|
and server_default is not None
|
||||||
|
)
|
||||||
|
|
||||||
|
def compare_server_default(
|
||||||
|
self,
|
||||||
|
inspector_column,
|
||||||
|
metadata_column,
|
||||||
|
rendered_metadata_default,
|
||||||
|
rendered_inspector_default,
|
||||||
|
):
|
||||||
|
# partially a workaround for SQLAlchemy issue #3023; if the
|
||||||
|
# column were created without "NOT NULL", MySQL may have added
|
||||||
|
# an implicit default of '0' which we need to skip
|
||||||
|
# TODO: this is not really covered anymore ?
|
||||||
|
if (
|
||||||
|
metadata_column.type._type_affinity is sqltypes.Integer
|
||||||
|
and inspector_column.primary_key
|
||||||
|
and not inspector_column.autoincrement
|
||||||
|
and not rendered_metadata_default
|
||||||
|
and rendered_inspector_default == "'0'"
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
elif (
|
||||||
|
rendered_inspector_default
|
||||||
|
and inspector_column.type._type_affinity is sqltypes.Integer
|
||||||
|
):
|
||||||
|
rendered_inspector_default = (
|
||||||
|
re.sub(r"^'|'$", "", rendered_inspector_default)
|
||||||
|
if rendered_inspector_default is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
|
return rendered_inspector_default != rendered_metadata_default
|
||||||
|
elif (
|
||||||
|
rendered_metadata_default
|
||||||
|
and metadata_column.type._type_affinity is sqltypes.String
|
||||||
|
):
|
||||||
|
metadata_default = re.sub(r"^'|'$", "", rendered_metadata_default)
|
||||||
|
return rendered_inspector_default != f"'{metadata_default}'"
|
||||||
|
elif rendered_inspector_default and rendered_metadata_default:
|
||||||
|
# adjust for "function()" vs. "FUNCTION" as can occur particularly
|
||||||
|
# for the CURRENT_TIMESTAMP function on newer MariaDB versions
|
||||||
|
|
||||||
|
# SQLAlchemy MySQL dialect bundles ON UPDATE into the server
|
||||||
|
# default; adjust for this possibly being present.
|
||||||
|
onupdate_ins = re.match(
|
||||||
|
r"(.*) (on update.*?)(?:\(\))?$",
|
||||||
|
rendered_inspector_default.lower(),
|
||||||
|
)
|
||||||
|
onupdate_met = re.match(
|
||||||
|
r"(.*) (on update.*?)(?:\(\))?$",
|
||||||
|
rendered_metadata_default.lower(),
|
||||||
|
)
|
||||||
|
|
||||||
|
if onupdate_ins:
|
||||||
|
if not onupdate_met:
|
||||||
|
return True
|
||||||
|
elif onupdate_ins.group(2) != onupdate_met.group(2):
|
||||||
|
return True
|
||||||
|
|
||||||
|
rendered_inspector_default = onupdate_ins.group(1)
|
||||||
|
rendered_metadata_default = onupdate_met.group(1)
|
||||||
|
|
||||||
|
return re.sub(
|
||||||
|
r"(.*?)(?:\(\))?$", r"\1", rendered_inspector_default.lower()
|
||||||
|
) != re.sub(
|
||||||
|
r"(.*?)(?:\(\))?$", r"\1", rendered_metadata_default.lower()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return rendered_inspector_default != rendered_metadata_default
|
||||||
|
|
||||||
|
def correct_for_autogen_constraints(
|
||||||
|
self,
|
||||||
|
conn_unique_constraints,
|
||||||
|
conn_indexes,
|
||||||
|
metadata_unique_constraints,
|
||||||
|
metadata_indexes,
|
||||||
|
):
|
||||||
|
# TODO: if SQLA 1.0, make use of "duplicates_index"
|
||||||
|
# metadata
|
||||||
|
removed = set()
|
||||||
|
for idx in list(conn_indexes):
|
||||||
|
if idx.unique:
|
||||||
|
continue
|
||||||
|
# MySQL puts implicit indexes on FK columns, even if
|
||||||
|
# composite and even if MyISAM, so can't check this too easily.
|
||||||
|
# the name of the index may be the column name or it may
|
||||||
|
# be the name of the FK constraint.
|
||||||
|
for col in idx.columns:
|
||||||
|
if idx.name == col.name:
|
||||||
|
conn_indexes.remove(idx)
|
||||||
|
removed.add(idx.name)
|
||||||
|
break
|
||||||
|
for fk in col.foreign_keys:
|
||||||
|
if fk.name == idx.name:
|
||||||
|
conn_indexes.remove(idx)
|
||||||
|
removed.add(idx.name)
|
||||||
|
break
|
||||||
|
if idx.name in removed:
|
||||||
|
break
|
||||||
|
|
||||||
|
# then remove indexes from the "metadata_indexes"
|
||||||
|
# that we've removed from reflected, otherwise they come out
|
||||||
|
# as adds (see #202)
|
||||||
|
for idx in list(metadata_indexes):
|
||||||
|
if idx.name in removed:
|
||||||
|
metadata_indexes.remove(idx)
|
||||||
|
|
||||||
|
def correct_for_autogen_foreignkeys(self, conn_fks, metadata_fks):
|
||||||
|
conn_fk_by_sig = {
|
||||||
|
self._create_reflected_constraint_sig(fk).unnamed_no_options: fk
|
||||||
|
for fk in conn_fks
|
||||||
|
}
|
||||||
|
metadata_fk_by_sig = {
|
||||||
|
self._create_metadata_constraint_sig(fk).unnamed_no_options: fk
|
||||||
|
for fk in metadata_fks
|
||||||
|
}
|
||||||
|
|
||||||
|
for sig in set(conn_fk_by_sig).intersection(metadata_fk_by_sig):
|
||||||
|
mdfk = metadata_fk_by_sig[sig]
|
||||||
|
cnfk = conn_fk_by_sig[sig]
|
||||||
|
# MySQL considers RESTRICT to be the default and doesn't
|
||||||
|
# report on it. if the model has explicit RESTRICT and
|
||||||
|
# the conn FK has None, set it to RESTRICT
|
||||||
|
if (
|
||||||
|
mdfk.ondelete is not None
|
||||||
|
and mdfk.ondelete.lower() == "restrict"
|
||||||
|
and cnfk.ondelete is None
|
||||||
|
):
|
||||||
|
cnfk.ondelete = "RESTRICT"
|
||||||
|
if (
|
||||||
|
mdfk.onupdate is not None
|
||||||
|
and mdfk.onupdate.lower() == "restrict"
|
||||||
|
and cnfk.onupdate is None
|
||||||
|
):
|
||||||
|
cnfk.onupdate = "RESTRICT"
|
||||||
|
|
||||||
|
|
||||||
|
class MariaDBImpl(MySQLImpl):
|
||||||
|
__dialect__ = "mariadb"
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLAlterDefault(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column_name: str,
|
||||||
|
default: _ServerDefault,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
) -> None:
|
||||||
|
super(AlterColumn, self).__init__(name, schema=schema)
|
||||||
|
self.column_name = column_name
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLChangeColumn(AlterColumn):
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
name: str,
|
||||||
|
column_name: str,
|
||||||
|
schema: Optional[str] = None,
|
||||||
|
newname: Optional[str] = None,
|
||||||
|
type_: Optional[TypeEngine] = None,
|
||||||
|
nullable: Optional[bool] = None,
|
||||||
|
default: Optional[Union[_ServerDefault, Literal[False]]] = False,
|
||||||
|
autoincrement: Optional[bool] = None,
|
||||||
|
comment: Optional[Union[str, Literal[False]]] = False,
|
||||||
|
) -> None:
|
||||||
|
super(AlterColumn, self).__init__(name, schema=schema)
|
||||||
|
self.column_name = column_name
|
||||||
|
self.nullable = nullable
|
||||||
|
self.newname = newname
|
||||||
|
self.default = default
|
||||||
|
self.autoincrement = autoincrement
|
||||||
|
self.comment = comment
|
||||||
|
if type_ is None:
|
||||||
|
raise util.CommandError(
|
||||||
|
"All MySQL CHANGE/MODIFY COLUMN operations "
|
||||||
|
"require the existing type."
|
||||||
|
)
|
||||||
|
|
||||||
|
self.type_ = sqltypes.to_instance(type_)
|
||||||
|
|
||||||
|
|
||||||
|
class MySQLModifyColumn(MySQLChangeColumn):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(ColumnNullable, "mysql", "mariadb")
|
||||||
|
@compiles(ColumnName, "mysql", "mariadb")
|
||||||
|
@compiles(ColumnDefault, "mysql", "mariadb")
|
||||||
|
@compiles(ColumnType, "mysql", "mariadb")
|
||||||
|
def _mysql_doesnt_support_individual(element, compiler, **kw):
|
||||||
|
raise NotImplementedError(
|
||||||
|
"Individual alter column constructs not supported by MySQL"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(MySQLAlterDefault, "mysql", "mariadb")
|
||||||
|
def _mysql_alter_default(
|
||||||
|
element: MySQLAlterDefault, compiler: MySQLDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s ALTER COLUMN %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
(
|
||||||
|
"SET DEFAULT %s" % format_server_default(compiler, element.default)
|
||||||
|
if element.default is not None
|
||||||
|
else "DROP DEFAULT"
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(MySQLModifyColumn, "mysql", "mariadb")
|
||||||
|
def _mysql_modify_column(
|
||||||
|
element: MySQLModifyColumn, compiler: MySQLDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s MODIFY %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
_mysql_colspec(
|
||||||
|
compiler,
|
||||||
|
nullable=element.nullable,
|
||||||
|
server_default=element.default,
|
||||||
|
type_=element.type_,
|
||||||
|
autoincrement=element.autoincrement,
|
||||||
|
comment=element.comment,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(MySQLChangeColumn, "mysql", "mariadb")
|
||||||
|
def _mysql_change_column(
|
||||||
|
element: MySQLChangeColumn, compiler: MySQLDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
return "%s CHANGE %s %s %s" % (
|
||||||
|
alter_table(compiler, element.table_name, element.schema),
|
||||||
|
format_column_name(compiler, element.column_name),
|
||||||
|
format_column_name(compiler, element.newname),
|
||||||
|
_mysql_colspec(
|
||||||
|
compiler,
|
||||||
|
nullable=element.nullable,
|
||||||
|
server_default=element.default,
|
||||||
|
type_=element.type_,
|
||||||
|
autoincrement=element.autoincrement,
|
||||||
|
comment=element.comment,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _mysql_colspec(
|
||||||
|
compiler: MySQLDDLCompiler,
|
||||||
|
nullable: Optional[bool],
|
||||||
|
server_default: Optional[Union[_ServerDefault, Literal[False]]],
|
||||||
|
type_: TypeEngine,
|
||||||
|
autoincrement: Optional[bool],
|
||||||
|
comment: Optional[Union[str, Literal[False]]],
|
||||||
|
) -> str:
|
||||||
|
spec = "%s %s" % (
|
||||||
|
compiler.dialect.type_compiler.process(type_),
|
||||||
|
"NULL" if nullable else "NOT NULL",
|
||||||
|
)
|
||||||
|
if autoincrement:
|
||||||
|
spec += " AUTO_INCREMENT"
|
||||||
|
if server_default is not False and server_default is not None:
|
||||||
|
spec += " DEFAULT %s" % format_server_default(compiler, server_default)
|
||||||
|
if comment:
|
||||||
|
spec += " COMMENT %s" % compiler.sql_compiler.render_literal_value(
|
||||||
|
comment, sqltypes.String()
|
||||||
|
)
|
||||||
|
|
||||||
|
return spec
|
||||||
|
|
||||||
|
|
||||||
|
@compiles(schema.DropConstraint, "mysql", "mariadb")
|
||||||
|
def _mysql_drop_constraint(
|
||||||
|
element: DropConstraint, compiler: MySQLDDLCompiler, **kw
|
||||||
|
) -> str:
|
||||||
|
"""Redefine SQLAlchemy's drop constraint to
|
||||||
|
raise errors for invalid constraint type."""
|
||||||
|
|
||||||
|
constraint = element.element
|
||||||
|
if isinstance(
|
||||||
|
constraint,
|
||||||
|
(
|
||||||
|
schema.ForeignKeyConstraint,
|
||||||
|
schema.PrimaryKeyConstraint,
|
||||||
|
schema.UniqueConstraint,
|
||||||
|
),
|
||||||
|
):
|
||||||
|
assert not kw
|
||||||
|
return compiler.visit_drop_constraint(element)
|
||||||
|
elif isinstance(constraint, schema.CheckConstraint):
|
||||||
|
# note that SQLAlchemy as of 1.2 does not yet support
|
||||||
|
# DROP CONSTRAINT for MySQL/MariaDB, so we implement fully
|
||||||
|
# here.
|
||||||
|
if _is_mariadb(compiler.dialect):
|
||||||
|
return "ALTER TABLE %s DROP CONSTRAINT %s" % (
|
||||||
|
compiler.preparer.format_table(constraint.table),
|
||||||
|
compiler.preparer.format_constraint(constraint),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
return "ALTER TABLE %s DROP CHECK %s" % (
|
||||||
|
compiler.preparer.format_table(constraint.table),
|
||||||
|
compiler.preparer.format_constraint(constraint),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(
|
||||||
|
"No generic 'DROP CONSTRAINT' in MySQL - "
|
||||||
|
"please specify constraint type"
|
||||||
|
)
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user