Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zuul configuration #8

Merged
merged 24 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ cover/
coverage.xml
pylint.txt
unit-tests.xml
pycodestyle.txt
13 changes: 6 additions & 7 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def run_migrations_offline():

"""
url = config.get_main_option("sqlalchemy.url")
context.configure(url=url,
version_table='alembic_version_dird')
context.configure(url=url, version_table='alembic_version_dird')

with context.begin_transaction():
context.run_migrations()
Expand All @@ -47,13 +46,13 @@ def run_migrations_online():

"""
engine = engine_from_config(
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool)
config.get_section(config.config_ini_section),
prefix='sqlalchemy.',
poolclass=pool.NullPool,
)

connection = engine.connect()
context.configure(connection=connection,
version_table='alembic_version_dird')
context.configure(connection=connection, version_table='alembic_version_dird')

try:
with context.begin_transaction():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
down_revision = 'efe763372855'

source_table = sa.sql.table(
'dird_source',
sa.sql.column('extra_fields'),
sa.sql.column('backend'),
'dird_source', sa.sql.column('extra_fields'), sa.sql.column('backend')
)


def upgrade():
op.execute(
source_table
.update()
source_table.update()
.where(source_table.c.backend == 'phonebook')
.values(extra_fields=None)
)


def downgrade():
extra_fields = '''{"db_uri": "postgresql://asterisk:proformatique@localhost/asterisk"}'''
extra_fields = (
'''{"db_uri": "postgresql://asterisk:proformatique@localhost/asterisk"}'''
)
op.execute(
source_table
.update()
source_table.update()
.where(source_table.c.backend == 'phonebook')
.values(extra_fields=extra_fields)
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ def upgrade():
server_default=sa.text('uuid_generate_v4()'),
primary_key=True,
),
sa.Column(
'name',
sa.Text(),
nullable=False,
unique=True,
)
sa.Column('name', sa.Text(), nullable=False, unique=True),
)

op.create_table(
Expand All @@ -45,16 +40,12 @@ def upgrade():
sa.ForeignKey('dird_tenant.uuid', ondelete='CASCADE'),
nullable=False,
),
sa.Column(
'name',
sa.Text(),
nullable=False,
),
sa.Column('name', sa.Text(), nullable=False),
sa.Column(
'display_uuid',
sa.String(36),
sa.ForeignKey('dird_display.uuid', ondelete='SET NULL'),
)
),
)

op.create_table(
Expand All @@ -77,10 +68,7 @@ def upgrade():
sa.ForeignKey('dird_service.uuid', ondelete='CASCADE'),
nullable=False,
),
sa.Column(
'config',
JSON,
),
sa.Column('config', JSON),
)

