Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add migration for paths column in sub_repo_permissions#41785

Merged
pjlast merged 12 commits into
mainfrom
pjlast/41781-create-database-migrations
Oct 3, 2022
Merged

Add migration for paths column in sub_repo_permissions#41785
pjlast merged 12 commits into
mainfrom
pjlast/41781-create-database-migrations

Conversation

@pjlast

@pjlast pjlast commented Sep 20, 2022

Copy link
Copy Markdown
Contributor

Solves #41781

Adds a new column, paths to the sub_repo_permissions table. It's a concatenation of path_includes and path_excludes, with each entry in path_excludes being prepended with a - to signify that it is an exclusion.

Test plan

Ran migrations up and down locally and inspected DB. Buildkite 🤞

@pjlast pjlast requested review from a team September 20, 2022 10:58
@pjlast pjlast linked an issue Sep 20, 2022 that may be closed by this pull request
@cla-bot cla-bot Bot added the cla-signed label Sep 20, 2022

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread migrations/frontend/1663665519_perforce_merge_includes_excludes_columns/up.sql Outdated
Co-authored-by: Alex Ostrikov <alex.ostrikov@sourcegraph.com>
@mrnugget

Copy link
Copy Markdown
Contributor

Pretty sure you need to run sg generate to generate a new db schema and a bunch of other stuff.

@ryanslade

Copy link
Copy Markdown
Contributor

Pretty sure you need to run sg generate to generate a new db schema and a bunch of other stuff.

Yeah, I think you need to do the up migration locally and then run sg generate

@ryanslade ryanslade left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. but needs the generated files

@pjlast

pjlast commented Sep 20, 2022

Copy link
Copy Markdown
Contributor Author

@ryanslade @mrnugget added thanks

@ryanslade

Copy link
Copy Markdown
Contributor

:shipit:

COMMENT ON COLUMN sub_repo_permissions.paths IS 'Paths that begin with a minus sign (-) are exclusion paths.';

UPDATE sub_repo_permissions
SET paths = (path_includes || ARRAY(SELECT CONCAT('-', path_exclude) FROM unnest(path_excludes) as path_exclude));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to put these rules in the order they occur in the protections table, rather than just concatenating them? Or is the purpose of this migration just to get initial data into that column?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! 🙏

@pjlast

pjlast commented Sep 20, 2022

Copy link
Copy Markdown
Contributor Author

I'm going to keep this PR open so that we can make changes based on discoveries in the other sub-tasks

COMMENT ON COLUMN sub_repo_permissions.paths IS 'Paths that begin with a minus sign (-) are exclusion paths.';

UPDATE sub_repo_permissions
SET paths = (path_includes || ARRAY(SELECT CONCAT('-', path_exclude) FROM unnest(path_excludes) as path_exclude));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this might be completely stupid, but what if a path starts with - because a directory starts with -?

screenshot_2022-09-21_14 48 59@2x

Will that be treated as an exclusion path by accident?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be, we actually tried to mimic Perforce rules here. We should perhaps stick with their way of starting with -// instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd double check what the rule would look like and what our parsing makes out of it in case there's a - in there.

pjlast and others added 4 commits September 22, 2022 13:04
…o_permissions` table. (#41859)

This is the first part of Perforce rules matching simplification. The idea is that all rules are stored as is and read one-by-one during matching (vs. previous approach of "merging" the rules before storing them in the DB).

Test plan:
Unit tests updated. Existing related tests should not fail.
@ryanslade

Copy link
Copy Markdown
Contributor

@pjlast The other Perforce PR's have been merged, is there something blocking this going in? Are we waiting to add more test cases?

@pjlast

pjlast commented Sep 30, 2022

Copy link
Copy Markdown
Contributor Author

@ryanslade I'm just running through the manual test cases that @mollylogue has in the doc. I want to confirm that they work on the current version, then upgrade and run through them again

@sourcegraph-bot

sourcegraph-bot commented Oct 3, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 0a4f9e8...ff08a0b.

Notify File(s)
@beyang internal/search/symbol/symbol_test.go
@camdencheek internal/search/symbol/symbol_test.go
@indradhanush enterprise/cmd/repo-updater/internal/authz/perms_syncer_test.go
@keegancsmith internal/search/symbol/symbol_test.go
@unknwon enterprise/cmd/frontend/internal/authz/resolvers/resolver.go
enterprise/cmd/frontend/internal/authz/resolvers/resolver_test.go
enterprise/cmd/repo-updater/internal/authz/perms_syncer_test.go
enterprise/internal/authz/perforce/cmd/scanprotects/main.go
enterprise/internal/authz/perforce/cmd/scanprotects/main_test.go
enterprise/internal/authz/perforce/perforce_test.go
enterprise/internal/authz/perforce/protects.go
enterprise/internal/authz/perforce/protects_test.go
internal/authz/iface.go
internal/authz/sub_repo_perms.go
internal/authz/sub_repo_perms_test.go

@pjlast pjlast enabled auto-merge (squash) October 3, 2022 12:56
@pjlast pjlast disabled auto-merge October 3, 2022 12:57
@pjlast pjlast merged commit dbbb0e0 into main Oct 3, 2022
@pjlast pjlast deleted the pjlast/41781-create-database-migrations branch October 3, 2022 13:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Perforce: Create database migrations

6 participants