summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrail Finder (aider) <wohilas@gmail.com>2025-04-05 14:16:33 +0300
committerGrail Finder (aider) <wohilas@gmail.com>2025-04-05 14:16:33 +0300
commitabefce79dceba4dcf37bc1d8aa4fe9340622924a (patch)
tree3c3cb4cd225c27cf48214bced6e4630c4997df8b
parent9039360835e38a6de809332eb785ede124d71dea (diff)
refactor: remove migrations and add schema verification
-rw-r--r--internal/database/sql/main.go23
1 files changed, 18 insertions, 5 deletions
diff --git a/internal/database/sql/main.go b/internal/database/sql/main.go
index 9534e58..431dead 100644
--- a/internal/database/sql/main.go
+++ b/internal/database/sql/main.go
@@ -10,8 +10,6 @@ import (
"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
- migrate "github.com/rubenv/sql-migrate"
- "demoon/internal/database/migrations"
)
var (
@@ -19,6 +17,19 @@ var (
dbDriver = "sqlite3"
)
+// VerifyDB checks if required tables exist
+func (d *DB) VerifyDB() error {
+ var exists int
+ err := d.Conn.Get(&exists, `SELECT 1 FROM sqlite_master WHERE type='table' AND name='questions' LIMIT 1`)
+ if err != nil {
+ return errors.Wrap(err, "database verification failed")
+ }
+ if exists != 1 {
+ return errors.New("required tables not found in database")
+ }
+ return nil
+}
+
type DB struct {
Conn *sqlx.DB
URI string
@@ -58,9 +69,11 @@ func Init(dbPath string) (*DB, error) {
return nil, err
}
- // Run migrations
- if _, err := migrations.RunMigrations(result.Conn.DB, dbDriver); err != nil {
- return nil, errors.Wrap(err, "failed to run migrations")
+ // Verify tables exist
+ var tableCheck int
+ err = result.Conn.Get(&tableCheck, `SELECT 1 FROM sqlite_master WHERE type='table' AND name='questions' LIMIT 1`)
+ if err != nil {
+ return nil, errors.Wrap(err, "database schema verification failed")
}
return &result, nil