Adding sqlite3 migrate and make utility commands
parent
012ae2783e
commit
bda1ba8324
@ -1,3 +1,5 @@
|
|||||||
module git.runcible.io/learning/ratchet
|
module git.runcible.io/learning/ratchet
|
||||||
|
|
||||||
go 1.23.3
|
go 1.23.3
|
||||||
|
|
||||||
|
require github.com/mattn/go-sqlite3 v1.14.24 // indirect
|
||||||
|
@ -0,0 +1,2 @@
|
|||||||
|
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
@ -0,0 +1 @@
|
|||||||
|
DROP TABLE IF EXISTS snippets;
|
@ -0,0 +1,20 @@
|
|||||||
|
PRAGMA foreign_keys=1;
|
||||||
|
CREATE TABLE snippets (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT,
|
||||||
|
content TEXT,
|
||||||
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
expires_at DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
-- Add an index on the created column.
|
||||||
|
CREATE INDEX idx_snippets_created ON snippets(created_at);
|
||||||
|
|
||||||
|
-- Add a trigger to keep timestamp updated.
|
||||||
|
CREATE TRIGGER snippet_update_timestamp
|
||||||
|
AFTER UPDATE ON snippets
|
||||||
|
FOR EACH ROW
|
||||||
|
BEGIN
|
||||||
|
UPDATE snippets SET updated_at = CURRENT_TIMESTAMP WHERE id = OLD.id;
|
||||||
|
END;
|
Loading…
Reference in New Issue