/opt/imunify360/venv/lib/python3.11/site-packages/playhouse/__pycache__
Edit: /opt/imunify360/venv/lib/python3.11/site-packages/playhouse/__pycache__/migrate.cpython-311.pyc (52689B)
§
Ú¿‡Hãìô¶ã óÎ — d Z ddlmZ ddlZddlZddlZddlT ddlmZ ddlmZ ddlm Z ddlm
Z
dd lmZ dd
lmZ ddlm
Z
ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ n
# e$ r dZY nw xY w G d„ de¦ « Zd„ Zd„ Z G d„ de¦ « Z G d„ de¦ « Z G d„ de¦ « Z G d„ d edd¦ « ¦ « Z G d„ d e¦ « Z G d!„ d"e¦ « Zd#„ ZdS )$ah
Lightweight schema migrations.
Example Usage
-------------
Instantiate a migrator:
# Postgres example:
my_db = PostgresqlDatabase(...)
migrator = PostgresqlMigrator(my_db)
# SQLite example:
my_db = SqliteDatabase('my_database.db')
migrator = SqliteMigrator(my_db)
Then you will use the `migrate` function to run various `Operation`s which
are generated by the migrator:
migrate(
migrator.add_column('some_table', 'column_name', CharField(default=''))
)
Migrations are not run inside a transaction, so if you wish the migration to
run in a transaction you will need to wrap the call to `migrate` in a
transaction block, e.g.:
with my_db.transaction():
migrate(...)
Supported Operations
--------------------
Add new field(s) to an existing model:
# Create your field instances. For non-null fields you must specify a
# default value.
pubdate_field = DateTimeField(null=True)
comment_field = TextField(default='')
# Run the migration, specifying the database table, field name and field.
migrate(
migrator.add_column('comment_tbl', 'pub_date', pubdate_field),
migrator.add_column('comment_tbl', 'comment', comment_field),
)
Renaming a field:
# Specify the table, original name of the column, and its new name.
migrate(
migrator.rename_column('story', 'pub_date', 'publish_date'),
migrator.rename_column('story', 'mod_date', 'modified_date'),
)
Dropping a field:
migrate(
migrator.drop_column('story', 'some_old_field'),
)
Making a field nullable or not nullable:
# Note that when making a field not null that field must not have any
# NULL values present.
migrate(
# Make `pub_date` allow NULL values.
migrator.drop_not_null('story', 'pub_date'),
# Prevent `modified_date` from containing NULL values.
migrator.add_not_null('story', 'modified_date'),
)
Renaming a table:
migrate(
migrator.rename_table('story', 'stories_tbl'),
)
Adding an index:
# Specify the table, column names, and whether the index should be
# UNIQUE or not.
migrate(
# Create an index on the `pub_date` column.
migrator.add_index('story', ('pub_date',), False),
# Create a multi-column index on the `pub_date` and `status` fields.
migrator.add_index('story', ('pub_date', 'status'), False),
# Create a unique index on the category and title fields.
migrator.add_index('story', ('category_id', 'title'), True),
)
Dropping an index:
# Specify the index name.
migrate(migrator.drop_index('story', 'story_pub_date_status'))
Adding or dropping table constraints:
.. code-block:: python
# Add a CHECK() constraint to enforce the price cannot be negative.
migrate(migrator.add_constraint(
'products',
'price_check',
Check('price >= 0')))
# Remove the price check constraint.
migrate(migrator.drop_constraint('products', 'price_check'))
# Add a UNIQUE constraint on the first and last names.
migrate(migrator.add_unique('person', 'first_name', 'last_name'))
é )Ú
namedtupleN)Ú*)Ú
CommaNodeList)ÚEnclosedNodeList©ÚEntity)Ú
Expression)ÚNode)ÚNodeList)ÚOP)Ú callable_)Úsort_models)Úsqlite3)Ú_truncate_constraint_name)ÚCockroachDatabasec ó* — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )Ú Operationz/Encapsulate a single schema altering operation.c ó> — || _ || _ || _ || _ d S ©N)ÚmigratorÚmethodÚargsÚkwargs)Úselfr r r r s úq/builddir/build/BUILD/imunify360-venv-2.6.3/opt/imunify360/venv/lib/python3.11/site-packages/playhouse/migrate.pyÚ__init__zOperation.__init__Œ s" € Ø ˆŒ
؈ŒØˆŒ ؈Œˆˆó c óD — | j j |¦ « d S r )r ÚdatabaseÚexecute)r Únodes r r zOperation.execute’ s! € ØŒ
Ô×&Ò& tÑ,Ô,Ð,Ð,Ð,r c ó2 — t |t t f¦ « r| |¦ « d S t |t ¦ « r| ¦ « d S t |t t f¦ « r|D ]}| |¦ « Œd S d S r ) Ú
isinstancer
ÚContextr r ÚrunÚlistÚtupleÚ_handle_result)r ÚresultÚitems r r( zOperation._handle_result• s£ € Ý�f�t¥W˜oÑ.Ô.ð *Ø�LŠL˜Ñ Ô Ð Ð Ð Ý
˜¥ Ñ
*Ô
*ð *Ø�JŠJ‰LŒLˆLˆLˆLÝ
˜¥¥u
Ñ
.Ô
.ð *Øð
*ð
*�Ø×#Ò# DÑ)Ô)Ð)Ð)ð *ð *ð
*ð
*r c ó¶ — | j ¦ « }d|d<