Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs about Unique Constraints #1933

Merged
merged 1 commit into from
Mar 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
);
```
Loading