Eliminate deprecation warning in db

Use ``func.count()`` expression instead of ``Table.count()``
to remove deprecation warning in migration script.

Change-Id: I2ce26c14cf5aaa125a3744494931a8981589a5a4
This commit is contained in:
TommyLike 2017-04-14 14:27:24 +08:00
parent 4007618092
commit 0428ef2a29
1 changed files with 3 additions and 4 deletions

View File

@ -13,7 +13,7 @@
import datetime
from sqlalchemy import Boolean, Column, DateTime, Integer
from sqlalchemy import ForeignKey, MetaData, String, Table
from sqlalchemy import ForeignKey, MetaData, String, Table, func, select
# Default number of quota groups. We should not read from config file.
DEFAULT_QUOTA_GROUPS = 10
@ -80,9 +80,8 @@ def upgrade(migrate_engine):
# Add group quota data into DB.
quota_classes = Table('quota_classes', meta, autoload=True)
rows = (quota_classes.count().
where(quota_classes.c.resource == 'groups').
execute().scalar())
rows = select([func.count()]).select_from(quota_classes).where(
quota_classes.c.resource == 'groups').execute().scalar()
# Do not add entries if there are already 'groups' entries.
if rows: