Пример #1
0
    def migrate_data(self):
        activities_table = table(
            "activities",
            column("id"),
            column("kind"),
            column("summary"),
            column("title"),
            column("description"),
        )

        activities_translation_table = table(
            "activities_translation",
            column("id"),
            column("locale"),
            column("title"),
            column("label"),
            column("summary"),
            column("description"),
        )

        activities = self.connection.execute(
            activities_table.select()).fetchall()
        for activity in activities:
            self.execute(
                activities_translation_table.insert(
                    values={
                        'id': activity.id,
                        'locale': DEFAULT_LOCALE,
                        'title': activity.title,
                        # the label column is new so we use the kind
                        # for existing entries
                        'label': activity.kind,
                        'summary': activity.summary,
                        'description': activity.description
                    }))
Пример #2
0
    def get_existing_id_lookup(self):
        org_role_table = table("org_roles",
                               column('id'),
                               column('organization_id'),
                               column('person_id'),
                               column('function'))

        contact_table = table(
            "contacts",
            column('id'),
            column('former_contact_id'))

        org_contact = aliased(contact_table, alias='org_contact')
        person_contact = aliased(contact_table, alias='person_contact')

        query = self.db_session.query(org_role_table, org_contact, person_contact)
        query = query.join(org_contact,
                           org_role_table.c.organization_id == org_contact.c.id)
        query = query.join(person_contact,
                           org_role_table.c.person_id == person_contact.c.id)

        mapping = {}

        for gever_row in query:
            key = u'{}:{}'.format(gever_row[5], gever_row[7])
            mapping[key] = gever_row[0]

        return mapping
Пример #3
0
 def _str_idx_constraint(m1, m2, op):
     idx_tbl = table("str_idx_%s_%s" % (m1.table.fullname, m1.key),
                     column("s"), column("id"))
     return table(m1.table.fullname, column("rowid")).c.rowid.in_(
         select([idx_tbl.c.id])
             .where(idx_tbl.c.s.op(op)(func.mol_signature(m2)))
             )
Пример #4
0
    def migrate_data(self):
        activities_table = table(
            "activities", column("id"), column("kind"), column("summary"), column("title"), column("description")
        )

        activities_translation_table = table(
            "activities_translation",
            column("id"),
            column("locale"),
            column("title"),
            column("label"),
            column("summary"),
            column("description"),
        )

        activities = self.connection.execute(activities_table.select()).fetchall()
        for activity in activities:
            self.execute(
                activities_translation_table.insert(
                    values={
                        "id": activity.id,
                        "locale": DEFAULT_LOCALE,
                        "title": activity.title,
                        # the label column is new so we use the kind
                        # for existing entries
                        "label": activity.kind,
                        "summary": activity.summary,
                        "description": activity.description,
                    }
                )
            )
Пример #5
0
    def get_existing_id_lookup(self):
        org_role_table = table("org_roles", column('id'),
                               column('organization_id'), column('person_id'),
                               column('function'))

        contact_table = table("contacts", column('id'),
                              column('former_contact_id'))

        org_contact = aliased(contact_table, alias='org_contact')
        person_contact = aliased(contact_table, alias='person_contact')

        query = self.db_session.query(org_role_table, org_contact,
                                      person_contact)
        query = query.join(
            org_contact, org_role_table.c.organization_id == org_contact.c.id)
        query = query.join(person_contact,
                           org_role_table.c.person_id == person_contact.c.id)

        mapping = {}

        for gever_row in query:
            key = u'{}:{}'.format(gever_row[5], gever_row[7])
            mapping[key] = gever_row[0]

        return mapping
def _migrate_network_segments(engine):
    # Code similar to migrate_to_ml2.BaseMigrateToMl2.migrate_network_segments
    source_table = sa_expr.table('hyperv_network_bindings')
    source_segments = engine.execute(
        sa_expr.select(['*'], from_obj=source_table))
    ml2_segments = [dict(x) for x in source_segments]
    for segment in ml2_segments:
        _migrate_segment_dict(segment)

    if ml2_segments:
        ml2_network_segments = sa_expr.table('ml2_network_segments')
        op.execute(ml2_network_segments.insert(), ml2_segments)
