• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mishankov / platforma / 18873948603

28 Oct 2025 11:57AM UTC coverage: 19.929% (+10.6%) from 9.36%
18873948603

Pull #10

github

mishankov
Remove goconst linter from test and update migration test

Remove the table existence check from the test since we're now expecting
the migration to be fully reverted or not attempted.
Pull Request #10: Fix migrations

114 of 161 new or added lines in 5 files covered. (70.81%)

3 existing lines in 3 files now uncovered.

224 of 1124 relevant lines covered (19.93%)

0.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.86
/database/database.go
1
package database
2

3
import (
4
        "context"
5
        "fmt"
6

7
        "github.com/jmoiron/sqlx"
8
        _ "github.com/lib/pq"
9
)
10

11
type Database struct {
12
        *sqlx.DB
13
        repositories map[string]any
14
        migrators    map[string]migrator
15
        repository   *Repository
16
        service      *service
17
}
18

19
func New(connection string) (*Database, error) {
1✔
20
        db, err := sqlx.Connect("postgres", connection)
1✔
21
        if err != nil {
1✔
22
                return nil, fmt.Errorf("failed to connect to database: %w", err)
×
23
        }
×
24

25
        repository := newRepository(db)
1✔
26
        service := newService(repository)
1✔
27
        return &Database{DB: db, repositories: make(map[string]any), migrators: make(map[string]migrator), repository: repository, service: service}, nil
1✔
28
}
29

30
func (db *Database) RegisterRepository(name string, repository any) {
1✔
31
        db.repositories[name] = repository
1✔
32

1✔
33
        if migr, ok := repository.(migrator); ok {
2✔
34
                db.migrators[name] = migr
1✔
35
        }
1✔
36
}
37

38
func (db *Database) Migrate(ctx context.Context) error {
1✔
39
        // Ensure that migration table exists
1✔
40
        err := db.service.MigrateSelf(ctx)
1✔
41
        if err != nil {
1✔
NEW
42
                return err
×
UNCOV
43
        }
×
44

45
        // Get completed migrations
46
        migrationLogs, err := db.service.GetMigrationLogs(ctx)
1✔
47
        if err != nil {
1✔
48
                return fmt.Errorf("failed to select migrations state: %w", err)
×
49
        }
×
50

51
        // Get migrations from all migrators
52
        migrations := []Migration{}
1✔
53
        for name, migrator := range db.migrators {
2✔
54
                for _, migr := range migrator.Migrations() {
2✔
55
                        migr.repository = name
1✔
56
                        migrations = append(migrations, migr)
1✔
57
                }
1✔
58
        }
59

60
        err = db.service.ApplyMigrations(ctx, migrations, migrationLogs)
1✔
61
        if err != nil {
2✔
62
                return err
1✔
63
        }
1✔
64

65
        return nil
1✔
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc