Compare commits
7 Commits
13f102755f
...
a7d42f515d
| Author | SHA1 | Date | |
|---|---|---|---|
|
a7d42f515d
|
|||
|
67f8143b1d
|
|||
|
2a45779278
|
|||
|
116438cd0f
|
|||
|
c06582e084
|
|||
|
15b77364eb
|
|||
|
43d6e98916
|
@@ -2,4 +2,7 @@ module solopm.com/solopm-server
|
||||
|
||||
go 1.26.3
|
||||
|
||||
require github.com/joho/godotenv v1.5.1 // indirect
|
||||
require (
|
||||
github.com/golang-migrate/migrate/v4 v4.19.1 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
)
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
github.com/golang-migrate/migrate/v4 v4.19.1 h1:OCyb44lFuQfYXYLx1SCxPZQGU7mcaZ7gH9yH4jSFbBA=
|
||||
github.com/golang-migrate/migrate/v4 v4.19.1/go.mod h1:CTcgfjxhaUtsLipnLoQRWCrjYXycRz/g5+RWDuYgPrE=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package db
|
||||
|
||||
import (
|
||||
"database/sql",
|
||||
"log"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/sqlite3"
|
||||
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := sql.Open("sqlite3", "database.sqlite")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
driver, err := sqlite3.WithInstance(db, &sqlite3.Config{})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
migrator, err := migrate.NewWithDatabaseInstance(
|
||||
"file://migrations/", "sqlite3", driver
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := migrator.Up(); err != nill && err != migrate.ErrNoChange {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_00_00_000000_create_audit_log_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "audit_log" --------------------------------------
|
||||
DROP TABLE IF EXISTS "audit_log";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_00_00_000000_create_audit_log_table.sql
|
||||
-- internal/db/migrations/2026_00_00_000000_create_audit_log_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "audit_log" ------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "audit_log" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000000_create_users_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "users" ------------------------------------------
|
||||
DROP TABLE IF EXISTS "users";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000000_create_users_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000000_create_users_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "users" ----------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "users" (
|
||||
@@ -27,17 +27,17 @@ CREATE UNIQUE INDEX IF NOT EXISTS "idx_users_provider"
|
||||
-- -------------------------------------------------------------
|
||||
|
||||
-- INSERT "SYSTEM" USER ----------------------------------------
|
||||
INSERT INTO `users`
|
||||
(`username`,`is_admin`,`name`,`email`,`avatar_url`)
|
||||
INSERT INTO users
|
||||
(username,is_admin,name,email,avatar_url)
|
||||
VALUES
|
||||
("system", true, "System User", "system@localhost", "")
|
||||
('system', true, 'System User', 'system@localhost', '')
|
||||
;
|
||||
-- -------------------------------------------------------------
|
||||
|
||||
-- INSERT "ZOMBIE" USER ----------------------------------------
|
||||
INSERT INTO `users`
|
||||
(`username`,`is_admin`,`name`,`email`,`avatar_url`)
|
||||
INSERT INTO users
|
||||
(username,is_admin,name,email,avatar_url)
|
||||
VALUES
|
||||
("zombie", false, "Zombie", "zombie@localhost", "")
|
||||
('zombie', false, 'Zombie', 'zombie@localhost', '')
|
||||
;
|
||||
-- -------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000010_create_projects_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "projects" ---------------------------------------
|
||||
DROP TABLE IF EXISTS "projects";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,6 +1,6 @@
|
||||
-- internal/db/migrations/2026_01_01_000010_create_projects_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000010_create_projects_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "projects" ------------------------------------
|
||||
-- CREATE TABLE "projects" -------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "projects"(
|
||||
"id" Integer NOT NULL PRIMARY KEY AUTOINCREMENT,
|
||||
"creator_id" Integer NOT NULL REFERENCES "users"("id"),
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_user_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_user" -----------------------------------
|
||||
DROP TABLE IF EXISTS "project_user";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_user_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_user_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_user" ---------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_user" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_labels_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_labels" ---------------------------------
|
||||
DROP TABLE IF EXISTS "project_labels";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_labels_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000011_create_project_labels_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_labels" -------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_labels" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000013_create_project_links_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_links" ----------------------------------
|
||||
DROP TABLE IF EXISTS "project_links";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000013_create_project_links_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000013_create_project_links_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_links" --------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_links" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000014_create_project_attachments_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_attachments" ----------------------------
|
||||
DROP TABLE IF EXISTS "project_attachments";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000014_create_project_attachments_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000014_create_project_attachments_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_attachments" --------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_attachments" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000015_create_project_favorites_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_favorites" ------------------------------
|
||||
DROP TABLE IF EXISTS "project_favorites";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000015_create_project_favorites_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000015_create_project_favorites_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_favorites" ----------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_favorites" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_00_000007_create_project_dependencies_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "project_dependencies" -----------------------------
|
||||
DROP TABLE IF EXISTS "project_dependencies";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_00_000007_create_project_dependencies_table.sql
|
||||
-- internal/db/migrations/2026_01_00_000007_create_project_dependencies_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "project_dependencies" -----------------------------
|
||||
CREATE TABLE IF NOT EXISTS "project_dependencies" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000020_create_issues_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issues" -----------------------------------------
|
||||
DROP TABLE IF EXISTS "issues";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000020_create_issues_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000020_create_issues_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issues" ---------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issues" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000021_create_issue_labels_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_labels" -----------------------------------
|
||||
DROP TABLE IF EXISTS "issue_labels";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000021_create_issue_labels_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000021_create_issue_labels_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_labels" ---------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_labels" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000022_create_issue_links_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_links" ------------------------------------
|
||||
DROP TABLE IF EXISTS "issue_links";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000022_create_issue_links_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000022_create_issue_links_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_links" ----------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_links" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000023_create_issue_attachments_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_attachments" ------------------------------
|
||||
DROP TABLE IF EXISTS "issue_attachments";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000023_create_issue_attachments_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000023_create_issue_attachments_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_attachments" ----------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_attachments" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000005_create_issue_blockers_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_blockers" ---------------------------------
|
||||
DROP TABLE IF EXISTS "issue_blockers";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000005_create_issue_blockers_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000005_create_issue_blockers_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_blockers" -------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_blockers" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000024_create_issue_comments_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_comments" ---------------------------------
|
||||
DROP TABLE IF EXISTS "issue_comments";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000024_create_issue_comments_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000024_create_issue_comments_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_comments" -------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_comments" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000106_create_issue_comment_links_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_comment_links" ----------------------------
|
||||
DROP TABLE IF EXISTS "issue_comment_links";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000106_create_issue_comment_links_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000106_create_issue_comment_links_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_comment_links" --------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_comment_links" (
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_01_000107_create_issue_comment_attachments_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "issue_comment_attachments" --------------------------
|
||||
DROP TABLE IF EXISTS "issue_comment_attachments";
|
||||
-- -------------------------------------------------------------
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_01_000107_create_issue_comment_attachments_table.sql
|
||||
-- internal/db/migrations/2026_01_01_000107_create_issue_comment_attachments_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "issue_comment_attachments" --------------------------
|
||||
CREATE TABLE IF NOT EXISTS "issue_comment_attachments" (
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
-- internal/db/migrations/2026_01_02_000001_create_webhook_receipts_table.sql.down.sql
|
||||
|
||||
-- DROP TABLE "webhook_receipts" -------------------------------
|
||||
DROP TABLE IF EXISTS "webhook_receipts";
|
||||
-- -------------------------------------------------------------
|
||||
@@ -1,4 +1,4 @@
|
||||
-- internal/db/migrations/2026_01_02_000001_create_webhook_receipts_table.sql
|
||||
-- internal/db/migrations/2026_01_02_000001_create_webhook_receipts_table.sql.up.sql
|
||||
|
||||
-- CREATE TABLE "webhook_receipts" -------------------------------
|
||||
CREATE TABLE IF NOT EXISTS "webhook_receipts" (
|
||||
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DB_NAME="database.sqlite"
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo "You need to tell me up or down"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" == "up" ]]; then
|
||||
rm -f "$DB_NAME"
|
||||
touch "$DB_NAME"
|
||||
for file in migrations/*.up.sql; do
|
||||
echo "Executing $file..."
|
||||
sqlite3 "$DB_NAME" < "$file"
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ "$1" == "down" ]]; then
|
||||
for file in migrations/*.down.sql; do
|
||||
echo "Executing $file..."
|
||||
sqlite3 "$DB_NAME" < "$file"
|
||||
done
|
||||
fi
|
||||
Reference in New Issue
Block a user