def _migrate_network_segments(engine):
    # Code similar to migrate_to_ml2.BaseMigrateToMl2.migrate_network_segments
    source_table = sa_expr.table('hyperv_network_bindings')
    source_segments = engine.execute(
        sa_expr.select(['*'], from_obj=source_table))
    ml2_segments = [dict(x) for x in source_segments]
    for segment in ml2_segments:
        _migrate_segment_dict(segment)

    if ml2_segments:
        ml2_network_segments = sa_expr.table('ml2_network_segments')
        op.execute(ml2_network_segments.insert(), ml2_segments)
def upgrade(active_plugins=None, options=None):
    op.add_column('refreshtokens',
                  sa.Column('access_token_id', sa.Integer(), nullable=False))
    op.drop_table('access_refresh_tokens')

    # Delete all refresh and access tokens, as the relationship is no longer
    # valid.
    bind = op.get_bind()

    refresh_table = table('refreshtokens')
    access_table = table('accesstokens')

    bind.execute(refresh_table.delete())
    bind.execute(access_table.delete())
Пример #9
0
    def insert_workflow_state_data(self):
        agenda_items_table = table('agendaitems', column('id'),
                                   column('workflow_state'),
                                   column('meeting_id'))
        self.execute(
            agenda_items_table.update().values(workflow_state='pending'))

        meeting_table = table('meetings', column('id'),
                              column('workflow_state'))

        for meeting in self.execute(meeting_table.select().where(
                meeting_table.c.workflow_state == 'closed')):

            self.execute(agenda_items_table.update().where(
                agenda_items_table.c.meeting_id == meeting.id).values(
                    workflow_state='decided'))
Пример #10
0
    def migrate_data(self):
        meeting_table = table(
            "meetings",
            column("id"),
            column("date"),
            column("start_time"),
            column("end_time"),
            column("start"),
            column("end"),
        )

        meetings = self.connection.execute(meeting_table.select()).fetchall()
        for meeting in meetings:
            date = meeting.date
            start_time = meeting.start_time or datetime.min.time()
            end_time = meeting.end_time or datetime.min.time()

            start = datetime.combine(date, start_time)
            end = datetime.combine(date, end_time)

            self.execute(
                meeting_table.update()
                .values(start=start, end=end)
                .where(meeting_table.columns.id == meeting.id)
            )
Пример #11
0
def upgrade(active_plugins=None, options=None):
    bind = op.get_bind()

    branches = list(bind.execute(
        sa.select(columns=['id', 'name', 'project_id'],
                  from_obj=sa.Table('branches', sa.MetaData()))))

    projects = list(bind.execute(
        sa.select(columns=['id'], from_obj=sa.Table('projects',
                                                    sa.MetaData()))))
    if len(projects) > 0:
        branch_dict = {}

        for branch in branches:
            branch_dict[(branch['project_id'], branch['name'])] = branch['id']

        tasks_table = table(
            'tasks',
            sa.Column('project_id', sa.Integer(), nullable=True),
            sa.Column('branch_id', sa.Integer(), nullable=True),
        )

        bind.execute(tasks_table.update().
                     where(tasks_table.c.project_id.is_(None)).
                     values(project_id=projects[0].id))

        for project in projects:
            bind.execute(
                tasks_table.update().
                where(tasks_table.c.project_id == project['id']).
                values(branch_id=branch_dict[(project['id'], "master")])
            )
Пример #12
0
    def test_sql_with_for_update(self):
        table1 = table("mytable", column("myid"), column("name"),
                       column("description"))

        self.assert_compile(
            table1.select().with_for_update(),
            "SELECT mytable.myid, mytable.name, mytable.description "
            "FROM mytable FOR UPDATE",
        )

        self.assert_compile(
            table1.select().with_for_update(nowait=True),
            "SELECT mytable.myid, mytable.name, mytable.description "
            "FROM mytable FOR UPDATE NOWAIT",
        )

        self.assert_compile(
            table1.select().with_for_update(read=True),
            "SELECT mytable.myid, mytable.name, mytable.description "
            "FROM mytable FOR SHARE LOCK",
        )

        self.assert_compile(
            table1.select().with_for_update(skip_locked=True),
            "SELECT mytable.myid, mytable.name, mytable.description "
            "FROM mytable FOR UPDATE IGNORE LOCKED",
        )
