wdcli: Use progress writer instead of IOStream
This commit is contained in:
parent
890022ae64
commit
3b78b06fff
49 changed files with 396 additions and 393 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
var errSQLBackup = errors.New("SQLBackup: Mysqldump returned non-zero exit code")
|
||||
|
|
@ -17,8 +18,7 @@ func (*SQL) BackupName() string {
|
|||
// Backup makes a backup of all SQL databases into the path dest.
|
||||
func (sql *SQL) Backup(scontext component.StagingContext) error {
|
||||
return scontext.AddFile("", func(ctx context.Context, file io.Writer) error {
|
||||
io := scontext.IO().Streams(file, nil, nil, 0).NonInteractive()
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysqldump", "--all-databases")
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(scontext.Progress()), "sql", "mysqldump", "--all-databases")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,16 +16,14 @@ func (*SQL) SnapshotName() string { return "sql" }
|
|||
func (sql *SQL) Snapshot(wisski models.Instance, scontext component.StagingContext) error {
|
||||
return scontext.AddDirectory(".", func(ctx context.Context) error {
|
||||
return scontext.AddFile(wisski.SqlDatabase+".sql", func(ctx context.Context, file io.Writer) error {
|
||||
return sql.SnapshotDB(ctx, scontext.IO(), file, wisski.SqlDatabase)
|
||||
return sql.SnapshotDB(ctx, scontext.Progress(), file, wisski.SqlDatabase)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// SnapshotDB makes a backup of the sql database into dest.
|
||||
func (sql *SQL) SnapshotDB(ctx context.Context, io stream.IOStream, dest io.Writer, database string) error {
|
||||
io = io.Streams(dest, nil, nil, 0).NonInteractive()
|
||||
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, io, "sql", "mysqldump", "--databases", database)
|
||||
func (sql *SQL) SnapshotDB(ctx context.Context, progress io.Writer, dest io.Writer, database string) error {
|
||||
code, err := sql.Stack(sql.Environment).Exec(ctx, stream.NonInteractive(progress), "sql", "mysqldump", "--databases", database)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/FAU-CDI/wisski-distillery/internal/models"
|
||||
|
|
@ -44,14 +45,14 @@ var errSQLUnableToMigrate = exit.Error{
|
|||
}
|
||||
|
||||
// Update initializes or updates the SQL database.
|
||||
func (sql *SQL) Update(ctx context.Context, io stream.IOStream) error {
|
||||
func (sql *SQL) Update(ctx context.Context, progress io.Writer) error {
|
||||
|
||||
// unsafely create the admin user!
|
||||
{
|
||||
if err := sql.unsafeWaitShell(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
logging.LogMessage(io, "Creating administrative user")
|
||||
logging.LogMessage(progress, "Creating administrative user")
|
||||
{
|
||||
username := sql.Config.MysqlAdminUser
|
||||
password := sql.Config.MysqlAdminPassword
|
||||
|
|
@ -62,7 +63,7 @@ func (sql *SQL) Update(ctx context.Context, io stream.IOStream) error {
|
|||
}
|
||||
|
||||
// create the admin user
|
||||
logging.LogMessage(io, "Creating sql database")
|
||||
logging.LogMessage(progress, "Creating sql database")
|
||||
{
|
||||
if !sqle.IsSafeDatabaseLiteral(sql.Config.DistilleryDatabase) {
|
||||
return errSQLUnsafeDatabaseName
|
||||
|
|
@ -74,7 +75,7 @@ func (sql *SQL) Update(ctx context.Context, io stream.IOStream) error {
|
|||
}
|
||||
|
||||
// wait for the database to come up
|
||||
logging.LogMessage(io, "Waiting for database update to be complete")
|
||||
logging.LogMessage(progress, "Waiting for database update to be complete")
|
||||
sql.WaitQueryTable(ctx)
|
||||
|
||||
tables := []struct {
|
||||
|
|
@ -107,7 +108,7 @@ func (sql *SQL) Update(ctx context.Context, io stream.IOStream) error {
|
|||
// migrate all of the tables!
|
||||
return logging.LogOperation(func() error {
|
||||
for _, table := range tables {
|
||||
logging.LogMessage(io, "migrating %q table", table.name)
|
||||
logging.LogMessage(progress, "migrating %q table", table.name)
|
||||
db, err := sql.QueryTable(ctx, false, table.table)
|
||||
if err != nil {
|
||||
return errSQLUnableToMigrate.WithMessageF(table.name, "unable to access table")
|
||||
|
|
@ -118,5 +119,5 @@ func (sql *SQL) Update(ctx context.Context, io stream.IOStream) error {
|
|||
}
|
||||
}
|
||||
return nil
|
||||
}, io, "migrating database tables")
|
||||
}, progress, "migrating database tables")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue