feat: use go1.16 and resources embedding (#235)
* feat: use go1.16 embedding for resources We want to embed everything that can be easily embedded. We should, at a minimum, replace the downloading of resources and bindata. Ref: https://github.com/ooni/probe/issues/1367. * fix: get rid of bindata and use go embed instead * fix: start unbreaking some automatic tests * fix: fetch resources as part of the mobile build * fix: convert more stuff to go1.16 I still expect many breakages, but we'll fix them. * fix: make the windows CI green * fix: get resources before running QA * fix: go1.16 uses modules by default * hopefully fix all other outstanding issues * fix(QA/telegram.py): add another DC IP address * Apply suggestions from code review
This commit is contained in:
parent
c33af04e29
commit
322394fe63
51 changed files with 439 additions and 778 deletions
|
|
@ -2,21 +2,45 @@ package database
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"embed"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/cmd/ooniprobe/internal/bindata"
|
||||
migrate "github.com/rubenv/sql-migrate"
|
||||
"upper.io/db.v3/lib/sqlbuilder"
|
||||
"upper.io/db.v3/sqlite"
|
||||
)
|
||||
|
||||
//go:embed migrations/*.sql
|
||||
var efs embed.FS
|
||||
|
||||
func readAsset(path string) ([]byte, error) {
|
||||
filep, err := efs.Open(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ioutil.ReadAll(filep)
|
||||
}
|
||||
|
||||
func readAssetDir(path string) ([]string, error) {
|
||||
var out []string
|
||||
lst, err := efs.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, e := range lst {
|
||||
out = append(out, e.Name())
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// RunMigrations runs the database migrations
|
||||
func RunMigrations(db *sql.DB) error {
|
||||
log.Debugf("running migrations")
|
||||
migrations := &migrate.AssetMigrationSource{
|
||||
Asset: bindata.Asset,
|
||||
AssetDir: bindata.AssetDir,
|
||||
Dir: "data/migrations",
|
||||
Asset: readAsset,
|
||||
AssetDir: readAssetDir,
|
||||
Dir: "migrations",
|
||||
}
|
||||
n, err := migrate.Exec(db, "sqlite3", migrations, migrate.Up)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue