Merge "Refine migration query added with CI change"
This commit is contained in:
commit
a77ca91133
@ -10,7 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sqlalchemy import Column, Enum, Index, MetaData, Table, select, not_
|
||||
from sqlalchemy import Column, Enum, Index, MetaData, Table, select, not_, and_
|
||||
from sqlalchemy.engine import reflection
|
||||
|
||||
|
||||
@ -37,10 +37,10 @@ def upgrade(migrate_engine):
|
||||
images.update().values(visibility='private').where(
|
||||
not_(images.c.is_public)).execute()
|
||||
# NOTE(dharinic): Identify 'shared' images from the above
|
||||
images.update().values(visibility='shared').where(
|
||||
images.c.visibility != 'public' and images.c.id.in_(select(
|
||||
images.update().values(visibility='shared').where(and_(
|
||||
images.c.visibility == 'private', images.c.id.in_(select(
|
||||
[image_members.c.image_id]).distinct().where(
|
||||
not_(image_members.c.deleted)))).execute()
|
||||
not_(image_members.c.deleted))))).execute()
|
||||
|
||||
insp = reflection.Inspector.from_engine(migrate_engine)
|
||||
for index in insp.get_indexes('images'):
|
||||
|
@ -157,6 +157,6 @@ INSERT INTO images (
|
||||
WHERE is_public=0;
|
||||
|
||||
UPDATE images SET visibility='private' WHERE visibility='shared';
|
||||
UPDATE images SET visibility='shared' WHERE visibility <> 'public' AND id IN (SELECT DISTINCT image_id FROM image_members WHERE deleted != 1);
|
||||
UPDATE images SET visibility='shared' WHERE visibility='private' AND id IN (SELECT DISTINCT image_id FROM image_members WHERE deleted != 1);
|
||||
|
||||
DROP TABLE images_backup;
|
||||
|
@ -1540,6 +1540,7 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
can_share=True,
|
||||
id=45)
|
||||
image_members.insert().values(temp).execute()
|
||||
|
||||
# adding an image member, but marking it deleted,
|
||||
# for testing 'private' visibility
|
||||
temp = dict(deleted=True,
|
||||
@ -1550,6 +1551,16 @@ class MigrationsMixin(test_migrations.WalkVersionsMixin):
|
||||
id=451)
|
||||
image_members.insert().values(temp).execute()
|
||||
|
||||
# adding an active image member for the 'public' image,
|
||||
# to test it remains public regardless.
|
||||
temp = dict(deleted=False,
|
||||
created_at=now,
|
||||
image_id='public_id',
|
||||
member='fake_member_450',
|
||||
can_share=True,
|
||||
id=450)
|
||||
image_members.insert().values(temp).execute()
|
||||
|
||||
def _check_045(self, engine, data):
|
||||
# check that after migration, 'visbility' column is introduced
|
||||
images = db_utils.get_table(engine, 'images')
|
||||
|
Loading…
Reference in New Issue
Block a user