Skip to content

add user table#124

Open
joachimschmidt557 wants to merge 1 commit intomainfrom
add-user-table
Open

add user table#124
joachimschmidt557 wants to merge 1 commit intomainfrom
add-user-table

Conversation

@joachimschmidt557
Copy link
Copy Markdown
Member

this is a first step toward saving other user-related data in the database (e.g. keys)

this is a first step toward saving other user-related data in the
database (e.g. keys)
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new user table and backfills it from existing interval data, then rebuilds the interval table to add a foreign-key relationship as a foundation for storing additional user-related data (e.g., keys) in the DB.

Changes:

  • Introduce a user table keyed by user_id and seed it from distinct interval.user_id values.
  • Recreate interval as a new table with a FOREIGN KEY (user_id) REFERENCES user(user_id) ON DELETE CASCADE, then swap it in.
  • Provide a down migration that rebuilds interval without the FK and drops the user table.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
storage/migrations/20260417200302_add_user_table.up.sql Creates and seeds user, rebuilds interval to add FK + cascade semantics.
storage/migrations/20260417200302_add_user_table.down.sql Restores interval schema without FK and removes the user table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1 to +3
CREATE TABLE user (
user_id integer PRIMARY KEY AUTOINCREMENT
);
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

Other migrations in this repo use IF NOT EXISTS / IF EXISTS for CREATE/DROP. To keep migrations resilient to partial runs and consistent with existing style, consider using CREATE TABLE IF NOT EXISTS user and DROP TABLE IF EXISTS ... (including temp tables like new_interval/old_interval if you keep them).

Copilot uses AI. Check for mistakes.

ALTER TABLE old_interval RENAME TO interval;

DROP TABLE user;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

For consistency with existing migrations (e.g., initialize.down.sql uses DROP TABLE IF EXISTS), consider using DROP TABLE IF EXISTS user here. This also makes rollback safer if the table was already removed or the migration was partially applied.

Suggested change
DROP TABLE user;
DROP TABLE IF EXISTS user;

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,25 @@
CREATE TABLE user (
user_id integer PRIMARY KEY AUTOINCREMENT
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

AUTOINCREMENT is usually unnecessary in SQLite and can have downsides (forces monotonically increasing ids and prevents reuse, can increase sqlite_sequence churn). If you don’t need those semantics, prefer INTEGER PRIMARY KEY without AUTOINCREMENT for the user_id column.

Suggested change
user_id integer PRIMARY KEY AUTOINCREMENT
user_id integer PRIMARY KEY

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +25
INSERT INTO new_interval (user_id, start_time, end_time, tags, annotation)
SELECT user_id, start_time, end_time, tags, annotation FROM interval;

DROP TABLE interval;

ALTER TABLE new_interval RENAME TO interval;
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

This migration is multi-step (copy data, drop table, rename). Consider wrapping the whole sequence in a single transaction so a failure can’t leave the DB in a partially migrated state (e.g., interval dropped but new_interval not renamed).

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +18
PRIMARY KEY (user_id, start_time, end_time, tags, annotation),
FOREIGN KEY (user_id) REFERENCES user (user_id) ON DELETE CASCADE
);
Copy link

Copilot AI Apr 17, 2026

Choose a reason for hiding this comment

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

SQLite only enforces FOREIGN KEY constraints (and runs ON DELETE CASCADE) when foreign key enforcement is enabled on the connection. I couldn’t find any code enabling PRAGMA foreign_keys = ON / DSN _foreign_keys=on, so this constraint may be a no-op at runtime.

Copilot uses AI. Check for mistakes.
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