-
Notifications
You must be signed in to change notification settings - Fork 845
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2490 from chaoss/dev-index-matview-patch-spg-1
Dev index matview patch spg 1
- Loading branch information
Showing
15 changed files
with
868 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dfadffd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
augur/application/schema/alembic/versions/22_mat_view_cntrbid.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
"""Fix Keys and materialized view | ||
Revision ID: 22 | ||
Revises: 21 | ||
Create Date: 2023-08-23 18:17:22.651191 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy import text | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '22' | ||
down_revision = '21' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
|
||
add_fix_keys_22() | ||
|
||
def downgrade(): | ||
|
||
upgrade=False | ||
|
||
add_fix_keys_22(upgrade) | ||
|
||
def add_fix_keys_22(upgrade=True): | ||
|
||
if upgrade: | ||
|
||
conn = op.get_bind() | ||
conn.execute(text(""" | ||
alter TABLE | ||
augur_data.commits DROP CONSTRAINT if exists fk_commits_contributors_3, | ||
DROP CONSTRAINT if exists fk_commits_contributors_4; | ||
alter TABLE augur_data.contributors | ||
DROP CONSTRAINT if exists "GH-UNIQUE-C", | ||
DROP CONSTRAINT if exists | ||
"GL-cntrb-LOGIN-UNIQUE";""")) | ||
|
||
conn = op.get_bind() | ||
conn.execute(text(""" | ||
drop materialized view if exists augur_data.explorer_contributor_actions; """)) | ||
|
||
conn = op.get_bind() | ||
conn.execute(text(""" | ||
create materialized view augur_data.explorer_contributor_actions as | ||
SELECT | ||
A.ID AS cntrb_id, | ||
A.created_at, | ||
A.repo_id, | ||
A.ACTION, | ||
repo.repo_name, | ||
A.LOGIN, | ||
DENSE_RANK() OVER(PARTITION BY A.ID, A.repo_id ORDER BY A.created_at) AS RANK | ||
FROM ( | ||
select | ||
commits.cmt_ght_author_id AS ID, | ||
commits.cmt_author_timestamp AS created_at, | ||
commits.repo_id, | ||
'commit' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
( augur_data.commits LEFT JOIN augur_data.contributors ON ( ( ( contributors.cntrb_id ) :: TEXT = ( commits.cmt_ght_author_id ) :: TEXT ) ) ) | ||
GROUP BY | ||
commits.cmt_commit_hash, | ||
commits.cmt_ght_author_id, | ||
commits.repo_id, | ||
commits.cmt_author_timestamp, | ||
'commit' :: TEXT, | ||
contributors.cntrb_login | ||
UNION all | ||
SELECT | ||
issues.reporter_id AS ID, | ||
issues.created_at, | ||
issues.repo_id, | ||
'issue_opened' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
( augur_data.issues LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = issues.reporter_id ) ) ) | ||
WHERE | ||
( issues.pull_request IS NULL ) | ||
UNION ALL | ||
SELECT | ||
pull_request_events.cntrb_id AS ID, | ||
pull_request_events.created_at, | ||
pull_requests.repo_id, | ||
'pull_request_closed' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.pull_requests, | ||
( augur_data.pull_request_events LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = pull_request_events.cntrb_id ) ) ) | ||
WHERE | ||
pull_requests.pull_request_id = pull_request_events.pull_request_id | ||
AND pull_requests.pr_merged_at IS NULL | ||
AND ( ( pull_request_events.ACTION ) :: TEXT = 'closed' :: TEXT ) | ||
UNION ALL | ||
SELECT | ||
pull_request_events.cntrb_id AS ID, | ||
pull_request_events.created_at, | ||
pull_requests.repo_id, | ||
'pull_request_merged' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.pull_requests, | ||
( augur_data.pull_request_events LEFT JOIN augur_data.contributors ON ( ( contributors.cntrb_id = pull_request_events.cntrb_id ) ) ) | ||
WHERE | ||
pull_requests.pull_request_id = pull_request_events.pull_request_id | ||
AND ( ( pull_request_events.ACTION ) :: TEXT = 'merged' :: TEXT ) | ||
UNION ALL | ||
SELECT | ||
issue_events.cntrb_id AS ID, | ||
issue_events.created_at, | ||
issues.repo_id, | ||
'issue_closed' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.issues, | ||
augur_data.issue_events | ||
LEFT JOIN augur_data.contributors ON contributors.cntrb_id = issue_events.cntrb_id | ||
WHERE | ||
issues.issue_id = issue_events.issue_id | ||
AND issues.pull_request IS NULL | ||
AND ( ( issue_events.ACTION ) :: TEXT = 'closed' :: TEXT ) | ||
UNION ALL | ||
SELECT | ||
pull_request_reviews.cntrb_id AS ID, | ||
pull_request_reviews.pr_review_submitted_at AS created_at, | ||
pull_requests.repo_id, | ||
( 'pull_request_review_' :: TEXT || ( pull_request_reviews.pr_review_state ) :: TEXT ) AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.pull_requests, | ||
augur_data.pull_request_reviews | ||
LEFT JOIN augur_data.contributors ON contributors.cntrb_id = pull_request_reviews.cntrb_id | ||
WHERE | ||
pull_requests.pull_request_id = pull_request_reviews.pull_request_id | ||
UNION ALL | ||
SELECT | ||
pull_requests.pr_augur_contributor_id AS ID, | ||
pull_requests.pr_created_at AS created_at, | ||
pull_requests.repo_id, | ||
'pull_request_open' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.pull_requests | ||
LEFT JOIN augur_data.contributors ON pull_requests.pr_augur_contributor_id = contributors.cntrb_id | ||
UNION ALL | ||
SELECT | ||
message.cntrb_id AS ID, | ||
message.msg_timestamp AS created_at, | ||
pull_requests.repo_id, | ||
'pull_request_comment' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.pull_requests, | ||
augur_data.pull_request_message_ref, | ||
augur_data.message | ||
LEFT JOIN augur_data.contributors ON contributors.cntrb_id = message.cntrb_id | ||
WHERE | ||
pull_request_message_ref.pull_request_id = pull_requests.pull_request_id | ||
AND pull_request_message_ref.msg_id = message.msg_id | ||
UNION ALL | ||
SELECT | ||
issues.reporter_id AS ID, | ||
message.msg_timestamp AS created_at, | ||
issues.repo_id, | ||
'issue_comment' :: TEXT AS ACTION, | ||
contributors.cntrb_login AS LOGIN | ||
FROM | ||
augur_data.issues, | ||
augur_data.issue_message_ref, | ||
augur_data.message | ||
LEFT JOIN augur_data.contributors ON contributors.cntrb_id = message.cntrb_id | ||
WHERE | ||
issue_message_ref.msg_id = message.msg_id | ||
AND issues.issue_id = issue_message_ref.issue_id | ||
AND issues.closed_at != message.msg_timestamp | ||
) A, | ||
augur_data.repo | ||
WHERE | ||
A.repo_id = repo.repo_id | ||
ORDER BY | ||
A.created_at DESC""")) | ||
|
45 changes: 45 additions & 0 deletions
45
augur/application/schema/alembic/versions/23_add_index_ghlogin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""add index | ||
Revision ID: 23 | ||
Revises: 22 | ||
Create Date: 2023-08-23 18:17:22.651191 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy import text | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '23' | ||
down_revision = '22' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
|
||
gh_loginindex() | ||
|
||
def downgrade(): | ||
|
||
upgrade=False | ||
|
||
gh_loginindex(upgrade) | ||
|
||
def gh_loginindex(upgrade=True): | ||
|
||
if upgrade: | ||
|
||
conn = op.get_bind() | ||
conn.execute(text(""" | ||
CREATE INDEX if not exists "gh_login" ON "augur_data"."contributors" USING btree ( | ||
"gh_login" ASC NULLS FIRST);""")) | ||
|
||
else: | ||
|
||
|
||
conn = op.get_bind() | ||
conn.execute(text(""" | ||
DROP INDEX if exists "gh_login" ON "augur_data"."contributors" USING btree ( | ||
"gh_login" ASC NULLS FIRST);""")) |
49 changes: 49 additions & 0 deletions
49
augur/application/schema/alembic/versions/24_alter_repo_labor_unique.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Alter repo labor unique | ||
Revision ID: 24 | ||
Revises: 23 | ||
Create Date: 2023-08-25 18:17:22.651191 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
from sqlalchemy.sql import text | ||
import re | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '24' | ||
down_revision = '23' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
|
||
conn = op.get_bind() | ||
|
||
#Remove constraint being initially deferred. | ||
conn.execute(text(f""" | ||
ALTER TABLE "augur_data"."repo_labor" | ||
DROP CONSTRAINT IF EXISTS "rl-unique", | ||
ADD CONSTRAINT "rl-unique" UNIQUE ("repo_id", "rl_analysis_date", "file_path", "file_name"); | ||
""")) | ||
""" | ||
""" | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
conn = op.get_bind() | ||
|
||
#Make unique initially deferred | ||
conn.execute(text(f""" | ||
ALTER TABLE "augur_data"."repo_labor" | ||
DROP CONSTRAINT IF EXISTS "rl-unique", | ||
ADD CONSTRAINT "rl-unique" UNIQUE ("repo_id", "rl_analysis_date", "file_path", "file_name") DEFERRABLE INITIALLY DEFERRED; | ||
""")) | ||
|
||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.