42 lines
2.6 KiB
Python
42 lines
2.6 KiB
Python
|
|
from pathlib import Path
|
||
|
|
import pytest
|
||
|
|
from alembic import command
|
||
|
|
from alembic.config import Config
|
||
|
|
from sqlalchemy import create_engine,inspect,text
|
||
|
|
|
||
|
|
|
||
|
|
def test_v4_preserves_private_assets_and_adds_sharing_tombstones(tmp_path):
|
||
|
|
config=Config(str(Path(__file__).parents[1]/'alembic.ini'))
|
||
|
|
path=tmp_path/'upgrade-v4.sqlite'
|
||
|
|
config.attributes['url']='sqlite+aiosqlite:///'+str(path)
|
||
|
|
command.upgrade(config,'003')
|
||
|
|
engine=create_engine('sqlite:///'+str(path))
|
||
|
|
with engine.begin() as connection:
|
||
|
|
connection.execute(text("INSERT INTO visual_users(id,username,display_name,password_hash,role,disabled,must_change_password,created_at) VALUES('owner','owner','Owner','UNCHANGED','user',0,0,CURRENT_TIMESTAMP)"))
|
||
|
|
connection.execute(text("INSERT INTO visual_assets(id,owner_id,name,storage_key,kind,mime_type,size_bytes,sha256,tags,favorite,origin,ready,created_at) VALUES('asset','owner','Original','owner/asset/source.png','image','image/png',123,:sha,'[]',0,'upload',1,CURRENT_TIMESTAMP)"),{'sha':'0'*64})
|
||
|
|
command.upgrade(config,'head')
|
||
|
|
command.upgrade(config,'head')
|
||
|
|
with engine.begin() as connection:
|
||
|
|
assert connection.scalar(text('SELECT version_num FROM alembic_version'))=='004'
|
||
|
|
assert connection.execute(text("SELECT name,size_bytes,library_scope FROM visual_assets WHERE id='asset'")).one()==('Original',123,'private')
|
||
|
|
assert connection.scalar(text("SELECT password_hash FROM visual_users WHERE id='owner'"))=='UNCHANGED'
|
||
|
|
inspector=inspect(connection)
|
||
|
|
for name in ['visual_jobs','visual_drafts','visual_workflow_runs','visual_batches']:
|
||
|
|
column=next(c for c in inspector.get_columns(name) if c['name']=='deleted_at')
|
||
|
|
assert column['nullable']
|
||
|
|
assert 'visual_shared_assets' in inspector.get_table_names()
|
||
|
|
from app.schema import check_schema_revision
|
||
|
|
check_schema_revision(connection,{'004'})
|
||
|
|
|
||
|
|
|
||
|
|
def test_v4_reruns_after_partial_ddl(tmp_path):
|
||
|
|
config=Config(str(Path(__file__).parents[1]/'alembic.ini'))
|
||
|
|
path=tmp_path/'partial-v4.sqlite';config.attributes['url']='sqlite+aiosqlite:///'+str(path)
|
||
|
|
command.upgrade(config,'003');engine=create_engine('sqlite:///'+str(path))
|
||
|
|
with engine.begin() as connection:
|
||
|
|
connection.execute(text("ALTER TABLE visual_jobs ADD COLUMN deleted_at DATETIME NULL"))
|
||
|
|
connection.execute(text("ALTER TABLE visual_assets ADD COLUMN library_scope VARCHAR(16) NOT NULL DEFAULT 'private'"))
|
||
|
|
command.upgrade(config,'head')
|
||
|
|
with engine.begin() as connection:
|
||
|
|
assert connection.scalar(text('SELECT version_num FROM alembic_version'))=='004'
|