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

internal: Persist author in site config#46150

Merged
indradhanush merged 9 commits into
mainfrom
ig/persist-author-site-config
Jan 9, 2023
Merged

internal: Persist author in site config#46150
indradhanush merged 9 commits into
mainfrom
ig/persist-author-site-config

Conversation

@indradhanush

@indradhanush indradhanush commented Jan 5, 2023

Copy link
Copy Markdown
Contributor

Part of #46031. Follow up on #45618.

Why

We want to be able to show the site admin who made a specific change to the config.

Test plan

  1. Tested locally.

(Wanted to upload the GIF but its more than 10MB and its 2022 and GitHub restricts file size to 10MB. 😭)

image

  1. Builds pass.

@cla-bot cla-bot Bot added the cla-signed label Jan 5, 2023
@indradhanush indradhanush force-pushed the ig/persist-author-site-config branch from f3b625d to c10e356 Compare January 5, 2023 12:25
@indradhanush indradhanush marked this pull request as ready for review January 5, 2023 12:41
@indradhanush indradhanush requested a review from a team January 5, 2023 12:41
@indradhanush indradhanush added site-admin Site admin experience feature Tracking issues for a feature site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ... feature-request and removed feature Tracking issues for a feature labels Jan 5, 2023

@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, but I would remove all the pointers because they are in fact unused and just transformed to zero value of int32 🤔

@@ -0,0 +1,2 @@
ALTER TABLE critical_and_site_config
ADD COLUMN IF NOT EXISTS author_user_id integer;

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'm thinking about adding an index right away.
WDYT?

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.

And I think we keen to adding comments to columns. It would be nice to include what NULL author means.

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.

I'm thinking about adding an index right away.

Is there a use case in your mind about using the index? If we only need to list the changes, then we don't need the index.

And I think we keen to adding comments to columns. It would be nice to include what NULL author means.

We could add some comment about NULL meaning a likely a system start up that updated the config but it would be also misleading since we're just adding this column and I don't want to mislead users for historical columns that don't have the value set to NULL. Not really sure what's the best path here. 🤔

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'm thinking about adding an index right away.
WDYT?

I don't think it's necessary right now, since we likely won't be querying by author for foreseeable future.

But yeah, while we're here, we can add it.

I'd also add a comment, yep.

COMMENT ON COLUMN critical_and_site_config.author_user_id IS 'Horsegraph was here.';

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.

@indradhanush I mean... it won't hurt and we have a bunch of initiatives about improving admin experience. I can easily imagine one day having a filter "by user" for site/code host config changes TBH.

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.

I mean... it won't hurt and we have a bunch of initiatives about improving admin experience. I can easily imagine one day having a filter "by user" for site/code host config changes TBH.

Well, indexes do grow on trees 😝.

I don't want to start building for a hypothetical scenario and end up with premature optimization. If we do end up building this in the future, it should be fairly easy to add an index concurrently for this table, especially since this table is expected to have low-write volume.

Comment thread internal/database/conf.go
Comment thread internal/database/conf.go Outdated
@indradhanush

Copy link
Copy Markdown
Contributor Author

LGTM, but I would remove all the pointers because they are in fact unused and just transformed to zero value of int32 🤔

@sashaostrikov We need to set author_user_id to NULL in some cases which is where we pass a nil instead. Are you suggesting to drop the pointer and pass 0 instead? If that's the case I think nil is better conceptually. 🤔

@mrnugget mrnugget 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.

Because I'm always a bit scared about that: have you tested this manually with a fresh instance that gets booted up with SITE_CONFIG_FILE?

Comment thread internal/conf/server.go Outdated
Comment thread internal/database/conf.go
@@ -0,0 +1,2 @@
ALTER TABLE critical_and_site_config
ADD COLUMN IF NOT EXISTS author_user_id integer;

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'm thinking about adding an index right away.
WDYT?

I don't think it's necessary right now, since we likely won't be querying by author for foreseeable future.

But yeah, while we're here, we can add it.

I'd also add a comment, yep.

COMMENT ON COLUMN critical_and_site_config.author_user_id IS 'Horsegraph was here.';

@mrnugget

mrnugget commented Jan 5, 2023

Copy link
Copy Markdown
Contributor

@sashaostrikov We need to set author_user_id to NULL in some cases which is where we pass a nil instead. Are you suggesting to drop the pointer and pass 0 instead? If that's the case I think nil is better conceptually. 🤔

I would agree with you in other projects, but here we often use 0 for "no value", because 0 is never ever a valid value, meaning it can be used as "no value" and safes us from nil pointer parties

@indradhanush

Copy link
Copy Markdown
Contributor Author

Because I'm always a bit scared about that: have you tested this manually with a fresh instance that gets booted up with SITE_CONFIG_FILE?

That's a great call out. I just tested it on a fresh instance with SITE_CONFIG_FILE and it loads up without any issues. And for changes from the UI, the author_user_id is recorded correctly.

Anyhow, it's a Friday and I'll merge it next week.

Note to self: Run main-dry-run before merging.

@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.

Latest changes LGTM :shipit:

@indradhanush indradhanush force-pushed the ig/persist-author-site-config branch from 1279d04 to e601a62 Compare January 9, 2023 04:44
@indradhanush

Copy link
Copy Markdown
Contributor Author

Rebased off latest main. main-dry-run now running here: https://github.com/sourcegraph/sourcegraph/tree/main-dry-run/ig/persist-author-site-config

@indradhanush indradhanush force-pushed the ig/persist-author-site-config branch from e601a62 to 60caff3 Compare January 9, 2023 06:15
@indradhanush indradhanush merged commit 3569493 into main Jan 9, 2023
@indradhanush indradhanush deleted the ig/persist-author-site-config branch January 9, 2023 06:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla-signed feature-request site-admin Site admin experience site-admin-ux Issues related to site-admin UX: bugs, papercuts, design, ...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants