mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 00:51:12 +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
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package sqlite
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
_ "github.com/mutecomm/go-sqlcipher/v4" // We require go sqlcipher that overrides default implementation
|
|
"github.com/status-im/migrate/v4/database/sqlcipher"
|
|
bindata "github.com/status-im/migrate/v4/source/go_bindata"
|
|
|
|
"github.com/status-im/status-go/internal/db/sqlite"
|
|
"github.com/status-im/status-go/pkg/messaging"
|
|
)
|
|
|
|
var migrationsTable = "status_protocol_go_" + sqlcipher.DefaultMigrationsTable
|
|
|
|
func Migrate(database *sql.DB) error {
|
|
lastProtocolMigrationVersion, _, err := sqlite.GetLastMigrationVersion(database, migrationsTable)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to get current migration version")
|
|
}
|
|
|
|
err = messaging.SQLiteMigrate(database, lastProtocolMigrationVersion)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to apply messaging migrations")
|
|
}
|
|
|
|
migrationNames, migrationGetter, err := prepareMigrations(defaultMigrations)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to prepare status-go/protocol migrations")
|
|
}
|
|
|
|
// Ensure the protocol migration table version is synchronized with the latest migration after migrations are moved between modules.
|
|
err = sqlite.UpdateMigrationTableVersion(database, migrationsTable, migrationNames, lastProtocolMigrationVersion)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to update migration table version")
|
|
}
|
|
|
|
options := sqlite.MigrateOptions{
|
|
MigrationTableName: migrationsTable,
|
|
}
|
|
err = sqlite.Migrate(database, bindata.Resource(migrationNames, bindata.AssetFunc(migrationGetter)), options)
|
|
if err != nil {
|
|
return errors.Wrap(err, "failed to apply status-go/protocol migrations")
|
|
}
|
|
|
|
return nil
|
|
}
|