Changeset 324 in code for trunk/cmd/sojuctl/main.go


Ignore:
Timestamp:
Jun 8, 2020, 9:59:03 AM (5 years ago)
Author:
contact
Message:

Introduce User.Created

For Network and Channel, the database only needed to define one Store
operation to create/update a record. However since User is missing an ID
we couldn't have a single StoreUser function like other types. We had
CreateUser and UpdatePassword. As new User fields get added (e.g. the
upcoming Admin flag) this isn't sustainable.

We could have CreateUser and UpdateUser, but this wouldn't be consistent
with other types. Instead, introduce User.Created which indicates
whether the record is already stored in the DB. This can be used in a
new StoreUser function to decide whether we need to UPDATE or INSERT
without relying on SQL constraints and INSERT OR UPDATE.

The ListUsers and GetUser functions set User.Created to true.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cmd/sojuctl/main.go

    r308 r324  
    7070                        Password: string(hashed),
    7171                }
    72                 if err := db.CreateUser(&user); err != nil {
     72                if err := db.StoreUser(&user); err != nil {
    7373                        log.Fatalf("failed to create user: %v", err)
    7474                }
     
    9191
    9292                user := soju.User{
     93                        Created:  true,
    9394                        Username: username,
    9495                        Password: string(hashed),
    9596                }
    96                 if err := db.UpdatePassword(&user); err != nil {
     97                if err := db.StoreUser(&user); err != nil {
    9798                        log.Fatalf("failed to update password: %v", err)
    9899                }
    99 
    100100        default:
    101101                flag.Usage()
Note: See TracChangeset for help on using the changeset viewer.