func scanExpandedFormation(s postgres.Scanner) (*ct.ExpandedFormation, error) { f := &ct.ExpandedFormation{ App: &ct.App{}, Release: &ct.Release{}, } var artifactIDs string err := s.Scan( &f.App.ID, &f.App.Name, &f.App.Meta, &f.Release.ID, &artifactIDs, &f.Release.Meta, &f.Release.Env, &f.Release.Processes, &f.Processes, &f.Tags, &f.UpdatedAt, ) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } if artifactIDs != "" { f.Release.ArtifactIDs = split(artifactIDs[1:len(artifactIDs)-1], ",") } return f, nil }
func scanExpandedFormation(s postgres.Scanner) (*ct.ExpandedFormation, error) { f := &ct.ExpandedFormation{ App: &ct.App{}, Release: &ct.Release{}, Artifact: &ct.Artifact{}, } var artifactID *string err := s.Scan( &f.App.ID, &f.App.Name, &f.Release.ID, &artifactID, &f.Release.Meta, &f.Release.Env, &f.Release.Processes, &f.Artifact.ID, &f.Artifact.Type, &f.Artifact.URI, &f.Processes, &f.Tags, &f.UpdatedAt, ) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } if artifactID != nil { f.Release.ArtifactID = *artifactID } return f, nil }
func scanJob(s postgres.Scanner) (*ct.Job, error) { job := &ct.Job{} var state string err := s.Scan( &job.ID, &job.UUID, &job.HostID, &job.AppID, &job.ReleaseID, &job.Type, &state, &job.Meta, &job.ExitStatus, &job.HostError, &job.RunAt, &job.Restarts, &job.CreatedAt, &job.UpdatedAt, &job.Args, ) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } job.State = ct.JobState(state) return job, nil }
func scanArtifact(s postgres.Scanner) (*ct.Artifact, error) { artifact := &ct.Artifact{} err := s.Scan(&artifact.ID, &artifact.Type, &artifact.URI, &artifact.CreatedAt) if err == pgx.ErrNoRows { err = ErrNotFound } return artifact, err }
func scanProvider(s postgres.Scanner) (*ct.Provider, error) { p := &ct.Provider{} err := s.Scan(&p.ID, &p.Name, &p.URL, &p.CreatedAt, &p.UpdatedAt) if err == pgx.ErrNoRows { err = ErrNotFound } return p, err }
func scanKey(s postgres.Scanner) (*ct.Key, error) { key := &ct.Key{} err := s.Scan(&key.ID, &key.Key, &key.Comment, &key.CreatedAt) if err == sql.ErrNoRows { err = ErrNotFound } return key, err }
func scanArtifact(s postgres.Scanner) (*ct.Artifact, error) { artifact := &ct.Artifact{} err := s.Scan(&artifact.ID, &artifact.Type, &artifact.URI, &artifact.CreatedAt) if err == sql.ErrNoRows { err = ErrNotFound } artifact.ID = postgres.CleanUUID(artifact.ID) return artifact, err }
func scanArtifact(s postgres.Scanner) (*ct.Artifact, error) { artifact := &ct.Artifact{} var typ string err := s.Scan(&artifact.ID, &typ, &artifact.URI, &artifact.Meta, &artifact.CreatedAt) if err == pgx.ErrNoRows { err = ErrNotFound } artifact.Type = host.ArtifactType(typ) return artifact, err }
func scanFormation(s postgres.Scanner) (*ct.Formation, error) { f := &ct.Formation{} err := s.Scan(&f.AppID, &f.ReleaseID, &f.Processes, &f.Tags, &f.CreatedAt, &f.UpdatedAt) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } return f, err }
func scanJob(s postgres.Scanner) (*ct.Job, error) { job := &ct.Job{} err := s.Scan(&job.ID, &job.AppID, &job.ReleaseID, &job.Type, &job.State, &job.Meta, &job.CreatedAt, &job.UpdatedAt) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } return job, nil }
func scanJobEvent(s postgres.Scanner) (*ct.JobEvent, error) { event := &ct.JobEvent{} err := s.Scan(&event.ID, &event.JobID, &event.AppID, &event.ReleaseID, &event.Type, &event.State, &event.CreatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } event.AppID = postgres.CleanUUID(event.AppID) event.ReleaseID = postgres.CleanUUID(event.ReleaseID) return event, nil }
func scanJob(s postgres.Scanner) (*ct.Job, error) { job := &ct.Job{} var meta []byte err := s.Scan(&job.ID, &job.AppID, &job.ReleaseID, &job.Type, &job.State, &meta, &job.CreatedAt, &job.UpdatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } err = json.Unmarshal(meta, &job.Meta) return job, nil }
func scanResource(s postgres.Scanner) (*ct.Resource, error) { r := &ct.Resource{} var appIDs string err := s.Scan(&r.ID, &r.ProviderID, &r.ExternalID, &r.Env, &appIDs, &r.CreatedAt) if err == pgx.ErrNoRows { return nil, ErrNotFound } else if err != nil { return nil, err } if appIDs != "" { r.Apps = split(appIDs[1:len(appIDs)-1], ",") } return r, err }
func scanApp(s postgres.Scanner) (*ct.App, error) { app := &ct.App{} var releaseID *string err := s.Scan(&app.ID, &app.Name, &app.Meta, &app.Strategy, &releaseID, &app.CreatedAt, &app.UpdatedAt) if err == pgx.ErrNoRows { return nil, ErrNotFound } else if err != nil { return nil, err } if releaseID != nil { app.ReleaseID = *releaseID } return app, err }
func scanFormation(s postgres.Scanner) (*ct.Formation, error) { f := &ct.Formation{} var procs []byte err := s.Scan(&f.AppID, &f.ReleaseID, &procs, &f.CreatedAt, &f.UpdatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } if len(procs) > 0 { err = json.Unmarshal(procs, &f.Processes) } return f, err }
func scanRelease(s postgres.Scanner) (*ct.Release, error) { var artifactID *string release := &ct.Release{} err := s.Scan(&release.ID, &artifactID, &release.Env, &release.Processes, &release.Meta, &release.CreatedAt) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } if artifactID != nil { release.ArtifactID = *artifactID } return release, err }
func scanExpandedFormation(s postgres.Scanner) (*ct.ExpandedFormation, error) { f := &ct.ExpandedFormation{ App: &ct.App{}, Release: &ct.Release{}, } var artifactIDs string var appReleaseID *string err := s.Scan( &f.App.ID, &f.App.Name, &f.App.Meta, &f.App.Strategy, &appReleaseID, &f.App.DeployTimeout, &f.App.CreatedAt, &f.App.UpdatedAt, &f.Release.ID, &artifactIDs, &f.Release.Meta, &f.Release.Env, &f.Release.Processes, &f.Release.CreatedAt, &f.Processes, &f.Tags, &f.UpdatedAt, &f.Deleted, ) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } if appReleaseID != nil { f.App.ReleaseID = *appReleaseID } if f.App.Meta == nil { // ensure we don't return `{"meta": null}` f.App.Meta = make(map[string]string) } if artifactIDs != "" { f.Release.ArtifactIDs = split(artifactIDs[1:len(artifactIDs)-1], ",") if len(f.Release.ArtifactIDs) > 0 { f.Release.LegacyArtifactID = f.Release.ArtifactIDs[0] } } return f, nil }
func scanRelease(s postgres.Scanner) (*ct.Release, error) { var artifactIDs string release := &ct.Release{} err := s.Scan(&release.ID, &artifactIDs, &release.Env, &release.Processes, &release.Meta, &release.CreatedAt) if err != nil { if err == pgx.ErrNoRows { err = ErrNotFound } return nil, err } if artifactIDs != "" { release.ArtifactIDs = split(artifactIDs[1:len(artifactIDs)-1], ",") release.LegacyArtifactID = release.ImageArtifactID() } return release, err }
func scanAppEvent(s postgres.Scanner) (*ct.AppEvent, error) { var event ct.AppEvent var typ string var data []byte err := s.Scan(&event.ID, &event.AppID, &event.ObjectID, &typ, &data, &event.CreatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } event.AppID = postgres.CleanUUID(event.AppID) event.ObjectType = ct.EventType(typ) event.Data = json.RawMessage(data) return &event, nil }
func scanApp(s postgres.Scanner) (*ct.App, error) { app := &ct.App{} var meta hstore.Hstore err := s.Scan(&app.ID, &app.Name, &meta, &app.Strategy, &app.CreatedAt, &app.UpdatedAt) if err == sql.ErrNoRows { err = ErrNotFound } if len(meta.Map) > 0 { app.Meta = make(map[string]string, len(meta.Map)) for k, v := range meta.Map { app.Meta[k] = v.String } } app.ID = postgres.CleanUUID(app.ID) return app, err }
func scanDeployment(s postgres.Scanner) (*ct.Deployment, error) { d := &ct.Deployment{} var oldReleaseID *string var status *string err := s.Scan(&d.ID, &d.AppID, &oldReleaseID, &d.NewReleaseID, &d.Strategy, &status, &d.Processes, &d.DeployTimeout, &d.CreatedAt, &d.FinishedAt) if err == pgx.ErrNoRows { err = ErrNotFound } if oldReleaseID != nil { d.OldReleaseID = *oldReleaseID } if status != nil { d.Status = *status } return d, err }
func (rr *ResourceRepo) Add(r *ct.Resource) error { if r.ID == "" { r.ID = random.UUID() } tx, err := rr.db.Begin() if err != nil { return err } err = tx.QueryRow("resource_insert", r.ID, r.ProviderID, r.ExternalID, r.Env).Scan(&r.CreatedAt) if err != nil { tx.Rollback() return err } for i, appID := range r.Apps { var row postgres.Scanner if idPattern.MatchString(appID) { row = tx.QueryRow("app_resource_insert_app_by_name_or_id", appID, appID, r.ID) } else { row = tx.QueryRow("app_resource_insert_app_by_name", appID, r.ID) } if err := row.Scan(&r.Apps[i]); err != nil { tx.Rollback() return err } } for _, appID := range r.Apps { if err := createEvent(tx.Exec, &ct.Event{ AppID: appID, ObjectID: r.ID, ObjectType: ct.EventTypeResource, }, r); err != nil { tx.Rollback() return err } } if len(r.Apps) == 0 { // Ensure an event is created if there are no associated apps if err := createEvent(tx.Exec, &ct.Event{ ObjectID: r.ID, ObjectType: ct.EventTypeResource, }, r); err != nil { tx.Rollback() return err } } return tx.Commit() }
func scanResource(s postgres.Scanner) (*ct.Resource, error) { r := &ct.Resource{} var env hstore.Hstore var appIDs string err := s.Scan(&r.ID, &r.ProviderID, &r.ExternalID, &env, &appIDs, &r.CreatedAt) if err == sql.ErrNoRows { err = ErrNotFound } r.Env = make(map[string]string, len(env.Map)) for k, v := range env.Map { r.Env[k] = v.String } if appIDs != "" { r.Apps = split(appIDs[1:len(appIDs)-1], ",") } return r, err }
func scanRelease(s postgres.Scanner) (*ct.Release, error) { var artifactID *string release := &ct.Release{} var data []byte err := s.Scan(&release.ID, &artifactID, &data, &release.CreatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } if artifactID != nil { release.ArtifactID = *artifactID } err = json.Unmarshal(data, release) return release, err }
func scanApp(s postgres.Scanner) (*ct.App, error) { app := &ct.App{} var meta []byte var releaseID *string err := s.Scan(&app.ID, &app.Name, &meta, &app.Strategy, &releaseID, &app.CreatedAt, &app.UpdatedAt) if err == sql.ErrNoRows { return nil, ErrNotFound } else if err != nil { return nil, err } if releaseID != nil { app.ReleaseID = *releaseID } if len(meta) > 0 { err = json.Unmarshal(meta, &app.Meta) } return app, err }
func scanApp(s postgres.Scanner) (*ct.App, error) { app := &ct.App{} var releaseID *string err := s.Scan(&app.ID, &app.Name, &app.Meta, &app.Strategy, &releaseID, &app.DeployTimeout, &app.CreatedAt, &app.UpdatedAt) if err == pgx.ErrNoRows { return nil, ErrNotFound } else if err != nil { return nil, err } if releaseID != nil { app.ReleaseID = *releaseID } if app.Meta == nil { // ensure `{}` rather than `null` when serializing to JSON app.Meta = map[string]string{} } return app, err }
func scanJob(s postgres.Scanner) (*ct.Job, error) { job := &ct.Job{} var meta hstore.Hstore err := s.Scan(&job.ID, &job.AppID, &job.ReleaseID, &job.Type, &job.State, &meta, &job.CreatedAt, &job.UpdatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } if len(meta.Map) > 0 { job.Meta = make(map[string]string, len(meta.Map)) for k, v := range meta.Map { job.Meta[k] = v.String } } return job, nil }
func scanArtifact(s postgres.Scanner) (*ct.Artifact, error) { artifact := &ct.Artifact{} var typ string var size *int64 var layerURLTemplate *string err := s.Scan(&artifact.ID, &typ, &artifact.URI, &artifact.Meta, &artifact.RawManifest, &artifact.Hashes, &size, &layerURLTemplate, &artifact.CreatedAt) if err == pgx.ErrNoRows { err = ErrNotFound } artifact.Type = ct.ArtifactType(typ) if size != nil { artifact.Size = *size } if layerURLTemplate != nil { artifact.LayerURLTemplate = *layerURLTemplate } return artifact, err }
func scanFormation(s postgres.Scanner) (*ct.Formation, error) { f := &ct.Formation{} var procs hstore.Hstore err := s.Scan(&f.AppID, &f.ReleaseID, &procs, &f.CreatedAt, &f.UpdatedAt) if err != nil { if err == sql.ErrNoRows { err = ErrNotFound } return nil, err } f.Processes = make(map[string]int, len(procs.Map)) for k, v := range procs.Map { n, _ := strconv.Atoi(v.String) if n > 0 { f.Processes[k] = n } } return f, nil }
func scanDeployment(s postgres.Scanner) (*ct.Deployment, error) { d := &ct.Deployment{} var procs hstore.Hstore err := s.Scan(&d.ID, &d.AppID, &d.OldReleaseID, &d.NewReleaseID, &d.Strategy, &procs, &d.CreatedAt, &d.FinishedAt) if err == sql.ErrNoRows { err = ErrNotFound } d.Processes = make(map[string]int, len(procs.Map)) for k, v := range procs.Map { n, _ := strconv.Atoi(v.String) if n > 0 { d.Processes[k] = n } } d.ID = postgres.CleanUUID(d.ID) d.AppID = postgres.CleanUUID(d.AppID) d.OldReleaseID = postgres.CleanUUID(d.OldReleaseID) d.NewReleaseID = postgres.CleanUUID(d.NewReleaseID) return d, err }