Skip to content

Commit

Permalink
Add teams and organisations backend
Browse files Browse the repository at this point in the history
Complete teams and organisations, extend campaigns from tags into own objects

Port teams, orgs and campaigns to APIv2

Cleaning up and debugging teams, orgs and campaigns backend

fix revision for merge

Handle non-null fields + Consistent table names

CI fix: Update Image ID

Black formatting

Flake updates

Flake fix

Remove the default length

Ignore E203 psf/black#315

Revert ignore flag on flake
  • Loading branch information
Zack LaVergne authored and ramyaragupathy committed Oct 23, 2019
1 parent 6309fa4 commit e99862f
Show file tree
Hide file tree
Showing 42 changed files with 3,210 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ jobs:
build:
working_directory: /home/circleci/app
docker:
- image: circleci/python:3-buster-browsers
- image: circleci/python:3.7-buster-browsers
steps:
- checkout
- setup_remote_docker
Expand Down
6 changes: 4 additions & 2 deletions migrations/versions/0eee8c1abd3a_.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def upgrade():
count = 0
match = 0

with open("migrations/continents.json") as continents_data:
with open("scripts/world/continents.json") as continents_data:
continents = json.load(continents_data)

for project in projects:
Expand All @@ -55,7 +55,9 @@ def upgrade():
if is_match:
project_continent = continent["properties"]["CONTINENT"]
with open(
"migrations/" + project_continent + ".json", "r", encoding="utf-8"
"scripts/world/" + project_continent + ".json",
"r",
encoding="utf-8" "scripts/world/" + project_continent + ".json",
) as countries_data:
countries = json.load(countries_data)
if not project_centroid.is_valid:
Expand Down
219 changes: 219 additions & 0 deletions migrations/versions/e3282e2db2d7_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
"""empty message
Revision ID: e3282e2db2d7
Revises: 068674f06b0f
Create Date: 2019-06-17 18:34:11.058440
"""
from alembic import op
import sqlalchemy as sa
from server.models.postgis.statuses import TeamVisibility, OrganisationVisibility


