Skip to content

feat: persist preferred project by account key#1366

Merged
jonathanlab merged 1 commit intomainfrom
03-30-feat_persist_preferred_project_by_account_key
Apr 1, 2026
Merged

feat: persist preferred project by account key#1366
jonathanlab merged 1 commit intomainfrom
03-30-feat_persist_preferred_project_by_account_key

Conversation

@jonathanlab
Copy link
Copy Markdown
Contributor

@jonathanlab jonathanlab commented Mar 30, 2026

Problem

Now we're not persisting preferred project on logout followed by login

Changes

persist it in sqlite, keying by region and account key

Copy link
Copy Markdown
Contributor Author

jonathanlab commented Mar 30, 2026

@jonathanlab jonathanlab marked this pull request as ready for review March 30, 2026 14:34
@jonathanlab jonathanlab force-pushed the 03-30-feat_persist_preferred_project_by_account_key branch from 87a631f to 464aeac Compare March 31, 2026 11:50
@jonathanlab jonathanlab force-pushed the 03-30-refactor_hook_up_renderer_auth_logic_to_service branch 2 times, most recently from ddd1bec to f3b186c Compare March 31, 2026 13:44
@jonathanlab jonathanlab force-pushed the 03-30-feat_persist_preferred_project_by_account_key branch 2 times, most recently from 1b8363f to 3d93c97 Compare March 31, 2026 13:52
@jonathanlab jonathanlab force-pushed the 03-30-refactor_hook_up_renderer_auth_logic_to_service branch from f3b186c to 1e35e6d Compare March 31, 2026 13:52
Comment on lines +1 to +7
CREATE TABLE `auth_preferences` (
`account_key` text NOT NULL,
`cloud_region` text NOT NULL,
`last_selected_project_id` integer,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The auth_preferences table is missing a PRIMARY KEY or UNIQUE constraint on (account_key, cloud_region). This will allow duplicate rows to be inserted for the same account and region combination, causing unpredictable behavior in the get and save methods.

Impact: Multiple preference records can exist for the same account/region, and LIMIT 1 queries will return arbitrary rows. The update logic in save() may also fail to work correctly.

Fix: Add a composite primary key:

CREATE TABLE `auth_preferences` (
  `account_key` text NOT NULL,
  `cloud_region` text NOT NULL,
  `last_selected_project_id` integer,
  `created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
  `updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
  PRIMARY KEY (`account_key`, `cloud_region`)
);
Suggested change
CREATE TABLE `auth_preferences` (
`account_key` text NOT NULL,
`cloud_region` text NOT NULL,
`last_selected_project_id` integer,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL
);
CREATE TABLE `auth_preferences` (
`account_key` text NOT NULL,
`cloud_region` text NOT NULL,
`last_selected_project_id` integer,
`created_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) NOT NULL,
PRIMARY KEY (`account_key`, `cloud_region`)
);

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

@jonathanlab jonathanlab force-pushed the 03-30-refactor_hook_up_renderer_auth_logic_to_service branch from 1e35e6d to 7255c9c Compare March 31, 2026 14:20
@jonathanlab jonathanlab force-pushed the 03-30-feat_persist_preferred_project_by_account_key branch 3 times, most recently from 6df4db0 to 03cfd87 Compare April 1, 2026 09:53
Copy link
Copy Markdown
Contributor Author

jonathanlab commented Apr 1, 2026

Merge activity

@jonathanlab jonathanlab changed the base branch from 03-30-refactor_hook_up_renderer_auth_logic_to_service to graphite-base/1366 April 1, 2026 10:11
jonathanlab added a commit that referenced this pull request Apr 1, 2026
## Problem

We've now hooked up our main services to the auth service, but the auth store is just a thin unreliable wrapper around the main service. We want to rely on trpc queries with tanstack query instead.
<!-- Who is this for and what problem does it solve? -->

<!-- Closes #ISSUE_ID -->

## Changes

- Gets rid of the auth store
- Moves onboarding logic into its own store
- Moves auth ui state into its own store
- Add a bunch of hooks for querying and mutating the auth state via the main auth service

-------

one test fails here (preferred org persistence), we can just forge merge with CI bypass this one since it's fixed in the [next PR](#1366) in the stack
@jonathanlab jonathanlab changed the base branch from graphite-base/1366 to main April 1, 2026 10:20
@jonathanlab jonathanlab force-pushed the 03-30-feat_persist_preferred_project_by_account_key branch from 03cfd87 to 0fb87ee Compare April 1, 2026 10:21
@jonathanlab jonathanlab merged commit d2e2f22 into main Apr 1, 2026
16 checks passed
@jonathanlab jonathanlab deleted the 03-30-feat_persist_preferred_project_by_account_key branch April 1, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants