Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/code/src/main/db/migrations/0004_auth_preferences.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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
);
Comment on lines +1 to +7
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.

--> statement-breakpoint
CREATE INDEX `auth_preferences_account_region_idx` ON `auth_preferences` (`account_key`,`cloud_region`);
Loading
Loading