Skip to content

Commit 4253a69

Browse files
committed
Extract best practices
1 parent fc69f5e commit 4253a69

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

usage-rules.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,4 @@ SPDX-License-Identifier: MIT
1010

1111
AshPostgres is the PostgreSQL data layer for Ash Framework. It's the most fully-featured Ash data layer and should be your default choice unless you have specific requirements for another data layer. Any PostgreSQL version higher than 13 is fully supported.
1212

13-
## Best Practices
14-
15-
1. **Organize migrations**: Run `mix ash.codegen` after each meaningful set of resource changes with a descriptive name:
16-
```bash
17-
mix ash.codegen --name add_user_roles
18-
mix ash.codegen --name implement_post_tagging
19-
```
20-
21-
2. **Use check constraints for domain invariants**: Enforce data integrity at the database level:
22-
```elixir
23-
check_constraints do
24-
check_constraint :valid_status, check: "status IN ('pending', 'active', 'completed')"
25-
check_constraint :positive_balance, check: "balance >= 0"
26-
end
27-
```
28-
29-
3. **Use custom statements for schema-only changes**: If you need to add database objects not directly tied to resources:
30-
```elixir
31-
custom_statements do
32-
statement "CREATE EXTENSION IF NOT EXISTS \"pgcrypto\""
33-
statement "CREATE INDEX users_search_idx ON users USING gin(search_vector)"
34-
end
35-
```
36-
3713
Remember that using AshPostgres provides a full-featured PostgreSQL data layer for your Ash application, giving you both the structure and declarative approach of Ash along with the power and flexibility of PostgreSQL.

usage-rules/best_practices.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!--
2+
SPDX-FileCopyrightText: 2020 Zach Daniel
3+
4+
SPDX-License-Identifier: MIT
5+
-->
6+
7+
# Best Practices
8+
9+
1. **Organize migrations**: Run `mix ash.codegen` after each meaningful set of resource changes with a descriptive name:
10+
```bash
11+
mix ash.codegen --name add_user_roles
12+
mix ash.codegen --name implement_post_tagging
13+
```
14+
15+
2. **Use check constraints for domain invariants**: Enforce data integrity at the database level:
16+
```elixir
17+
check_constraints do
18+
check_constraint :valid_status, check: "status IN ('pending', 'active', 'completed')"
19+
check_constraint :positive_balance, check: "balance >= 0"
20+
end
21+
```
22+
23+
3. **Use custom statements for schema-only changes**: If you need to add database objects not directly tied to resources:
24+
```elixir
25+
custom_statements do
26+
statement "CREATE EXTENSION IF NOT EXISTS \"pgcrypto\""
27+
statement "CREATE INDEX users_search_idx ON users USING gin(search_vector)"
28+
end
29+
```

0 commit comments

Comments
 (0)