def upgrade():
    op.create_table(
        "planet_name", sa.Column("id", sa.Integer, primary_key=True), sa.Column("name", sa.String, nullable=False)
    )
    op.create_unique_constraint("uc_planet_name", "planet_name", ["name"])
    op.add_column(
        "libration", sa.Column("first_planet_name_id", sa.Integer, sa.ForeignKey("planet_name.id"), nullable=True)
    )
    op.add_column(
        "libration", sa.Column("second_planet_name_id", sa.Integer, sa.ForeignKey("planet_name.id"), nullable=True)
    )

    planet_name_table = table("planet_name", column("id", sa.Integer), column("name", sa.String))
    op.bulk_insert(
        planet_name_table,
        [
            {"id": 9, "name": "PLUTO"},
            {"id": 8, "name": "NEPTUNE"},
            {"id": 7, "name": "URANUS"},
            {"id": 6, "name": "SATURN"},
            {"id": 5, "name": "JUPITER"},
            {"id": 4, "name": "MARS"},
            {"id": 3, "name": "EARTHMOO"},
            {"id": 2, "name": "VENUS"},
            {"id": 1, "name": "MERCURY"},
        ],
    )

    op.execute("UPDATE libration SET first_planet_name_id=5, second_planet_name_id=6")
Пример #14
0
def upgrade(active_plugins=None, options=None):
    bind = op.get_bind()

    branches = list(
        bind.execute(
            sa.select(columns=['id', 'name', 'project_id'],
                      from_obj=sa.Table('branches', sa.MetaData()))))

    projects = list(
        bind.execute(
            sa.select(columns=['id'],
                      from_obj=sa.Table('projects', sa.MetaData()))))
    if len(projects) > 0:
        branch_dict = {}

        for branch in branches:
            branch_dict[(branch['project_id'], branch['name'])] = branch['id']

        tasks_table = table(
            'tasks',
            sa.Column('project_id', sa.Integer(), nullable=True),
            sa.Column('branch_id', sa.Integer(), nullable=True),
        )

        bind.execute(tasks_table.update().where(
            tasks_table.c.project_id.is_(None)).values(
                project_id=projects[0].id))

        for project in projects:
            bind.execute(tasks_table.update().where(
                tasks_table.c.project_id == project['id']).values(
                    branch_id=branch_dict[(project['id'], "master")]))
Пример #15
0
 def get_existing_id_lookup(self):
     contact_table = table(
         "contacts",
         column('id'),
         column('former_contact_id'))
     stmt = select([contact_table.c.former_contact_id, contact_table.c.id])
     return {key: value for (key, value) in self.db_session.execute(stmt)}
def upgrade(active_plugins=None, options=None):
    op.add_column(
        'branches',
        sa.Column('restricted', sa.Boolean(), default=False)
    )

    bind = op.get_bind()

    branches_table = table(
        'branches',
        sa.Column('name', sa.String(100), nullable=True),
        sa.Column('restricted', sa.Boolean(), default=False)
    )

    bind.execute(
        branches_table.update().where(
            branches_table.c.name != 'master'
        ).values(restricted=False)
    )

    bind.execute(
        branches_table.update().where(
            branches_table.c.name == 'master'
        ).values(restricted=True)
    )
Пример #17
0
    def migrate(self):
        self.add_userid_column()
        self.migrate_data()
        self.remove_watcherid_column()
        self.make_userid_column_required()

        self.notifications_table = table("notifications", column("id"), column("activity_id"), column("watcher_id"))
Пример #18
0
    def add_meeting_sequence_to_period(self):
        self.op.add_column("periods", Column("meeting_sequence_number", Integer, nullable=True))

        periods_table = table("periods", column("id"), column("meeting_sequence_number"))
        self.execute(periods_table.update().values(meeting_sequence_number=0))

        self.op.alter_column("periods", "meeting_sequence_number", existing_type=Integer, nullable=False)
