Stop soft-deleting Profiles and actually delete them.
The information we're storing in Profiles isn't unique enough that we should go
through the hassle we're going through to soft-delete it.
Add a deleteProfile method to our profileStore, and implement it for our
postgres and memstore implementations.
Add a DeleteProfile wrapper for our Context.
Remove the Deleted property from the Profile type and the ProfileChange type,
and update references to it.
Stop cleaning up after our Profile in the UpdateProfileHandler, because there's
no longer any way to delete the Profile from the UpdateProfileHandler.
Update our get/list* methods so they don't filter on the non-existent Deleted
property anymore.
Update our SQL schema definition to not include the deleted column.
Update our profile tests to use the DeleteProfile method and stop comparing the
no-longer-existing Deleted property.
5 "github.com/secondbit/pan"
8 func (s Scope) GetSQLTableName() string {
12 func (p *postgres) createScopesSQL(scopes []Scope) *pan.Query {
13 fields, _ := pan.GetFields(scopes[0])
14 query := pan.New(pan.POSTGRES, "INSERT INTO "+pan.GetTableName(scopes[0]))
15 query.Include("(" + pan.QueryList(fields) + ")")
16 query.Include("VALUES")
17 query.FlushExpressions(" ")
18 for _, scope := range scopes {
19 _, values := pan.GetFields(scope)
20 query.Include("("+pan.VariableList(len(values))+")", values...)
22 return query.FlushExpressions(", ")
25 func (p *postgres) createScopes(scopes []Scope) error {
29 query := p.createScopesSQL(scopes)
30 _, err := p.db.Exec(query.String(), query.Args...)
31 if e, ok := err.(*pq.Error); ok && e.Constraint == "scopes_pkey" {
32 err = ErrScopeAlreadyExists
37 func (p *postgres) getScopesSQL(ids []string) *pan.Query {
39 intids := make([]interface{}, len(ids))
40 for pos, id := range ids {
43 fields, _ := pan.GetFields(scope)
44 query := pan.New(pan.POSTGRES, "SELECT "+pan.QueryList(fields)+" FROM "+pan.GetTableName(scope))
46 query.Include(pan.GetUnquotedColumn(scope, "ID") + " IN")
47 query.Include("("+pan.VariableList(len(ids))+")", intids...)
48 return query.FlushExpressions(" ")
51 func (p *postgres) getScopes(ids []string) ([]Scope, error) {
52 query := p.getScopesSQL(ids)
53 rows, err := p.db.Query(query.String(), query.Args...)
60 err := pan.Unmarshal(rows, &scope)
64 scopes = append(scopes, scope)
66 if err = rows.Err(); err != nil {
72 func (p *postgres) updateScopeSQL(id string, change ScopeChange) *pan.Query {
74 query := pan.New(pan.POSTGRES, "UPDATE "+pan.GetTableName(scope)+" SET ")
75 query.IncludeIfNotNil(pan.GetUnquotedColumn(scope, "Name")+" = ?", change.Name)
76 query.IncludeIfNotNil(pan.GetUnquotedColumn(scope, "Description")+" = ?", change.Description)
77 query.FlushExpressions(", ")
79 query.Include(pan.GetUnquotedColumn(scope, "ID")+" = ?", id)
80 return query.FlushExpressions(" ")
83 func (p *postgres) updateScope(id string, change ScopeChange) error {
87 query := p.updateScopeSQL(id, change)
88 res, err := p.db.Exec(query.String(), query.Args...)
92 rows, err := res.RowsAffected()
97 return ErrScopeNotFound
102 func (p *postgres) removeScopesSQL(ids []string) *pan.Query {
104 intids := make([]interface{}, len(ids))
105 for pos, id := range ids {
108 query := pan.New(pan.POSTGRES, "DELETE FROM "+pan.GetTableName(scope))
110 query.Include(pan.GetUnquotedColumn(scope, "ID") + " IN")
111 query.Include("("+pan.VariableList(len(ids))+")", intids...)
112 return query.FlushExpressions(" ")
115 func (p *postgres) removeScopes(ids []string) error {
116 query := p.removeScopesSQL(ids)
117 res, err := p.db.Exec(query.String(), query.Args...)
121 rows, err := res.RowsAffected()
126 return ErrScopeNotFound
131 func (p *postgres) listScopesSQL() *pan.Query {
133 fields, _ := pan.GetFields(scope)
134 query := pan.New(pan.POSTGRES, "SELECT "+pan.QueryList(fields)+" FROM "+pan.GetTableName(scope))
135 return query.FlushExpressions(" ")
138 func (p *postgres) listScopes() ([]Scope, error) {
139 query := p.listScopesSQL()
140 rows, err := p.db.Query(query.String(), query.Args...)
142 return []Scope{}, err
147 err = pan.Unmarshal(rows, &scope)
151 scopes = append(scopes, scope)
153 if err = rows.Err(); err != nil {