Skip to content

Commit 38eec0b

Browse files
committed
docs: reformat docs and revisit certain guides
improvement: support `mix ash.rollback` with interactive rollback
1 parent a02653e commit 38eec0b

22 files changed

+277
-131
lines changed

config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ if Mix.env() == :test do
1818
config :ash, :validate_domain_resource_inclusion?, false
1919
config :ash, :validate_domain_config_inclusion?, false
2020

21+
config :ash_postgres, :ash_domains, [AshPostgres.Test.Domain]
22+
2123
config :ash_postgres, AshPostgres.TestRepo,
2224
username: "postgres",
2325
database: "ash_postgres_test",

documentation/dsls/DSL:-AshPostgres.DataLayer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ end
5252
| [`migration_ignore_attributes`](#postgres-migration_ignore_attributes){: #postgres-migration_ignore_attributes } | `list(atom)` | `[]` | A list of attributes that will be ignored when generating migrations. |
5353
| [`table`](#postgres-table){: #postgres-table } | `String.t` | | The table to store and read the resource from. If this is changed, the migration generator will not remove the old table. |
5454
| [`schema`](#postgres-schema){: #postgres-schema } | `String.t` | | The schema that the table is located in. Schema-based multitenancy will supercede this option. If this is changed, the migration generator will not remove the old schema. |
55-
| [`polymorphic?`](#postgres-polymorphic?){: #postgres-polymorphic? } | `boolean` | `false` | Declares this resource as polymorphic. See the [polymorphic resources guide](/documentation/topics/polymorphic_resources.md) for more. |
55+
| [`polymorphic?`](#postgres-polymorphic?){: #postgres-polymorphic? } | `boolean` | `false` | Declares this resource as polymorphic. See the [polymorphic resources guide](/documentation/topics/resources/polymorphic-resources.md) for more. |
5656

5757

5858
## postgres.custom_indexes

documentation/home.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# AshPostgres Documentation
2+
3+
Welcome! This documentation is for `AshPostgres`, the PostgreSQL data layer for [Ash Framework](https://hexdocs.pm/ash). If you have not yet, please see the [Ash Framework documentation](https://hexdocs.pm/ash).
4+
5+
## Dive In
6+
7+
- [Get Started](documentation/tutorials/get-started-with-postgres.md)
8+
9+
---
10+
11+
## Tutorials
12+
13+
- [Get Started](documentation/tutorials/get-started-with-postgres.md)
14+
15+
## Topics
16+
17+
### Resources
18+
19+
- [References](documentation/topics/resources/references.md)
20+
- [Polymorphic Resources](documentation/topics/resources/polymorphic-resources.md)
21+
22+
### Development
23+
24+
- [Migrations and tasks](documentation/topics/development/migrations-and-tasks.md)
25+
- [Testing](documentation/topics/development/testing.md)
26+
- [Upgrading to 2.0](documentation/topics/development/upgrading-to-2.0.md)
27+
28+
### Advanced
29+
30+
- [Expressions](documentation/topics/advanced/expressions.md)
31+
- [Manual Relationships](documentation/topics/advanced/manual-relationships.md)
32+
- [Schema Based Multitenancy](documentation/topics/advanced/schema-based-multitenancy.md)

documentation/how_to/using-fragments.md

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Expressions
2+
3+
In addition to the expressions listed in the [Ash expressions guide](https://hexdocs.pm/ash/expressions.html), AshPostgres provides the following expressions
4+
5+
# Fragments
6+
7+
Fragments allow you to use arbitrary postgres expressions in your queries. Fragments can often be an escape hatch to allow you to do things that don't have something officially supported with Ash.
8+
9+
### Examples
10+
11+
#### Simple expressions
12+
13+
```elixir
14+
fragment("? / ?", points, count)
15+
```
16+
17+
#### Calling functions
18+
19+
```elixir
20+
fragment("repeat('hello', 4)")
21+
```
22+
23+
#### Using entire queries
24+
25+
```elixir
26+
fragment("points > (SELECT SUM(points) FROM games WHERE user_id = ? AND id != ?)", user_id, id)
27+
```
28+
29+
> ### a last resport {: .warning}
30+
>
31+
> Using entire queries as shown above is a last resort, but can sometimes be the best way to accomplish a given task.
32+
33+
#### In calculations
34+
35+
```elixir
36+
calculations do
37+
calculate :lower_name, :string, expr(
38+
fragment("LOWER(?)", name)
39+
)
40+
end
41+
```
42+
43+
#### In migrations
44+
45+
```elixir
46+
create table(:managers, primary_key: false) do
47+
add :id, :uuid, null: false, default: fragment("UUID_GENERATE_V4()"), primary_key: true
48+
end
49+
```
50+
51+
## Like and ILike
52+
53+
These wrap the postgres builtin like and ilike operators.
54+
55+
Please be aware, these match *patterns* not raw text. Use `contains/1` if you want to match text without supporting patterns, i.e `%` and `_` have semantic meaning!
56+
57+
For example:
58+
59+
```elixir
60+
Ash.Query.filter(User, like(name, "%obo%")) # name contains obo anywhere in the string, case sensitively
61+
```
62+
63+
```elixir
64+
Ash.Query.filter(User, ilike(name, "%ObO%")) # name contains ObO anywhere in the string, case insensitively
65+
```
66+
67+
## Trigram similarity
68+
69+
To use this expression, you must have the `pg_trgm` extension in your repos `installed_extensions` list.
70+
71+
This calls the `similarity` function from that extension. See more https://www.postgresql.org/docs/current/pgtrgm.htmlhere: https://www.postgresql.org/docs/current/pgtrgm.html
72+
73+
For example:
74+
75+
```elixir
76+
Ash.Query.filter(User, trigram_similarity(first_name, "fred") > 0.8)
77+
```

documentation/how_to/join-manual-relationships.md renamed to documentation/topics/advanced/manual-relationships.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Join Manual Relationships
1+
# Manual Relationships
22

33
See [Defining Manual Relationships](https://hexdocs.pm/ash/defining-manual-relationships.html) for an idea of manual relationships in general.
44
Manual relationships allow for expressing complex/non-typical relationships between resources in a standard way.

documentation/topics/schema-based-multitenancy.md renamed to documentation/topics/advanced/schema-based-multitenancy.md

File renamed without changes.
File renamed without changes.

documentation/how_to/test-with-postgres.md renamed to documentation/topics/development/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Testing With Postgres
1+
# Testinging with AshPostgres
22

33
When using AshPostgres resources in tests, you will likely want to include use a test case similar to the following. This will ensure that your repo runs everything in a transaction.
44

documentation/how_to/upgrade.md renamed to documentation/topics/development/upgrading-to-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Upgrade from 1.0 to 2.0
1+
# Upgrading to 2.0
22

33
There are only three breaking changes in this release, one of them is very significant, the other two are minor.
44

0 commit comments

Comments
 (0)