Пример #19
0
def downgrade():
    op.create_table(
        'planet_name',
        sa.Column('id', sa.Integer, primary_key=True),
        sa.Column('name', sa.String, nullable=False),
    )
    op.create_unique_constraint('uc_planet_name', 'planet_name', ['name'])
    op.add_column('libration', sa.Column(
        'first_planet_name_id', sa.Integer, sa.ForeignKey('planet_name.id'), nullable=True
    ))
    op.add_column('libration', sa.Column(
        'second_planet_name_id', sa.Integer, sa.ForeignKey('planet_name.id'), nullable=True
    ))

    planet_name_table = table('planet_name', column('id', sa.Integer), column('name', sa.String))
    op.bulk_insert(planet_name_table, [
        {'id': 9, 'name': 'PLUTO'},
        {'id': 8, 'name': 'NEPTUNE'},
        {'id': 7, 'name': 'URANUS'},
        {'id': 6, 'name': 'SATURN'},
        {'id': 5, 'name': 'JUPITER'},
        {'id': 4, 'name': 'MARS'},
        {'id': 3, 'name': 'EARTHMOO'},
        {'id': 2, 'name': 'VENUS'},
        {'id': 1, 'name': 'MERCURY'},
    ])

    op.execute('UPDATE libration SET first_planet_name_id=5, second_planet_name_id=6')

    op.alter_column('libration', 'first_planet_name_id', nullable=False)
    op.alter_column('libration', 'second_planet_name_id', nullable=False)
    op.drop_constraint('libration_resonance_id_key', 'libration')
    op.create_unique_constraint('uc_resonance_planet_names', 'libration',
                                ['resonance_id', 'first_planet_name_id', 'second_planet_name_id'])
Пример #20
0
class AddMissingForwardingAddedNotificationDefault(SchemaMigration):
    """Add missing forwarding-added notification_default.
    """

    defaults_table = table(
        "notification_defaults",
        column("id"),
        column("kind"),
        column("mail_notification_roles"),
        column("badge_notification_roles")
    )

    def migrate(self):
        query = self.defaults_table.select().where(
            self.defaults_table.c.kind == 'forwarding-added')
        forwarding_added = self.connection.execute(query).fetchall()

        if not len(forwarding_added):
            self.insert_forwarding_added_default()

    def insert_forwarding_added_default(self):
        values = {
            'kind': 'forwarding-added',
            'mail_notification_roles': json.dumps([TASK_RESPONSIBLE_ROLE]),
            'badge_notification_roles': json.dumps(
                [TASK_RESPONSIBLE_ROLE, TASK_ISSUER_ROLE])}

        seq = Sequence('notification_defaults_id_seq')
        if self.supports_sequences:
            values['id'] = self.execute(seq)

        self.execute(self.defaults_table.insert().values(**values))
def _migrate_port_bindings(engine):
    # Code similar to migrate_to_ml2.BaseMigrateToMl2.migrate_port_bindings
    port_segment_map = _get_port_segment_map(engine)
    port_binding_ports = sa_expr.table('portbindingports')
    source_bindings = engine.execute(
        sa_expr.select(['*'], from_obj=port_binding_ports))
    ml2_bindings = [dict(x) for x in source_bindings]
    for binding in ml2_bindings:
        binding['vif_type'] = portbindings.VIF_TYPE_HYPERV
        binding['driver'] = HYPERV
        segment = port_segment_map.get(binding['port_id'])
        if segment:
            binding['segment'] = segment
    if ml2_bindings:
        ml2_port_bindings = sa_expr.table('ml2_port_bindings')
        op.execute(ml2_port_bindings.insert(), ml2_bindings)
Пример #22
0
    def raise_column_length(self):

        # add new column with the new size
        self.op.add_column(
            'favorites',
            Column('tmp_plone_uid', String(UID_LENGTH)))

        # migrate_data
        _table = table(
            'favorites',
            column("id"),
            column('plone_uid'),
            column('tmp_plone_uid'))

        items = self.connection.execute(_table.select()).fetchall()
        for item in items:
            self.execute(
                _table.update()
                .values(tmp_plone_uid=item.plone_uid)
                .where(_table.columns.id == item.id)
            )

        # drop old column
        self.op.drop_column('favorites', 'plone_uid')

        # rename new column
        self.op.alter_column('favorites',
                             'tmp_plone_uid',
                             new_column_name='plone_uid')
