Skip to content

Commit

Permalink
Loosen up constraints for email. Fixes #362
Browse files Browse the repository at this point in the history
  • Loading branch information
deluan committed Aug 19, 2020
1 parent 6081299 commit 45e708f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
14 changes: 13 additions & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ func Db() *sql.DB {
func EnsureLatestVersion() {
db := Db()

err := goose.SetDialect(Driver)
// Disable foreign_keys to allow re-creating tables in migrations
_, err := db.Exec("PRAGMA foreign_keys=off")
defer func() {
_, err := db.Exec("PRAGMA foreign_keys=on")
if err != nil {
log.Error("Error re-enabling foreign_keys", err)
}
}()
if err != nil {
log.Error("Error disabling foreign_keys", err)
}

err = goose.SetDialect(Driver)
if err != nil {
log.Error("Invalid DB driver", "driver", Driver, err)
os.Exit(1)
Expand Down
42 changes: 42 additions & 0 deletions db/migrations/20200819111809_drop_email_unique_constraint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package migrations

import (
"database/sql"

"github.com/pressly/goose"
)

func init() {
goose.AddMigration(upDropEmailUniqueConstraint, downDropEmailUniqueConstraint)
}

func upDropEmailUniqueConstraint(tx *sql.Tx) error {
_, err := tx.Exec(`
create table user_dg_tmp
(
id varchar(255) not null
primary key,
user_name varchar(255) default '' not null
unique,
name varchar(255) default '' not null,
email varchar(255) default '' not null,
password varchar(255) default '' not null,
is_admin bool default FALSE not null,
last_login_at datetime,
last_access_at datetime,
created_at datetime not null,
updated_at datetime not null
);
insert into user_dg_tmp(id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at) select id, user_name, name, email, password, is_admin, last_login_at, last_access_at, created_at, updated_at from user;
drop table user;
alter table user_dg_tmp rename to user;
`)
return err
}

func downDropEmailUniqueConstraint(tx *sql.Tx) error {
return nil
}
2 changes: 1 addition & 1 deletion ui/src/user/UserCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const UserCreate = (props) => {
<SimpleForm redirect="list" variant={'outlined'}>
<TextInput source="userName" validate={[required()]} />
<TextInput source="name" validate={[required()]} />
<TextInput source="email" validate={[required(), email()]} />
<TextInput source="email" validate={[email()]} />
<PasswordInput source="password" validate={[required()]} />
<BooleanInput source="isAdmin" defaultValue={false} />
</SimpleForm>
Expand Down

0 comments on commit 45e708f

Please sign in to comment.