mirror of
https://github.com/status-im/status-go.git
synced 2026-08-30 16:41:20 +00:00
Part of the Go project layout migration, item 27. Pure move plus import-path rewrite across 502 files. No API or behaviour change. `internal/` keeps the messaging application logic unimportable from outside the module, which is what the issue asks for -- status-go is consumed through the C-bindings in mobile/, not as a Go library. Things that had to follow the move, beyond the Go imports: - tools/generate-handlers/template.txt. messenger_handlers.go is generated, and the template hard-codes the imports it emits, so the generated file kept importing protocol/common and failed typecheck. - .gitignore. The ignore rule for that generated file was pinned to the old path; without moving it, a 1486-line generated file starts being tracked. - Makefile: the logosstorage and torrent test targets (both the archive packages and ./protocol itself), the archive README, migration-protocol. - scripts/run_unit_tests.sh, which names the protocol package explicitly to shard its tests. - scripts/cleanup_generated_files.sh and .golangci.yml. scripts/migration_check.sh also needed a fix that is not specific to this move: it validated every file the branch touched under a migration dir against the timestamp naming rule, and a directory rename makes every migration in it look newly added. It now excludes renames, so moving a migration is not mistaken for adding one. refs #7067
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
appmigrations "github.com/status-im/status-go/internal/protocol/migrations"
|
|
push_notification_client_migrations "github.com/status-im/status-go/internal/protocol/pushnotificationclient/migrations"
|
|
push_notification_server_migrations "github.com/status-im/status-go/internal/protocol/pushnotificationserver/migrations"
|
|
)
|
|
|
|
type getter func(string) ([]byte, error)
|
|
|
|
type migrationsWithGetter struct {
|
|
Names []string
|
|
Getter getter
|
|
}
|
|
|
|
var defaultMigrations = []migrationsWithGetter{
|
|
{
|
|
Names: appmigrations.AssetNames(),
|
|
Getter: appmigrations.Asset,
|
|
},
|
|
{
|
|
Names: push_notification_server_migrations.AssetNames(),
|
|
Getter: push_notification_server_migrations.Asset,
|
|
},
|
|
{
|
|
Names: push_notification_client_migrations.AssetNames(),
|
|
Getter: push_notification_client_migrations.Asset,
|
|
},
|
|
}
|
|
|
|
func prepareMigrations(migrations []migrationsWithGetter) ([]string, getter, error) {
|
|
var allNames []string
|
|
nameToGetter := make(map[string]getter)
|
|
|
|
for _, m := range migrations {
|
|
for _, name := range m.Names {
|
|
if !validateName(name) {
|
|
continue
|
|
}
|
|
|
|
if _, ok := nameToGetter[name]; ok {
|
|
return nil, nil, errors.Errorf("migration with name %s already exists", name)
|
|
}
|
|
allNames = append(allNames, name)
|
|
nameToGetter[name] = m.Getter
|
|
}
|
|
}
|
|
|
|
return allNames, func(name string) ([]byte, error) {
|
|
getter, ok := nameToGetter[name]
|
|
if !ok {
|
|
return nil, errors.Errorf("no migration for name %s", name)
|
|
}
|
|
return getter(name)
|
|
}, nil
|
|
}
|
|
|
|
// validateName verifies that only *.sql files are taken into consideration.
|
|
func validateName(name string) bool {
|
|
return strings.HasSuffix(name, ".sql")
|
|
}
|