def _migrate_port_bindings(engine):
    # Code similar to migrate_to_ml2.BaseMigrateToMl2.migrate_port_bindings
    port_segment_map = _get_port_segment_map(engine)
    port_binding_ports = sa_expr.table('portbindingports')
    source_bindings = engine.execute(
        sa_expr.select(['*'], from_obj=port_binding_ports))
    ml2_bindings = [dict(x) for x in source_bindings]
    for binding in ml2_bindings:
        binding['vif_type'] = portbindings.VIF_TYPE_HYPERV
        binding['driver'] = HYPERV
        segment = port_segment_map.get(binding['port_id'])
        if segment:
            binding['segment'] = segment
    if ml2_bindings:
        ml2_port_bindings = sa_expr.table('ml2_port_bindings')
        op.execute(ml2_port_bindings.insert(), ml2_bindings)
Пример #24
0
def upgrade(active_plugins=None, options=None):
    op.create_table(
        "story_types",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column("created_at", sa.DateTime(), nullable=True),
        sa.Column("updated_at", sa.DateTime(), nullable=True),
        sa.Column("name", sa.String(50), nullable=True),
        sa.Column("icon", sa.String(50), nullable=True),
        sa.Column("restricted", sa.Boolean(), default=False),
        sa.Column("private", sa.Boolean(), default=False),
        sa.Column("visible", sa.Boolean(), default=True),
        sa.PrimaryKeyConstraint("id"),
        mysql_engine=MYSQL_ENGINE,
        mysql_charset=MYSQL_CHARSET,
    )

    bind = op.get_bind()

    story_types_table = table(
        "story_types",
        sa.Column("name", sa.String(50), nullable=True),
        sa.Column("icon", sa.String(50), nullable=True),
        sa.Column("restricted", sa.Boolean(), default=False),
        sa.Column("private", sa.Boolean(), default=False),
        sa.Column("visible", sa.Boolean(), default=True),
    )

    bind.execute(story_types_table.insert().values(name="bug", icon="fa-bug"))

    bind.execute(story_types_table.insert().values(name="feature", icon="fa-lightbulb-o", restricted=True))

    bind.execute(story_types_table.insert().values(name="private_vulnerability", icon="fa-lock", private=True))

    bind.execute(story_types_table.insert().values(name="public_vulnerability", icon="fa-bomb", visible=False))
Пример #25
0
 def __init__(self, data: List[str], asteroid_num: int, planets: Tuple[str]):
     super(ThreeBodyResonanceFactory, self).__init__(planets)
     self._bodies = dict(
         first_body={
             'name': self._planets[0],
             LONG_COEFF: int(data[0]),
             PERI_COEFF: int(data[3])
         },
         second_body={
             'name': self._planets[1],
             LONG_COEFF: int(data[1]),
             PERI_COEFF: int(data[4])
         },
         small_body={
             'name': 'A%s' % asteroid_num,
             LONG_COEFF: int(data[2]),
             PERI_COEFF: int(data[5]),
             'axis': float(data[6])
         }
     )
     self._body_tables = dict(
         first_body=alias(_planet_table, 'first_body'),
         second_body=alias(_planet_table, 'second_body'),
         small_body=alias(_asteroid_table, 'small_body')
     )
     self._resonance_cls = ThreeBodyResonance
     self._resonance_table = table(self._resonance_cls.__tablename__, *self._columns)
Пример #26
0
    def create_default_periods_for_committees(self):
        self.committees_table = table("committees", column("id"))
        self.date = date.today()
        self.end_of_year = date(self.date.year, 12, 31)

        for committee in self.connection.execute(
                self.committees_table.select()).fetchall():
            self.create_initial_period(committee)
Пример #27
0
    def create_default_periods_for_committees(self):
        self.committees_table = table("committees", column("id"))
        self.date = date.today()
        self.end_of_year = date(self.date.year, 12, 31)

        for committee in self.connection.execute(
                self.committees_table.select()).fetchall():
            self.create_initial_period(committee)
Пример #28
0
    def insert_default_value(self, tablename):
        contact_table = table(
            tablename,
            column("id"),
            column("is_active"))

        self.connection.execute(
            contact_table.update().values(is_active=True))
