Merge "use common code for migrations"

This commit is contained in:
Jenkins 2014-01-28 12:42:45 +00:00 committed by Gerrit Code Review
commit a536b56e22
5 changed files with 10 additions and 43 deletions

View File

@ -18,23 +18,12 @@
import sqlalchemy as sa
from ceilometer.storage.sqlalchemy import migration
from ceilometer.storage.sqlalchemy import models
_col = 'timestamp'
def _paged(query, size):
offset = 0
while True:
page = query.offset(offset).limit(size).execute()
if page.rowcount <= 0:
# There are no more rows
break
for row in page:
yield row
offset += size
def _convert_data_type(table, col, from_t, to_t, pk_attr='id', index=False):
temp_col_n = 'convert_data_type_temp_col'
# Override column we're going to convert with from_t, since the type we're
@ -49,7 +38,7 @@ def _convert_data_type(table, col, from_t, to_t, pk_attr='id', index=False):
new_col = getattr(table.c, temp_col_n)
query = sa.select([key_attr, orig_col])
for key, value in _paged(query, 1000):
for key, value in migration.paged(query):
table.update().where(key_attr == key)\
.values({temp_col_n: value}).execute()

View File

@ -11,8 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ceilometer.storage.sqlalchemy import migration
from migrate import ForeignKeyConstraint
from sqlalchemy import Column
from sqlalchemy import Integer
@ -21,6 +19,8 @@ from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from ceilometer.storage.sqlalchemy import migration
def upgrade(migrate_engine):
meta = MetaData(bind=migrate_engine)

View File

@ -11,8 +11,6 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from ceilometer.storage.sqlalchemy import migration
from migrate import ForeignKeyConstraint
from sqlalchemy import Column
from sqlalchemy import Integer
@ -22,6 +20,8 @@ from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import UniqueConstraint
from ceilometer.storage.sqlalchemy import migration
def upgrade(migrate_engine):
meta = MetaData(migrate_engine)

View File

@ -18,21 +18,10 @@
import sqlalchemy as sa
from ceilometer.storage.sqlalchemy import migration
from ceilometer.storage.sqlalchemy import models
def _paged(query, size):
offset = 0
while True:
page = query.offset(offset).limit(size).execute()
if page.rowcount <= 0:
# There are no more rows
break
for row in page:
yield row
offset += size
def _convert_data_type(table, col, from_t, to_t, pk_attr='id', index=False):
temp_col_n = 'convert_data_type_temp_col'
# Override column we're going to convert with from_t, since the type we're
@ -47,7 +36,7 @@ def _convert_data_type(table, col, from_t, to_t, pk_attr='id', index=False):
new_col = getattr(table.c, temp_col_n)
query = sa.select([key_attr, orig_col])
for key, value in _paged(query, 1000):
for key, value in migration.paged(query):
table.update().where(key_attr == key)\
.values({temp_col_n: value}).execute()

View File

@ -18,21 +18,10 @@
import sqlalchemy as sa
from ceilometer.storage.sqlalchemy import migration
from ceilometer.storage.sqlalchemy import models
def _paged(query, size):
offset = 0
while True:
page = query.offset(offset).limit(size).execute()
if page.rowcount <= 0:
# There are no more rows
break
for row in page:
yield row
offset += size
def _convert_data_type(table, col, from_t, to_t, pk_attr='id'):
temp_col_n = 'convert_data_type_temp_col'
# Override column we're going to convert with from_t, since the type we're
@ -47,7 +36,7 @@ def _convert_data_type(table, col, from_t, to_t, pk_attr='id'):
new_col = getattr(table.c, temp_col_n)
query = sa.select([key_attr, orig_col])
for key, value in _paged(query, 1000):
for key, value in migration.paged(query):
table.update().where(key_attr == key)\
.values({temp_col_n: value}).execute()