Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
3e4d654
begins ecto adapter, #38
Danwhy Feb 14, 2019
33f3102
updates test app and repo for adapter, #38
Danwhy Feb 15, 2019
403bb1a
adds create execute_ddl function clause, #44
Danwhy Feb 18, 2019
8be05cb
adds execute_ddl alter function clause, #44
Danwhy Feb 18, 2019
ae010d8
adds execute_ddl create index function clause, #44
Danwhy Feb 18, 2019
54187b8
accounts for schema_migration table in create clause, #44
Danwhy Feb 18, 2019
c0dadca
adds all required colmns, only if they are missing, #44
Danwhy Feb 19, 2019
85aa257
adds tests for migrations, #44
Danwhy Feb 20, 2019
94808f3
adds remaining defdelgate to required functions #45
RobStallion Feb 28, 2019
e1f11ff
reorder function definitions to match behavior's order #45
RobStallion Feb 28, 2019
7735134
adds update functionality, #46
Danwhy Feb 28, 2019
87a7f9b
adds excid as dep #45
RobStallion Feb 28, 2019
44f96fc
creates an insert function which adds cid and entry_id to params #45
RobStallion Feb 28, 2019
19f0529
merges with insert
Danwhy Feb 28, 2019
4f9b4ea
removes previous migration files #45
RobStallion Mar 1, 2019
3818a4e
Creates migration and schema for comments table
RobStallion Mar 1, 2019
8a3e176
removes previous schema files #45
RobStallion Mar 1, 2019
f906baf
comment out all previous tests #45
RobStallion Mar 1, 2019
ad66390
remove functions that were causing errors #45
RobStallion Mar 1, 2019
eaa87b5
Adds timestamps to migration file. (leaves timestamps out of schema o…
RobStallion Mar 1, 2019
f43ca35
correct typo
RobStallion Mar 1, 2019
7124449
Creates a test to insert a comment into the database #45
RobStallion Mar 1, 2019
ff3f1d3
creates a clause to ensure migrations to not fail because of schema_m…
RobStallion Mar 1, 2019
65f898e
adds unique constraint to comment changeset #45
RobStallion Mar 1, 2019
0c11e6f
adds tests #45
RobStallion Mar 1, 2019
2b1bdf0
removes test causing error #45
RobStallion Mar 4, 2019
5c801b4
Merge pull request #52 from dwyl/insert-testing
RobStallion Mar 4, 2019
90927de
removes comments that are no longer needed #45
RobStallion Mar 4, 2019
c023e30
replace @conn with module name for clarity #45
RobStallion Mar 4, 2019
8c6d232
add "distinct on" in query, #40
SimonLab Mar 6, 2019
c934649
use regex instead of String.split to match query terms, https://githu…
SimonLab Mar 6, 2019
0eb4ce5
order by result by entry_id and inserted_at, #40
SimonLab Mar 6, 2019
2c4f4a2
create subquery for all function, #40
SimonLab Mar 6, 2019
a057334
Merge pull request #50 from dwyl/insert
nelsonic Mar 7, 2019
abf0f46
Update lib/alog/connection.ex
Mar 11, 2019
53c92d1
check deleted field is necessary on subquery, #40
SimonLab Mar 12, 2019
d9eb8b9
add test for all, #40
SimonLab Mar 12, 2019
9497ed2
merges update with adapter branch
Danwhy Mar 12, 2019
fd63ef5
Merge pull request #54 from dwyl/query-all
Danwhy Mar 12, 2019
db5378c
adds documentation
Danwhy Mar 12, 2019
052bd7e
Merge branch 'adapter' into update
Danwhy Mar 12, 2019
e0e08be
Merge pull request #51 from dwyl/update
RobStallion Mar 13, 2019
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
59 changes: 13 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,26 @@
# alog
alog (Append-only Log) is an easy way to start using the Lambda/Kappa architecture in your Elixir/Phoenix Apps while still using PostgreSQL (with Ecto).

This module provides some helper functions to make it easy to insert and retrieve the data you need.
This module is an Ecto Adapter that extends the default Postgres adapter with functionality to ensure data is only ever appended, never deleted or edited.

## Usage

At the top of the schema you wish to use append only functions for, `use` this module:
In your Repo module, when defining your Ecto Repo, set the adapter to be this module, Alog

``` elixir
use Alog
```

The append only functions will then be available to call as part of your schema.

## Example

``` elixir
defmodule MyApp.User do
use Ecto.Schema
use Alog

import Ecto.Changeset

schema "users" do
...
end

def changeset(user, attrs) do
...
end
``` elixir
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Alog
end
```

## Repo

You can set the repo you want Alog to use in a config file:

``` elixir
config :alog, Alog,
repo: MyApp.Repo
```

If you do not explicitly set a Repo, Alog will try to find it using your application name.
So if your app is `MyApp` and your schema is `MyApp.User`, or `MyApp.Accounts.User`, your Repo should be `MyApp.Repo`.

## Uniqueness
```

Due to the append only manner in which Alog stores data, it is not compatible with tables that have Unique Indexes applied to any of their columns. If you wish to use alog, you will have to remove these indexes.
## Considerations

For example, the following in a migration file would remove a unique index on the `email` column from the `users` table.
- When inserting or updating an item, the return value of the insert/update function is currently incorrect. The updates and inserts are however done correctly, as you will see if you get all items from the database using `Repo.all`.

```
drop(unique_index(:users, :email))
```
- We exclude the `schema_migrations` file from all alog functions, instead forwarding them on to the original Postgres Adapter.

See https://hexdocs.pm/ecto_sql/Ecto.Migration.html#content for more details.
- The autogenerated cid is used as the primary key. There is no way currently to define a custom primary key.

If you want to ensure each entry in your database has a unique field, you can use the [`Ecto.Changeset.unique_constraint/3`](https://hexdocs.pm/ecto/Ecto.Changeset.html#unique_constraint/3) function as normal, and Alog will ensure there are no repeated fields, other than those of the same entry, returning an invalid changeset if there are.
Hopefully these issues can later be resolved by looking at defining/extending our own version of the the `Ecto.Schema` macro.
1 change: 0 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use Mix.Config

config :alog, Alog.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "test_app_dev",
Expand Down
Loading