Пример #29
0
    def get_existing_id_lookup(self):
        url_table = table(
            "urls", column('id'), column('label'), column('contact_id'))

        contact_table = table(
            "contacts",
            column('id'), column('former_contact_id'))

        stmt = select([
            url_table.c.id, url_table.c.label, url_table.c.contact_id,
            contact_table.c.former_contact_id])
        stmt = stmt.select_from(
            join(url_table, contact_table,
                 url_table.c.contact_id == contact_table.c.id))

        return {self.get_identifier(gever_row): gever_row.id
                for gever_row in self.db_session.execute(stmt)}
Пример #30
0
    def before_execute(self):
        used_columns = self.get_used_columns()
        if not any(var in used_columns for var in reports_specials):
            return

        report_table = table('reports')
        self.add_join(report_table, 'id', 'adv_id')
        if not self.group_by:
            self.set_group_by([sql('id')])
Пример #31
0
    def insert_placeholders(self):
        """Fill empty MailAddress with a placeholder.
        """
        mailaddress_table = table('mail_addresses', column("id"),
                                  column("address"))

        self.execute(mailaddress_table.update().values(
            address=EMPTY_ADDRESS_PLACEHOLDER).where(
                mailaddress_table.columns.address == None))
Пример #32
0
    def get_watcherid_userid_mapping(self):
        mapping = {}
        watchers_table = table("watchers", column("id"), column("user_id"))

        watchers = self.connection.execute(watchers_table.select()).fetchall()
        for watcher in watchers:
            mapping[watcher.id] = watcher.user_id

        return mapping
Пример #33
0
    def get_watcherid_userid_mapping(self):
        mapping = {}
        watchers_table = table("watchers", column("id"), column("user_id"))

        watchers = self.connection.execute(watchers_table.select()).fetchall()
        for watcher in watchers:
            mapping[watcher.id] = watcher.user_id

        return mapping
Пример #34
0
def view(name, metadata, selectable):
    t = table(name)

    for c in selectable.c:
        c._make_proxy(t)

    CreateView(name, selectable).execute_at('after-create', metadata)
    DropView(name).execute_at('before-drop', metadata)
    return t
Пример #35
0
    def initialize(cls, url, initialize_data=True, initialize_schema=True):
        """Initialize the database.

        This includes the schema, the materialized views, the custom
        functions, and the initial content.
        """
        if url in cls.engine_for_url:
            engine = cls.engine_for_url[url]
            return engine, engine.connect()

        engine = cls.engine(url)
        if initialize_schema:
            cls.initialize_schema(engine)
        connection = engine.connect()

        # Check if the recursive equivalents function exists already.
        query = select(
            [literal_column('proname')]
        ).select_from(
            table('pg_proc')
        ).where(
            literal_column('proname')=='fn_recursive_equivalents'
        )
        result = connection.execute(query)
        result = list(result)

        # If it doesn't, create it.
        if not result and initialize_data:
            resource_file = os.path.join(
                cls.resource_directory(), cls.RECURSIVE_EQUIVALENTS_FUNCTION
            )
            if not os.path.exists(resource_file):
                raise IOError("Could not load recursive equivalents function from %s: file does not exist." % resource_file)
            sql = open(resource_file).read()
            connection.execute(sql)

        if initialize_data:
            session = Session(connection)
            cls.initialize_data(session)

        if connection:
            connection.close()

        if initialize_schema and initialize_data:
            # Only cache the engine if all initialization has been performed.
            #
            # Some pieces of code (e.g. the script that runs
            # migrations) have a legitimate need to bypass some of the
            # initialization, but normal operation of the site
            # requires that everything be initialized.
            #
            # Until someone tells this method to initialize
            # everything, we can't short-circuit this method with a
            # cache.
            cls.engine_for_url[url] = engine
        return engine, engine.connect()
Пример #36
0
    def insert_default_modified(self):
        """Insert time of migration as last modified timestamp."""

        meeting_table = table(
            'meetings',
            column('id'),
            column('modified'),
        )

        self.execute(meeting_table.update().values(modified=utcnow_tz_aware()))
Пример #37
0
    def get_existing_id_lookup(self):
        address_table = table("addresses", column('id'), column('label'),
                              column('contact_id'))

        contact_table = table("contacts", column('id'),
                              column('former_contact_id'))

        stmt = select([
            address_table.c.id, address_table.c.label,
            address_table.c.contact_id, contact_table.c.former_contact_id
        ])
        stmt = stmt.select_from(
            join(address_table, contact_table,
                 address_table.c.contact_id == contact_table.c.id))

        return {
            self.get_identifier(gever_row): gever_row.id
            for gever_row in self.db_session.execute(stmt)
        }
