Skip to content

Commit

Permalink
Misc doc changes
Browse files Browse the repository at this point in the history
List of changes:

- Set readme as default html doc page
- Use common source url
- Always get latest greatest ex_doc version
- Badges and more badges!
- Fix indentation
  • Loading branch information
kianmeng committed Nov 15, 2020
1 parent 5fc4036 commit 871d444
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 65 deletions.
113 changes: 57 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# EctoVista - PostgreSQL views for Ecto

![Elixir CI](https://github.com/flowerett/ecto_vista/workflows/Elixir%20CI/badge.svg)
[![Elixir CI](https://github.com/flowerett/ecto_vista/workflows/Elixir%20CI/badge.svg)](https://github.com/flowerett/ecto_vista/actions)
[![Module Version](https://img.shields.io/hexpm/v/ecto_vista.svg)](https://hex.pm/packages/ecto_vista)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ecto_vista/)
[![Total Download](https://img.shields.io/hexpm/dt/ecto_vista.svg)](https://hex.pm/packages/ecto_vista)
[![License](https://img.shields.io/hexpm/l/ecto_vista.svg)](https://github.com/yyy/ecto_vista/blob/master/LICENSE)
[![Last Updated](https://img.shields.io/github/last-commit/flowerett/ecto_vista.svg)](https://github.com/flowerett/ecto_vista/commits/master)

![Landscape](https://pp.userapi.com/c1111/u5935491/11475271/x_d17f8ffd.jpg)

Expand All @@ -10,8 +15,7 @@ Inspired by [scenic](https://github.com/scenic-views/scenic) library for ActiveR

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `ecto_vista` to your list of dependencies in `mix.exs`:
Add `ecto_vista` to your list of dependencies in `mix.exs`:

```elixir
def deps do
Expand All @@ -25,63 +29,65 @@ end

1. Add `ecto_vista` to your list of dependencies in `mix.exs` and run:

```
mix deps.get
```
```
mix deps.get
```

2. Generate your migration for the view, put the view definition like the one below
inside `change` or `up` method:

```
execute("""
CREATE MATERIALIZED VIEW catalog_v1 AS
SELECT c.*, count(p.id) AS product_count
FROM categories c
LEFT JOIN products p ON c.id = p.category_id
GROUP BY c.id
;
""")
```
```
execute("""
CREATE MATERIALIZED VIEW catalog_v1 AS
SELECT c.*, count(p.id) AS product_count
FROM categories c
LEFT JOIN products p ON c.id = p.category_id
GROUP BY c.id
;
""")
```

3. Use `EctoVista` module in your Ecto schema:

```
def App.Catalog do
use Ecto.Schema
use EctoVista,
repo: App.Repo
table_name: "catalog"
schema @table_name do
field(:name, :string)
field(:product_count, :integer)
end
end
```

The `@table_name` will be defined in macro as `{table_name}_v{version}` (version is 1 by default)
This naming convention facilitates 0-downtime view updates and will be handled automagically in future versions.

If you need to update the view, generate a new migration and then just update the version number in the schema definition:

```
def App.Catalog do
use Ecto.Schema
use EctoVista,
repo: App.Repo
table_name: "catalog"
version: 2
...
end
```
```
def App.Catalog do
use Ecto.Schema
use EctoVista,
repo: App.Repo
table_name: "catalog"
schema @table_name do
field(:name, :string)
field(:product_count, :integer)
end
end
```

The `@table_name` will be defined in macro as `{table_name}_v{version}`
(version is 1 by default). This naming convention facilitates 0-downtime view
updates and will be handled automagically in future versions.

If you need to update the view, generate a new migration and then just
update the version number in the schema definition:

```
def App.Catalog do
use Ecto.Schema
use EctoVista,
repo: App.Repo
table_name: "catalog"
version: 2
...
end
```

4. Don't forget to refresh your materialized view to see data:

```
iex> Catalog.refresh
:ok
```
```
iex> Catalog.refresh
:ok
```

## Roadmap

Expand All @@ -95,12 +101,7 @@ iex> Catalog.refresh
- [ ] Support all options to refresh and create views
- [ ] Implement automatic view versioning for migration

## Docs

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/ecto_vista](https://hexdocs.pm/ecto_vista).

## License

The source code is under the Apache 2 License.
Copyright (c) 2019- Nick Chernyshev.
16 changes: 7 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule EctoVista.MixProject do
use Mix.Project

@source_url "https://github.com/flowerett/ecto_vista"
@version "0.2.0"

def project do
Expand All @@ -22,13 +23,11 @@ defmodule EctoVista.MixProject do

# Docs
name: "EctoVista",
source_url: "https://github.com/flowerett/ecto_vista",
homepage_url: "https://github.com/flowerett/ecto_vista",
homepage_url: @source_url,
docs: docs()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
Expand All @@ -47,7 +46,6 @@ defmodule EctoVista.MixProject do
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ecto, "~> 3.5"},
Expand All @@ -59,7 +57,7 @@ defmodule EctoVista.MixProject do
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},

# Docs dependencies
{:ex_doc, "~> 0.23", only: :dev, runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:inch_ex, "~> 2.0", only: :dev, runtime: false}
]
end
Expand All @@ -68,16 +66,16 @@ defmodule EctoVista.MixProject do
[
maintainers: ["Nick Chernyshev"],
licenses: ["Apache 2.0"],
links: %{"GitHub" => "https://github.com/flowerett/ecto_vista"},
links: %{"GitHub" => @source_url},
files: ~w(.formatter.exs mix.exs README.md lib)
]
end

defp docs do
[
main: "EctoVista",
extras: ["README.md"],
source_url: "https://github.com/flowerett/ecto_vista"
main: "readme",
source_url: @source_url,
extras: ["README.md"]
]
end
end

0 comments on commit 871d444

Please sign in to comment.