@@ 66,19 66,19 @@ func migrations() []string {
schema_version INTEGER
)`, migrationsTable),
fmt.Sprintf(`CREATE TABLE users (
- id INTEGER NOT NULL PRIMARY KEY,
- ulid TEXT NOT NULL,
+ id TEXT NOT NULL PRIMARY KEY,
email TEXT NOT NULL,
pwd TEXT NOT NULL,
is_admin INTEGER DEFAULT FALSE NOT NULL,
- UNIQUE(ulid, email)
+ UNIQUE(id, email)
)`),
fmt.Sprintf(`CREATE TABLE domains (
id TEXT NOT NULL PRIMARY KEY,
apikey TEXT NOT NULL,
- owner INTEGER NOT NULL,
- ddns_domain TEXT,
+ owner TEXT NOT NULL,
+ ddns_domain TEXT NOT NULL,
a_record TEXT,
+ UNIQUE(id, ddns_domain),
FOREIGN KEY(owner) REFERENCES users(id)
)`),
}
@@ 23,7 23,7 @@ func CreateUser(email string, pwd string) error {
ulid := ulid.Make().String()
- _, err = DBConn.Exec(`INSERT INTO users(ulid, email, pwd) VALUES ($1, $2, $3)`,
+ _, err = DBConn.Exec(`INSERT INTO users(id, email, pwd) VALUES ($1, $2, $3)`,
ulid, email, string(encoded))
if err != nil {
return err
@@ 41,7 41,7 @@ func CreateAdmin(email string, pwd string) error {
ulid := ulid.Make().String()
- _, err = DBConn.Exec(`INSERT INTO users(ulid, email, pwd, is_admin) VALUES ($1, $2, $3, TRUE)`,
+ _, err = DBConn.Exec(`INSERT INTO users(id, email, pwd, is_admin) VALUES ($1, $2, $3, TRUE)`,
ulid, email, string(encoded))
if err != nil {
return err
@@ 51,7 51,7 @@ func CreateAdmin(email string, pwd string) error {
}
type User struct {
- Ulid string
+ Id string
Email string
IsAdmin bool
}
@@ 59,8 59,8 @@ type User struct {
func FetchUserWithCreds(email string, pwd string) (*User, error) {
user := User{ Email: email }
var encodedPwd string
- err := DBConn.QueryRow(`SELECT ulid, pwd FROM users WHERE email = $1`,
- email).Scan(&user.Ulid, &encodedPwd)
+ err := DBConn.QueryRow(`SELECT id, pwd FROM users WHERE email = $1`,
+ email).Scan(&user.Id, &encodedPwd)
if err == sql.ErrNoRows {
return nil, errors.New("User not found")
}
@@ 79,10 79,10 @@ func FetchUserWithCreds(email string, pwd string) (*User, error) {
return &user, nil
}
-func FetchUserWithUlid(ulid string) (*User, error) {
- user := User{ Ulid: ulid }
- err := DBConn.QueryRow(`SELECT email, is_admin FROM users WHERE ulid = $1`,
- ulid).Scan(&user.Email, &user.IsAdmin)
+func FetchUserWithId(id string) (*User, error) {
+ user := User{ Id: id }
+ err := DBConn.QueryRow(`SELECT email, is_admin FROM users WHERE id = $1`,
+ id).Scan(&user.Email, &user.IsAdmin)
if err == sql.ErrNoRows {
return nil, errors.New("User not found")
}
@@ 94,7 94,7 @@ func FetchUserWithUlid(ulid string) (*User, error) {
}
func FetchAllUsers() ([]User, error) {
- rows, err := DBConn.Query(`SELECT ulid, email, is_admin FROM users`)
+ rows, err := DBConn.Query(`SELECT id, email, is_admin FROM users`)
if err != nil {
return nil, err
}
@@ 103,7 103,7 @@ func FetchAllUsers() ([]User, error) {
var users []User
for rows.Next() {
var user User
- err = rows.Scan(&user.Ulid, &user.Email, &user.IsAdmin)
+ err = rows.Scan(&user.Id, &user.Email, &user.IsAdmin)
if err != nil {
return nil, err
}