Merge "use common code for migrations"
This commit is contained in:
commit
a536b56e22
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user