Skip to content

Commit

Permalink
Updated docs and version refs to the new release
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredbaudisch committed Oct 27, 2016
1 parent 2a7567d commit c99713f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Add `ecto_instashard` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[{:ecto_instashard, "~> 0.1.1"}]
[{:ecto_instashard, "~> 0.2.0"}]
end
```

Expand Down Expand Up @@ -112,10 +112,7 @@ defmodule ChatApp.Shards.Messages do
# the sharded table
table: "messages",
system_env: "MESSAGE_DATABASES",
scripts: [
:messages01_schema, :messages02_sequence,
:messages03_next_id, :messages04_table
],
scripts: [:messages],
worker_name: ChatApp.Repositories.Messages,
supervisor_name: ChatApp.Repositories.MessagesSupervisor
]
Expand Down Expand Up @@ -144,18 +141,15 @@ end
```

### <a name="scripts"></a>Database Scripts and Migrations
InstaShard can create your sharded tables and dynamic PostgreSQL schemas if you provide the related SQL scripts. Each script must contain one DDL command. Whenever you want to have the logical shard position defined, add `$1` to the DDL. Save the scripts in the folder `scripts` in your application and fill the list of SQL scripts as atoms in the Shard configuration, in the `scripts` key (as per previous example).
InstaShard can create your sharded tables and dynamic PostgreSQL schemas if you provide the related SQL scripts. Each DDL command must be separated by two blank lines. Whenever you want to have the logical shard position defined, add `$1` to the DDL. Save the scripts in the folder `scripts` in your application and fill the list of SQL scripts as atoms in the Shard configuration, in the `scripts` key (as per previous example).

Examples of scripts (these scripts are also inside `test/scripts`):

```sql
-- scripts/messages01_schema.sql
CREATE SCHEMA shard$1;

-- scripts/messages02_sequence.sql
CREATE SEQUENCE shard$1.message_seq;

-- scripts/messages03_next_id.sql
CREATE OR REPLACE FUNCTION shard$1.next_id(OUT result bigint) AS $$
DECLARE
our_epoch bigint := 1314220021721;
Expand All @@ -165,15 +159,13 @@ DECLARE
max_shard_id bigint := 2048;
BEGIN
SELECT nextval('shard$1.message_seq') % max_shard_id INTO seq_id;

SELECT FLOOR(EXTRACT(EPOCH FROM clock_timestamp()) * 1000) INTO now_millis;
result := (now_millis - our_epoch) << 23;
result := result | (shard_id << 10);
result := result | (seq_id);
END;
$$ LANGUAGE PLPGSQL;

-- scripts/messages04_table.sql
CREATE TABLE shard$1.messages (
id bigint not null default shard$1.next_id(),
user_id int not null,
Expand Down Expand Up @@ -262,7 +254,7 @@ Use the helper functions included in the shard module:
- [ ] Example project
- [ ] Helper functions documentation
- [ ] Helper functions in a separate macro
- [ ] Support DDL in a single file instead of multiple files
- [X] Support DDL in a single file instead of multiple files

## License

Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ defmodule Ecto.InstaShard.Mixfile do

def project do
[app: :ecto_instashard,
version: "0.1.1",
version: "0.2.0",
elixir: "~> 1.3",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
docs: [source_ref: "v0.1.1", main: "readme", extras: ["README.md"]],
docs: [source_ref: "v0.2.0", main: "readme", extras: ["README.md"]],
description: description(),
package: package(),
deps: deps()]
Expand Down

0 comments on commit c99713f

Please sign in to comment.