Пример #38
0
def add_admin_user():
    stmt = table('users',
            column('username'),
            column('_password_hash')).insert().\
                values\
                  (
                    username=sa.bindparam('username'),
                    _password_hash=sa.bindparam('_password_hash'),
                  )
    op.get_bind().execute(stmt,[dict(username='******',_password_hash=pw('admin'))])
Пример #39
0
    def insert_placeholders(self):
        """Fill empty phone_number with a placeholder.
        """
        phonenumbers_table = table('phonenumbers',
                                  column("id"),
                                  column("phone_number"))

        self.execute(phonenumbers_table.update()
                     .values(phone_number=EMPTY_PHONE_NUMBER_PLACEHOLDER)
                     .where(phonenumbers_table.columns.phone_number == None))
Пример #40
0
    def insert_default_modified(self):
        """Insert time of migration as last modified timestamp."""

        meeting_table = table(
            'meetings',
            column('id'),
            column('modified'),
        )

        self.execute(meeting_table.update().values(modified=utcnow_tz_aware()))
Пример #41
0
    def insert_placeholders(self):
        """Fill empty MailAddress with a placeholder.
        """
        mailaddress_table = table('mail_addresses',
                                  column("id"),
                                  column("address"))

        self.execute(mailaddress_table.update()
                     .values(address=EMPTY_ADDRESS_PLACEHOLDER)
                     .where(mailaddress_table.columns.address == None))
Пример #42
0
    def insert_workflow_state_data(self):
        agenda_items_table = table(
            'agendaitems',
            column('id'), column('workflow_state'), column('meeting_id'))
        self.execute(
            agenda_items_table.update().values(workflow_state='pending'))

        meeting_table = table('meetings',
                              column('id'), column('workflow_state'))

        for meeting in self.execute(
                meeting_table
                .select()
                .where(meeting_table.c.workflow_state == 'closed')):

            self.execute(agenda_items_table
                         .update()
                         .where(agenda_items_table.c.meeting_id == meeting.id)
                         .values(workflow_state='decided'))
Пример #43
0
    def insert_placeholders(self):
        """Fill empty URLs with a placeholder.
        """
        url_table = table('urls',
                          column("id"),
                          column("url"))

        self.execute(url_table.update()
                     .values(url=EMPTY_URL_PLACEHOLDER)
                     .where(url_table.columns.url == None))
Пример #44
0
    def migrate_data(self):
        """Temporarily insert placeholders as repository_folder_title,
        the real value will be inserted by the 4633 upgradestep.
        """
        default_language = get_preferred_language_code()

        proposal_table = table("proposals", column("id"), column("repository_folder_title"), column("language"))

        self.execute(proposal_table.update().values(repository_folder_title=u"-"))
        self.execute(proposal_table.update().values(language=default_language))
Пример #45
0
    def migrate(self):
        # This upgrade runs only when no content has been created.
        # This assumption holds because this will be the first "productive"
        # release of opengever.meeting.

        meeting_table = table("meetings", column("id"))
        meetings = self.connection.execute(meeting_table.select()).fetchall()
        assert len(meetings) == 0, "runs only for empty meeting-tables"

        self.add_dossier_columns()
Пример #46
0
    def migrate_data(self):
        """Temporarily insert placeholders as dossier_reference_numbers,
        the real value will be inserted by the 4603 upgradestep.
        """
        proposal_table = table("proposals",
                               column("id"),
                               column("dossier_reference_number"))

        self.execute(
            proposal_table.update().values(dossier_reference_number=u'-'))
Пример #47
0
    def migrate(self):
        # This upgrade runs only when no content has been created.
        # This assumption holds because this will be the first "productive"
        # release of opengever.meeting.

        meeting_table = table("meetings", column("id"))
        meetings = self.connection.execute(meeting_table.select()).fetchall()
        assert len(meetings) == 0, "runs only for empty meeting-tables"

        self.add_dossier_columns()
