-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: update slug size after 2nd attemp
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
-- +micrate Up | ||
-- SQL in section 'Up' is executed when this migration is applied | ||
|
||
-- Step 1: Create a new table with the desired column type | ||
CREATE TABLE links_new ( | ||
id TEXT PRIMARY KEY NOT NULL, | ||
user_id TEXT NOT NULL, | ||
slug VARCHAR(8) UNIQUE NOT NULL, | ||
url TEXT NOT NULL, | ||
created_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
updated_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
|
||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
); | ||
|
||
-- Step 2: Copy data from the old table to the new table | ||
INSERT INTO links_new (id, user_id, slug, url, created_at, updated_at) | ||
SELECT id, user_id, slug, url, created_at, updated_at FROM links; | ||
|
||
-- Step 3: Drop the old table | ||
DROP TABLE links; | ||
|
||
-- Step 4: Rename the new table to the old table's name | ||
ALTER TABLE links_new RENAME TO links; | ||
|
||
-- +micrate Down | ||
-- SQL section 'Down' is executed when this migration is rolled back | ||
|
||
-- Step 1: Create a new table with the original column type | ||
CREATE TABLE links_old ( | ||
id TEXT PRIMARY KEY NOT NULL, | ||
user_id TEXT NOT NULL, | ||
slug VARCHAR(4) UNIQUE NOT NULL, | ||
url TEXT NOT NULL, | ||
created_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
updated_at INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
|
||
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE | ||
); | ||
|
||
-- Step 2: Copy data from the current table to the old table | ||
INSERT INTO links_old (id, user_id, slug, url, created_at, updated_at) | ||
SELECT id, user_id, substr(slug, 1, 4), url, created_at, updated_at FROM links; | ||
|
||
-- Step 3: Drop the current table | ||
DROP TABLE links; | ||
|
||
-- Step 4: Rename the old table to the current table's name | ||
ALTER TABLE links_old RENAME TO links; |