Skip to content

🎧 Your Personal Streaming Service

Loosen up constraints for `email`. Fixes #362

Deluan45e708f5913a
diff --git a/db/db.go b/db/db.go
index 85c76baa2..b1ba2e2a2 100644
--- a/db/db.go
+++ b/db/db.go
@@ -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)
diff --git a/db/migrations/20200819111809_drop_email_unique_constraint.go b/db/migrations/20200819111809_drop_email_unique_constraint.go
new file mode 100644
index 000000000..886dff541
--- /dev/null
+++ b/db/migrations/20200819111809_drop_email_unique_constraint.go
@@ -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
+}
diff --git a/ui/src/user/UserCreate.js b/ui/src/user/UserCreate.js
index ab50c5fe8..9966930d8 100644
--- a/ui/src/user/UserCreate.js
+++ b/ui/src/user/UserCreate.js
@@ -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>