Пример #48
0
    def add_badge_column(self):
        self.op.add_column('notifications',
                           Column('is_badge', Boolean, default=False))

        notifications_table = table(
            "notifications",
            column("id"),
            column("is_badge"),
        )

        self.execute(notifications_table.update().values(is_badge=True))
Пример #49
0
    def migrate_data_oracle(self):
        """Because oracle does not support the Time datatype.
        We add a special handling to the 4200 upgradestep (AddMeetingTable)
        which creates Datetime fields instead of Time,
        therefore it's not possible to migrate date from the existing table.
        But we could presume, that there is not content created since then.
        """

        meeting_table = table("meetings", column("id"))
        meetings = self.connection.execute(meeting_table.select()).fetchall()
        assert len(meetings) == 0
Пример #50
0
    def migrate(self):
        self.add_userid_column()
        self.migrate_data()
        self.remove_watcherid_column()
        self.make_userid_column_required()

        self.notifications_table = table(
            "notifications",
            column("id"),
            column("activity_id"),
            column("watcher_id"),
        )
Пример #51
0
    def insert_badge_icon_settings(self):
        """Enable badge notification for all existing settings.
        """

        defaults_table = table(
            "notification_defaults",
            column("id"),
            column("badge_notification_roles"),
        )

        self.execute(defaults_table.update().values(
            badge_notification_roles=BADGE_NOTIFICATION_DEFAULT))
Пример #52
0
    def initialize(cls, url, initialize_data=True, initialize_schema=True):
        """Initialize the database.

        This includes the schema, the custom functions, and the
        initial content.
        """
        if url in cls.engine_for_url:
            engine = cls.engine_for_url[url]
            return engine, engine.connect()

        engine = cls.engine(url)
        if initialize_schema:
            cls.initialize_schema(engine)
        connection = engine.connect()

        # Check if the recursive equivalents function exists already.
        query = (select([literal_column("proname")]).select_from(
            table("pg_proc")).where(
                literal_column("proname") == "fn_recursive_equivalents"))
        result = connection.execute(query)
        result = list(result)

        # If it doesn't, create it.
        if not result and initialize_data:
            resource_file = os.path.join(cls.resource_directory(),
                                         cls.RECURSIVE_EQUIVALENTS_FUNCTION)
            if not os.path.exists(resource_file):
                raise IOError(
                    "Could not load recursive equivalents function from %s: file does not exist."
                    % resource_file)
            sql = open(resource_file).read()
            connection.execute(sql)

        if initialize_data:
            session = Session(connection)
            cls.initialize_data(session)

        if connection:
            connection.close()

        if initialize_schema and initialize_data:
            # Only cache the engine if all initialization has been performed.
            #
            # Some pieces of code (e.g. the script that runs
            # migrations) have a legitimate need to bypass some of the
            # initialization, but normal operation of the site
            # requires that everything be initialized.
            #
            # Until someone tells this method to initialize
            # everything, we can't short-circuit this method with a
            # cache.
            cls.engine_for_url[url] = engine
        return engine, engine.connect()
Пример #53
0
    def get_contact_mapping(self):
        if not self._contact_mapping:
            contact_table = table("contacts", column('id'),
                                  column('former_contact_id'))
            stmt = select(
                [contact_table.c.former_contact_id, contact_table.c.id])
            self._contact_mapping = {
                key: value
                for (key, value) in self.db_session.execute(stmt)
            }

        return self._contact_mapping
Пример #54
0
    def add_decision_sequence_to_period(self):
        self.op.add_column(
            'periods',
            Column('decision_sequence_number', Integer, nullable=True))

        periods_table = table('periods', column('id'),
                              column('decision_sequence_number'))
        self.execute(periods_table.update().values(decision_sequence_number=0))

        self.op.alter_column('periods',
                             'decision_sequence_number',
                             existing_type=Integer,
                             nullable=False)
Пример #55
0
    def migrate_data(self):
        """Temporarily insert placeholders as repository_folder_title,
        the real value will be inserted by the 4633 upgradestep.
        """
        default_language = get_preferred_language_code()

        proposal_table = table("proposals", column("id"),
                               column("repository_folder_title"),
                               column("language"))

        self.execute(
            proposal_table.update().values(repository_folder_title=u'-'))
        self.execute(proposal_table.update().values(language=default_language))