Skip to content

Commit

Permalink
Add docs about Unique Constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
amitaibu committed Mar 16, 2024
1 parent f2dbbea commit fa08a0c
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Guide/database.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -765,14 +765,6 @@ Similarly as for renaming, deleting a column currently won't work automatically
1. Delete your column in the Schema Designer
2. Delete the column from the database by executing `ALTER TABLE tablename DROP COLUMN colname`
### Alternate Method
There's always more than one way. This is another.
1. Make changes in the Schema Designer
2. Click `Save DB to Fixtures` in the Schema Designer (Use the arrow next to the `Update DB` button to see this option)
3. Edit `Fixtures.sql` to your heart's content.
4. Click `Push to DB` in the Schema Designer (Use the arrow next to the `Update DB` button to see this option)
### Migrations In Production
Expand Down Expand Up @@ -848,3 +840,16 @@ action CreateUserAction = do
redirectTo NewSessionAction
```
## Unique Constraints
It's possible to use the UI to set the unique constraint on a column. However, sometimes you might want to add a unique constraint on multiple columns. This can be done by adding a unique constraint to the `Schema.sql` file. For example, to add a unique constraint on the `email` and `username` columns of the `users` table, you would add the following to the `Schema.sql` file:
```sql
CREATE TABLE users (
id UUID DEFAULT uuid_generate_v4() PRIMARY KEY NOT NULL,
email TEXT NOT NULL,
username TEXT NOT NULL,
UNIQUE (email, username)
);
```

0 comments on commit fa08a0c

Please sign in to comment.