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

mishankov / platforma / 18869388098

28 Oct 2025 08:59AM UTC coverage: 18.19% (+8.8%) from 9.36%
18869388098

Pull #10

github

mishankov
Remove Windows from CI matrix
Pull Request #10: Fix migrations

98 of 175 new or added lines in 5 files covered. (56.0%)

4 existing lines in 3 files now uncovered.

207 of 1138 relevant lines covered (18.19%)

0.2 hits per line

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

77.14
/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 {
1✔
NEW
62
                return err
×
UNCOV
63
        }
×
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