~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/storage/sqlalchemy/migrate_repo/versions/024_event_use_floatingprecision.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2014-03-06 14:44:28 UTC
  • mto: (28.1.1 utopic-proposed) (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20140306144428-rvphsh4igwyulzf0
Tags: upstream-2014.1~b3
ImportĀ upstreamĀ versionĀ 2014.1~b3

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
import sqlalchemy as sa
20
20
 
 
21
from ceilometer.storage.sqlalchemy import migration
21
22
from ceilometer.storage.sqlalchemy import models
22
23
 
23
24
 
24
 
def _paged(query, size):
25
 
    offset = 0
26
 
    while True:
27
 
        page = query.offset(offset).limit(size).execute()
28
 
        if page.rowcount <= 0:
29
 
            # There are no more rows
30
 
            break
31
 
        for row in page:
32
 
            yield row
33
 
        offset += size
34
 
 
35
 
 
36
25
def _convert_data_type(table, col, from_t, to_t, pk_attr='id', index=False):
37
26
    temp_col_n = 'convert_data_type_temp_col'
38
27
    # Override column we're going to convert with from_t, since the type we're
47
36
    new_col = getattr(table.c, temp_col_n)
48
37
 
49
38
    query = sa.select([key_attr, orig_col])
50
 
    for key, value in _paged(query, 1000):
 
39
    for key, value in migration.paged(query):
51
40
        table.update().where(key_attr == key)\
52
41
            .values({temp_col_n: value}).execute()
53
42