def downgrade(migrate_engine): if migrate_engine.name == 'mysql': meta = sa.MetaData(bind=migrate_engine) event = sa.Table('event', meta, autoload=True) _convert_data_type(event, 'generated', models.PreciseTimestamp(), sa.Float(), pk_attr='id', index=True) trait = sa.Table('trait', meta, autoload=True) _convert_data_type(trait, 't_datetime', models.PreciseTimestamp(), sa.Float(), pk_attr='id', index=True)
def upgrade(migrate_engine): meta = sqlalchemy.MetaData(bind=migrate_engine) meter = sqlalchemy.Table('meter', meta, autoload=True) c = sqlalchemy.Column('recorded_at', models.PreciseTimestamp(), default=timeutils.utcnow) meter.create_column(c)
def upgrade(migrate_engine): if migrate_engine.name == 'mysql': meta = sa.MetaData(bind=migrate_engine) meter = sa.Table('meter', meta, autoload=True) _convert_data_type(meter, _col, sa.DateTime(), models.PreciseTimestamp(), pk_attr='id', index=True)
def downgrade(migrate_engine): if migrate_engine.name == 'mysql': meta = sa.MetaData(bind=migrate_engine) for table_name, col_name, pk_attr in to_convert: table = sa.Table(table_name, meta, autoload=True) _convert_data_type(table, col_name, models.PreciseTimestamp(), sa.DateTime(), pk_attr=pk_attr)
def downgrade(migrate_engine): meta = sa.MetaData(bind=migrate_engine) event = sa.Table('event', meta, autoload=True) trait_type = sa.Table( 'trait_type', meta, sa.Column('id', sa.Integer, primary_key=True), sa.Column('desc', sa.String(255)), sa.Column('data_type', sa.Integer), sa.UniqueConstraint('desc', 'data_type', name='tt_unique'), mysql_engine='InnoDB', mysql_charset='utf8', ) trait_type.create() trait = sa.Table( 'trait', meta, sa.Column('id', sa.Integer, primary_key=True), sa.Column('trait_type_id', sa.Integer, sa.ForeignKey(trait_type.c.id)), sa.Column('event_id', sa.Integer, sa.ForeignKey(event.c.id)), sa.Column('t_string', sa.String(255), nullable=True, default=None), sa.Column('t_float', sa.Float(53), nullable=True, default=None), sa.Column('t_int', sa.Integer, nullable=True, default=None), sa.Column('t_datetime', models.PreciseTimestamp(), nullable=True, default=None), sa.Index('ix_trait_t_int', 't_int'), sa.Index('ix_trait_t_string', 't_string'), sa.Index('ix_trait_t_datetime', 't_datetime'), sa.Index('ix_trait_t_float', 't_float'), mysql_engine='InnoDB', mysql_charset='utf8', ) trait.create() for t_name, __, __, col_name, type_id in tables: table = sa.Table(t_name, meta, autoload=True) trait_type.insert().from_select([trait_type.c.desc, trait_type.c.data_type], sa.select([table.c.key, type_id]) .distinct()).execute() trait.insert().from_select([trait.c['event_id'], trait.c['trait_type_id'], trait.c[col_name]], sa.select([table.c.event_id, trait_type.c.id, table.c.value]) .select_from( table.join( trait_type, table.c.key == trait_type.c.desc)) ).execute() table.drop()
def setUp(self): super(PreciseTimestampTest, self).setUp() self._mysql_dialect = self.fake_dialect('mysql') self._postgres_dialect = self.fake_dialect('postgres') self._type = models.PreciseTimestamp() self._date = datetime.datetime(2012, 7, 2, 10, 44)
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import sqlalchemy as sa from ceilometer.storage.sqlalchemy import models tables = [('trait_text', sa.Text, True, 't_string', 1), ('trait_int', sa.Integer, False, 't_int', 2), ('trait_float', sa.Float, False, 't_float', 3), ('trait_datetime', models.PreciseTimestamp(), False, 't_datetime', 4) ] def upgrade(migrate_engine): meta = sa.MetaData(bind=migrate_engine) trait = sa.Table('trait', meta, autoload=True) event = sa.Table('event', meta, autoload=True) trait_type = sa.Table('trait_type', meta, autoload=True) for t_name, t_type, t_nullable, col_name, __ in tables: t_table = sa.Table( t_name, meta, sa.Column('event_id', sa.Integer, sa.ForeignKey(event.c.id),
# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import sqlalchemy as sa from ceilometer.storage.sqlalchemy import models tables = [('trait_text', sa.String(255), True, 't_string', 1), ('trait_int', sa.Integer, False, 't_int', 2), ('trait_float', sa.Float(53), False, 't_float', 3), ('trait_datetime', models.PreciseTimestamp(), False, 't_datetime', 4)] def upgrade(migrate_engine): meta = sa.MetaData(bind=migrate_engine) trait = sa.Table('trait', meta, autoload=True) event = sa.Table('event', meta, autoload=True) trait_type = sa.Table('trait_type', meta, autoload=True) for t_name, t_type, t_nullable, col_name, __ in tables: t_table = sa.Table( t_name, meta, sa.Column('event_id', sa.Integer, sa.ForeignKey(event.c.id), primary_key=True), sa.Column('key', sa.String(255), primary_key=True), sa.Column('value', t_type, nullable=t_nullable),