add remoteidx

This commit is contained in:
sawka 2022-09-14 12:06:55 -07:00
parent a74ee69da5
commit 002876a07b
5 changed files with 13 additions and 3 deletions

View File

@ -87,7 +87,8 @@ CREATE TABLE remote (
sshopts json NOT NULL, sshopts json NOT NULL,
remoteopts json NOT NULL, remoteopts json NOT NULL,
lastconnectts bigint NOT NULL, lastconnectts bigint NOT NULL,
archived boolean NOT NULL archived boolean NOT NULL,
remoteidx int NOT NULL
); );
CREATE TABLE cmd ( CREATE TABLE cmd (

View File

@ -82,7 +82,8 @@ CREATE TABLE remote (
sshopts json NOT NULL, sshopts json NOT NULL,
remoteopts json NOT NULL, remoteopts json NOT NULL,
lastconnectts bigint NOT NULL, lastconnectts bigint NOT NULL,
archived boolean NOT NULL archived boolean NOT NULL,
remoteidx int NOT NULL
); );
CREATE TABLE cmd ( CREATE TABLE cmd (
sessionid varchar(36) NOT NULL, sessionid varchar(36) NOT NULL,

View File

@ -81,6 +81,7 @@ type RemoteRuntimeState struct {
DefaultState *sstore.RemoteState `json:"defaultstate"` DefaultState *sstore.RemoteState `json:"defaultstate"`
ConnectMode string `json:"connectmode"` ConnectMode string `json:"connectmode"`
Archived bool `json:"archived"` Archived bool `json:"archived"`
RemoteIdx int64 `json:"remoteidx"`
} }
func logf(rem *sstore.RemoteType, fmtStr string, args ...interface{}) { func logf(rem *sstore.RemoteType, fmtStr string, args ...interface{}) {
@ -324,6 +325,7 @@ func (msh *MShellProc) GetRemoteRuntimeState() RemoteRuntimeState {
Status: msh.Status, Status: msh.Status,
ConnectMode: msh.Remote.ConnectMode, ConnectMode: msh.Remote.ConnectMode,
Archived: msh.Remote.Archived, Archived: msh.Remote.Archived,
RemoteIdx: msh.Remote.RemoteIdx,
} }
if msh.Err != nil { if msh.Err != nil {
state.ErrorStr = msh.Err.Error() state.ErrorStr = msh.Err.Error()

View File

@ -30,7 +30,7 @@ func NumSessions(ctx context.Context) (int, error) {
func GetAllRemotes(ctx context.Context) ([]*RemoteType, error) { func GetAllRemotes(ctx context.Context) ([]*RemoteType, error) {
var rtn []*RemoteType var rtn []*RemoteType
err := WithTx(ctx, func(tx *TxWrap) error { err := WithTx(ctx, func(tx *TxWrap) error {
query := `SELECT * FROM remote` query := `SELECT * FROM remote ORDER BY remoteidx`
marr := tx.SelectMaps(query) marr := tx.SelectMaps(query)
for _, m := range marr { for _, m := range marr {
rtn = append(rtn, RemoteFromMap(m)) rtn = append(rtn, RemoteFromMap(m))
@ -121,6 +121,9 @@ func UpsertRemote(ctx context.Context, r *RemoteType) error {
if tx.Exists(query, r.RemoteCanonicalName) { if tx.Exists(query, r.RemoteCanonicalName) {
return fmt.Errorf("remote has duplicate canonicalname '%s', cannot create", r.RemoteCanonicalName) return fmt.Errorf("remote has duplicate canonicalname '%s', cannot create", r.RemoteCanonicalName)
} }
query = `SELECT max(remoteidx) FROM remote`
maxRemoteIdx := tx.GetInt(query)
r.RemoteIdx = int64(maxRemoteIdx + 1)
query = `INSERT INTO remote query = `INSERT INTO remote
( remoteid, physicalid, remotetype, remotealias, remotecanonicalname, remotesudo, remoteuser, remotehost, connectmode, initpk, sshopts, remoteopts, lastconnectts, archived) VALUES ( remoteid, physicalid, remotetype, remotealias, remotecanonicalname, remotesudo, remoteuser, remotehost, connectmode, initpk, sshopts, remoteopts, lastconnectts, archived) VALUES
(:remoteid,:physicalid,:remotetype,:remotealias,:remotecanonicalname,:remotesudo,:remoteuser,:remotehost,:connectmode,:initpk,:sshopts,:remoteopts,:lastconnectts,:archived)` (:remoteid,:physicalid,:remotetype,:remotealias,:remotecanonicalname,:remotesudo,:remoteuser,:remotehost,:connectmode,:initpk,:sshopts,:remoteopts,:lastconnectts,:archived)`

View File

@ -431,6 +431,7 @@ type RemoteType struct {
RemoteOpts *RemoteOptsType `json:"remoteopts"` RemoteOpts *RemoteOptsType `json:"remoteopts"`
LastConnectTs int64 `json:"lastconnectts"` LastConnectTs int64 `json:"lastconnectts"`
Archived bool `json:"archived"` Archived bool `json:"archived"`
RemoteIdx int64 `json:"remoteidx"`
} }
func (r *RemoteType) GetName() string { func (r *RemoteType) GetName() string {
@ -471,6 +472,7 @@ func (r *RemoteType) ToMap() map[string]interface{} {
rtn["remoteopts"] = quickJson(r.RemoteOpts) rtn["remoteopts"] = quickJson(r.RemoteOpts)
rtn["lastconnectts"] = r.LastConnectTs rtn["lastconnectts"] = r.LastConnectTs
rtn["archived"] = r.Archived rtn["archived"] = r.Archived
rtn["remoteidx"] = r.RemoteIdx
return rtn return rtn
} }
@ -493,6 +495,7 @@ func RemoteFromMap(m map[string]interface{}) *RemoteType {
quickSetJson(&r.RemoteOpts, m, "remoteopts") quickSetJson(&r.RemoteOpts, m, "remoteopts")
quickSetInt64(&r.LastConnectTs, m, "lastconnectts") quickSetInt64(&r.LastConnectTs, m, "lastconnectts")
quickSetBool(&r.Archived, m, "archived") quickSetBool(&r.Archived, m, "archived")
quickSetInt64(&r.RemoteIdx, m, "remoteidx")
return &r return &r
} }