Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sqlite): id column should be unique #894

Merged
merged 3 commits into from
May 12, 2024
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
22 changes: 22 additions & 0 deletions internal/database/migrations/sqlite/0003_uniq_id.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-- Create a temporary table
CREATE TABLE IF NOT EXISTS bookmark_temp(
id INTEGER PRIMARY KEY AUTOINCREMENT,
url TEXT NOT NULL,
title TEXT NOT NULL,
excerpt TEXT NOT NULL DEFAULT "",
author TEXT NOT NULL DEFAULT "",
public INTEGER NOT NULL DEFAULT 0,
modified TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
has_content BOOLEAN DEFAULT FALSE NOT NULL,
CONSTRAINT bookmark_url_UNIQUE UNIQUE(url)
);

-- Copy data from the original table to the temporary table
INSERT INTO bookmark_temp (id, url, title, excerpt, author, public, modified, has_content)
SELECT id, url, title, excerpt, author, public, modified, has_content FROM bookmark;

-- Drop the original table
DROP TABLE bookmark;

-- Rename the temporary table to the original table name
ALTER TABLE bookmark_temp RENAME TO bookmark;
1 change: 1 addition & 0 deletions internal/database/sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var sqliteMigrations = []migration{
return nil
}),
newFileMigration("0.3.0", "0.4.0", "sqlite/0002_denormalize_content"),
newFileMigration("0.4.0", "0.5.0", "sqlite/0003_uniq_id"),
}

// SQLiteDatabase is implementation of Database interface
Expand Down
Loading