# revision identifiers, used by Alembic.
revision = "e3282e2db2d7"
down_revision = "d2e18f0f34a9"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"organisations",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=512), nullable=False),
sa.Column("logo", sa.String(), nullable=True),
sa.Column("url", sa.String(), nullable=True),
sa.Column(
"visibility",
sa.Integer(),
nullable=False,
server_default=str(OrganisationVisibility.SECRET.value),
),
sa.PrimaryKeyConstraint("id")
# ,
# sa.UniqueConstraint("name"),
)
op.create_table(
"organisation_admins",
sa.Column("organisation_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.BigInteger(), nullable=False),
sa.ForeignKeyConstraint(["organisation_id"], ["organisations.id"]),
sa.ForeignKeyConstraint(["user_id"], ["users.id"]),
)
op.create_table(
"teams",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("organisation_id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(length=512), nullable=False),
sa.Column("logo", sa.String(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.Column("invite_only", sa.Boolean(), nullable=False),
sa.Column(
"visibility",
sa.Integer(),
nullable=False,
server_default=str(TeamVisibility.SECRET.value),
),
sa.ForeignKeyConstraint(
["organisation_id"], ["organisations.id"], name="fk_organisations"
),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"project_teams",
sa.Column("team_id", sa.Integer(), nullable=False),
sa.Column("project_id", sa.Integer(), nullable=False),
sa.Column("role", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["project_id"], ["projects.id"]),
sa.ForeignKeyConstraint(["team_id"], ["teams.id"]),
sa.PrimaryKeyConstraint("team_id", "project_id"),
)
op.create_table(
"team_members",
sa.Column("team_id", sa.Integer(), nullable=False),
sa.Column("user_id", sa.BigInteger(), nullable=False),
sa.Column("function", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["team_id"], ["teams.id"], name="fk_teams"),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name="fk_users"),
sa.PrimaryKeyConstraint("team_id", "user_id"),
)
op.add_column("projects", sa.Column("organisation_id", sa.Integer(), nullable=True))
op.alter_column(
"projects", "task_creation_mode", existing_type=sa.INTEGER(), nullable=False
)
op.create_index(
op.f("ix_projects_organisation_id"),
"projects",
["organisation_id"],
unique=False,
)
op.drop_index("ix_projects_organisation_tag", table_name="projects")
op.create_foreign_key(
"fk_organisations", "projects", "organisations", ["organisation_id"], ["id"]
)
op.drop_column("projects", "organisation_tag")
op.drop_index(
"idx_task_validation_mapper_status_composite",
table_name="task_invalidation_history",
)
op.create_index(
"idx_task_validation_mapper_status_composite",
"task_invalidation_history",
["mapper_id", "is_closed"],
unique=False,
)

# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"campaigns",
sa.Column("id", sa.Integer(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("logo", sa.String(), nullable=True),
sa.Column("url", sa.String(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.PrimaryKeyConstraint("id"),
)
op.create_table(
"campaign_projects",
sa.Column("campaign_id", sa.Integer(), nullable=True),
sa.Column("project_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(["campaign_id"], ["campaigns.id"]),
sa.ForeignKeyConstraint(["project_id"], ["projects.id"]),
)
op.create_table(
"campaign_organisations",
sa.Column("campaign_id", sa.Integer(), nullable=True),
sa.Column("organisation_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(["campaign_id"], ["campaigns.id"]),
sa.ForeignKeyConstraint(["organisation_id"], ["organisations.id"]),
)
op.drop_index(
"idx_task_validation_mapper_status_composite",
table_name="task_invalidation_history",
)
op.create_index(
"idx_task_validation_mapper_status_composite",
"task_invalidation_history",
["invalidator_id", "is_closed"],
unique=False,
)

conn = op.get_bind()

# Content migration: Migrate the campaigns tag in campaigns table
campaigns = conn.execute(
"select campaigns from tags where campaigns is not null"
).fetchall()

# This will be used to consolidate the data in tags table
dictionaries = {"HOTOSM": {"HOTOSM", "HOT-OSM"}, "ABC": {"abc", "ABc"}}

for campaign in campaigns:
result = campaign[0]
for campaign_key, campaign_values in dictionaries.items():
if campaign[0] in campaign_values:
result = campaign_key

query = "insert into campaigns(name) values('" + result + "')"
op.execute(query)

# Migrate the organisations tag in organisations table
organisations = conn.execute(
"select organisations from tags where organisations is not null"
).fetchall()

# This will be used to consolidate the data in the tags table
org_dictionaries = {"HOTOSM": {"HOTOSM", "HOT-OSM"}, "ABC": {"abc", "ABc"}}

for org in organisations:
result = org[0]
if result.startswith("'") or result.startswith('"'):
print(result)
result = result[1:]
for org_key, org_values in org_dictionaries.items():
if result in org_values:
result = org_key

query = "insert into organisations(name) values ('" + result + "')"
op.execute(query)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
"idx_task_validation_mapper_status_composite",
table_name="task_invalidation_history",
)
op.create_index(
"idx_task_validation_mapper_status_composite",
"task_invalidation_history",
["invalidator_id", "is_closed"],
unique=False,
)
op.add_column(
"projects",
sa.Column("organisation_tag", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.drop_constraint("fk_organisations", "projects", type_="foreignkey")
op.create_index(
"ix_projects_organisation_tag", "projects", ["organisation_tag"], unique=False
)
op.drop_index(op.f("ix_projects_organisation_id"), table_name="projects")
op.alter_column(
"projects", "task_creation_mode", existing_type=sa.INTEGER(), nullable=True
)
op.drop_column("projects", "organisation_id")
op.drop_table("team_members")
op.drop_table("project_teams")
op.drop_table("teams")
op.drop_table("campaign_organisations")
op.drop_table("campaign_projects")
op.drop_table("campaigns")
op.drop_table("organisation_admins")
op.drop_table("organisations")

# ### end Alembic commands ###
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit e99862f

Please sign in to comment.