From 61ba5dcc29a16bb3727209a76ee75fffff037dee Mon Sep 17 00:00:00 2001 From: Samuel Johnson Date: Thu, 11 Dec 2025 15:09:30 -0500 Subject: Add commenting system --- internal/dbmigrations.go | 8 ++++++++ internal/models/comment.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 internal/models/comment.go (limited to 'internal') diff --git a/internal/dbmigrations.go b/internal/dbmigrations.go index fcbaaaf..41180c7 100644 --- a/internal/dbmigrations.go +++ b/internal/dbmigrations.go @@ -56,4 +56,12 @@ func Migrate(db *sql.DB, webmaster string, passOne string, passTwo string) { fmt.Fprintf(os.Stderr, "Unable to create cookies table: %v\n", err) } } + + _, table_check = db.Query("SELECT * FROM comments;") + if table_check != nil { + _, err := db.Exec("CREATE TABLE comments (id SERIAL PRIMARY KEY, verified BOOLEAN NOT NULL, time TIMESTAMP DEFAULT CURRENT_TIMESTAMP, name TEXT NOT NULL, post_id INTEGER REFERENCES posts(id), content TEXT NOT NULL);") + if err != nil { + fmt.Fprintf(os.Stderr, "Unable to create comments table: %v\n", err) + } + } } diff --git a/internal/models/comment.go b/internal/models/comment.go new file mode 100644 index 0000000..df27ca3 --- /dev/null +++ b/internal/models/comment.go @@ -0,0 +1,12 @@ +package models + +import "time" + +type Comment struct { + Id int + IsVerified bool + Time time.Time + FormattedTime string + Name string + Content string +} -- cgit v1.2.3