op.create_table(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '1c6344eac1bd'
down_revision = '38485dfa4e41'

from alembic import op
import sqlalchemy as sa

constraint_name = 'dird_contact_hash_user_uuid'
table_name = 'dird_contact'
column_name = 'hash'


def upgrade():
op.add_column(table_name, sa.Column(column_name,
sa.String(40),
nullable=False))
op.add_column(table_name, sa.Column(column_name, sa.String(40), nullable=False))
op.create_unique_constraint(constraint_name, table_name, [column_name, 'user_uuid'])


Expand Down
42 changes: 27 additions & 15 deletions alembic/versions/1e0397088fa7_remove_duplicate_contact_field_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@

"""

from alembic import op
from sqlalchemy import sql

# revision identifiers, used by Alembic.
revision = '1e0397088fa7'
down_revision = '1e66a71e0352'

import sqlalchemy as sa
from alembic import op
from sqlalchemy import sql

contact_field_table = sql.table('dird_contact_fields',
sql.column('id'),
sql.column('name'),
sql.column('value'),
sql.column('contact_uuid'))
contact_field_table = sql.table(
'dird_contact_fields',
sql.column('id'),
sql.column('name'),
sql.column('value'),
sql.column('contact_uuid'),
)


def upgrade():
Expand All @@ -27,20 +28,31 @@ def upgrade():
if id_contact_field_row.contact_uuid not in known_contact_ids:
known_contact_ids.add(id_contact_field_row.contact_uuid)
else:
query = contact_field_table.delete().where(contact_field_table.c.id == id_contact_field_row.id)
query = contact_field_table.delete().where(
contact_field_table.c.id == id_contact_field_row.id
)
op.get_bind().execute(query)


def purge_divergent_id_contact_fields():
query = contact_field_table.delete().where(sql.and_(contact_field_table.c.name == 'id',
contact_field_table.c.value != contact_field_table.c.contact_uuid))
query = contact_field_table.delete().where(
sql.and_(
contact_field_table.c.name == 'id',
contact_field_table.c.value != contact_field_table.c.contact_uuid,
)
)
op.get_bind().execute(query)


def get_id_contact_field_rows():
id_contact_fields = (sql.select([contact_field_table.c.id, contact_field_table.c.contact_uuid])
.where(sql.and_(contact_field_table.c.name == 'id',
contact_field_table.c.value == contact_field_table.c.contact_uuid)))
id_contact_fields = sql.select(
[contact_field_table.c.id, contact_field_table.c.contact_uuid]
).where(
sql.and_(
contact_field_table.c.name == 'id',
contact_field_table.c.value == contact_field_table.c.contact_uuid,
)
)
return op.get_bind().execute(id_contact_fields)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,27 @@

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '1e66a71e0352'
down_revision = '28e9ff92ed2'

from alembic import op
import sqlalchemy as sa

constraint_name = 'dird_contact_hash_phonebook_id'
table_name = 'dird_contact'


def upgrade():
op.alter_column(table_name, 'user_uuid', nullable=True)
op.add_column(table_name,
sa.Column('phonebook_id',
sa.Integer(),
sa.ForeignKey('dird_phonebook.id', ondelete='CASCADE')))
op.add_column(
table_name,
sa.Column(
'phonebook_id',
sa.Integer(),
sa.ForeignKey('dird_phonebook.id', ondelete='CASCADE'),
),
)
op.create_unique_constraint(constraint_name, table_name, ['hash', 'phonebook_id'])


Expand Down
10 changes: 4 additions & 6 deletions alembic/versions/25e9a6782cac_add_source_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import (
ARRAY,
HSTORE,
JSON,
)
from sqlalchemy.dialects.postgresql import ARRAY, HSTORE, JSON

# revision identifiers, used by Alembic.
revision = '25e9a6782cac'
Expand All @@ -29,7 +25,9 @@ def upgrade():
op.add_column(table_name, sa.Column('first_matched_columns', ARRAY(sa.Text)))
op.add_column(table_name, sa.Column('format_columns', HSTORE))
op.add_column(table_name, sa.Column('extra_fields', JSON))
op.create_unique_constraint('dird_source_tenant_name', table_name, ['tenant_uuid', 'name'])
op.create_unique_constraint(
'dird_source_tenant_name', table_name, ['tenant_uuid', 'name']
)
op.drop_constraint('dird_source_name_key', table_name)


Expand Down
19 changes: 12 additions & 7 deletions alembic/versions/265d68f9c337_add_contact_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@

"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '265d68f9c337'
down_revision = 'd237d33088c6'

from alembic import op
import sqlalchemy as sa

table_name = 'dird_contact'
column_name = 'user_uuid'


def upgrade():
op.add_column(table_name, sa.Column(column_name,
sa.String(38),
sa.ForeignKey('dird_user.xivo_user_uuid', ondelete='CASCADE'),
nullable=False))
op.add_column(
table_name,
sa.Column(
column_name,
sa.String(38),
sa.ForeignKey('dird_user.xivo_user_uuid', ondelete='CASCADE'),
nullable=False,
),
)


def downgrade():
Expand Down
30 changes: 19 additions & 11 deletions alembic/versions/28e9ff92ed2_add_tables_for_the_phonebook_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@

"""

# revision identifiers, used by Alembic.
revision = '28e9ff92ed2'
down_revision = '2caf42314e25'

from alembic import op

from sqlalchemy.schema import Column
from sqlalchemy import (CheckConstraint,
ForeignKey,
Integer,
String,
Text,
UniqueConstraint)
from sqlalchemy import (
CheckConstraint,
ForeignKey,
Integer,
String,
Text,
UniqueConstraint,
)

# revision identifiers, used by Alembic.
revision = '28e9ff92ed2'
down_revision = '2caf42314e25'


def upgrade():
op.create_table(
'dird_tenant',
Column('id', Integer(), primary_key=True),
Column('name', String(255), CheckConstraint("name != ''"), unique=True, nullable=False),
Column(
'name',
String(255),
CheckConstraint("name != ''"),
unique=True,
nullable=False,
),
)
op.create_table(
'dird_phonebook',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

"""

# revision identifiers, used by Alembic.
revision = '2caf42314e25'
down_revision = '4cf41a847a26'

from alembic import op

from sqlalchemy.schema import Column
from sqlalchemy import ForeignKey, String, Text, Integer

# revision identifiers, used by Alembic.
revision = '2caf42314e25'
down_revision = '4cf41a847a26'


def upgrade():
op.create_table(
Expand All @@ -23,9 +23,19 @@ def upgrade():
)
op.create_table(
'dird_favorite',
Column('source_id', Integer(), ForeignKey('dird_source.id', ondelete='CASCADE'), primary_key=True),
Column(
'source_id',
Integer(),
ForeignKey('dird_source.id', ondelete='CASCADE'),
primary_key=True,
),
Column('contact_id', Text(), primary_key=True),
Column('user_uuid', String(38), ForeignKey('dird_user.xivo_user_uuid', ondelete='CASCADE'), primary_key=True),
Column(
'user_uuid',
String(38),
ForeignKey('dird_user.xivo_user_uuid', ondelete='CASCADE'),
primary_key=True,
),
)


Expand Down
Loading