Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc doc changes #134

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
19 changes: 13 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover
/cover/

# The directory Mix downloads your dependencies sources to.
/deps
/deps/

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc
# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

/.elixir_ls
# Ignore package tarball (built via "mix hex.build").
ecto-soft-delete-*.tar

# Temporary files, for example, from tests.
/tmp/
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [2.0.1] - 2020-05-08

- Add logic to `Ecto.SoftDelete.Repo.prepare_query` to respect `where` clauses that explicitly include records where deleted_at is not nil
- Add logic to `Ecto.SoftDelete.Repo.prepare_query` to respect `where` clauses
that explicitly include records where deleted_at is not nil

## [2.0.0] - 2020-05-06

Expand All @@ -22,16 +23,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- `Ecto.SoftDelete.Repo` for adding soft delete functions to repositories.
- `Ecto.SoftDelete.Repo` for adding soft delete functions to repositories

## [1.0.0] - 2019-02-15

### Added

- Ecto 3 support

## [0.2.0]
## [0.2.0] - 2018-12-31

### Fixed

- Missing license (MIT)

## [0.1.0] - 2017-12-20

- Initial release
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Setup for Development
# Contributing

```
## Setup for Development

```bash
git clone https://github.com/revelrylabs/ecto_soft_delete
mix deps.get
```

# Submitting Changes
## Submitting Changes

1. Fork the repository.
2. Set up the package per the instructions above and ensure `mix test`
Expand Down
15 changes: 0 additions & 15 deletions LICENSE

This file was deleted.

19 changes: 19 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright 2018 Revelry Labs LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
57 changes: 42 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
# EctoSoftDelete

[![Build Status](https://travis-ci.org/revelrylabs/ecto_soft_delete.svg?branch=master)](https://travis-ci.org/revelrylabs/ecto_soft_delete)
[![Hex.pm](https://img.shields.io/hexpm/dt/ecto_soft_delete.svg)](https://hex.pm/packages/ecto_soft_delete)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Coverage Status](https://opencov.prod.revelry.net/projects/21/badge.svg)](https://opencov.prod.revelry.net/projects/21)

# EctoSoftDelete
[![Module Version](https://img.shields.io/hexpm/v/ecto_soft_delete.svg)](https://hex.pm/packages/ecto_soft_delete)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/ecto_soft_delete/)
[![Total Download](https://img.shields.io/hexpm/dt/ecto_soft_delete.svg)](https://hex.pm/packages/ecto_soft_delete)
[![License](https://img.shields.io/hexpm/l/ecto_soft_delete.svg)](https://github.com/revelrylabs/ecto_soft_delete/blob/master/LICENSE)
[![Last Updated](https://img.shields.io/github/last-commit/revelrylabs/ecto_soft_delete.svg)](https://github.com/revelrylabs/ecto_soft_delete/commits/master)

Adds columns, fields, and queries for soft deletion with Ecto.

[Documentation](https://hexdocs.pm/ecto_soft_delete)
## Installation

The package can be installed by adding `:ecto_soft_delete` to your list of
dependencies in `mix.exs`:

Add to mix.exs:

```elixir
defp deps do
[
{:ecto_soft_delete, "~> 1.0"}
]
end
```

and do:

```
mix deps.get
```

## Usage

### Migrations

In migrations for schemas to support soft deletion, import `Ecto.SoftDelete.Migration`. Next, add `soft_delete_columns()` when creating a table
In migrations for schemas to support soft deletion, import
`Ecto.SoftDelete.Migration`. Next, add `soft_delete_columns()` when creating a
table:

```elixir
defmodule MyApp.Repo.Migrations.CreateUser do
Expand All @@ -33,23 +57,26 @@ end

### Schemas

Import `Ecto.SoftDelete.Schema` into your Schema module, then add `soft_delete_schema()` to your schema
Import `Ecto.SoftDelete.Schema` into your Schema module, then add
`soft_delete_schema()` to your schema:

```elixir
defmodule User do
use Ecto.Schema
import Ecto.SoftDelete.Schema
defmodule User do
use Ecto.Schema
import Ecto.SoftDelete.Schema

schema "users" do
field :email, :string
soft_delete_schema()
end
schema "users" do
field :email, :string
soft_delete_schema()
end
end
```

### Queries

To query for items that have not been deleted, use `with_undeleted(query)` which will filter out deleted items using the `deleted_at` column produced by the previous 2 steps
To query for items that have not been deleted, use `with_undeleted(query)`
which will filter out deleted items using the `deleted_at` column produced by
the previous 2 steps:

```elixir
import Ecto.SoftDelete.Query
Expand Down
6 changes: 4 additions & 2 deletions lib/ecto/soft_delete_migration.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
defmodule Ecto.SoftDelete.Migration do
@moduledoc """
Contains functions to add soft delete columns to a table during migrations
Contains functions to add soft delete columns to a table during migrations.
"""

use Ecto.Migration

@doc """
Adds deleted_at column to a table. This column is used to track if an item is deleted or not and when
Adds deleted_at column to a table.

This column is used to track if an item is deleted or not and when:

defmodule MyApp.Repo.Migrations.CreateUser do
use Ecto.Migration
Expand Down
4 changes: 2 additions & 2 deletions lib/ecto/soft_delete_query.ex
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
defmodule Ecto.SoftDelete.Query do
@moduledoc """
functions for querying data that is (or is not) soft deleted
Functions for querying data that is (or is not) soft deleted.
"""

import Ecto.Query

@doc """
Returns a query that searches only for undeleted items
Returns a query that searches only for undeleted items.

query = from(u in User, select: u)
|> with_undeleted
Expand Down
2 changes: 2 additions & 0 deletions lib/ecto/soft_delete_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ defmodule Ecto.SoftDelete.Repo do

@doc """
Soft deletes a struct.

Updates the `deleted_at` field with the current datetime in UTC.

It returns `{:ok, struct}` if the struct has been successfully
soft deleted or `{:error, changeset}` if there was a validation
or a known constraint error.
Expand Down
4 changes: 2 additions & 2 deletions lib/ecto/soft_delete_schema.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
defmodule Ecto.SoftDelete.Schema do
@moduledoc """
Contains schema macros to add soft delete fields to a schema
Contains schema macros to add soft delete fields to a schema.
"""

@doc """
Adds the deleted_at column to a schema
Adds the `deleted_at` column to a schema.

defmodule User do
use Ecto.Schema
Expand Down
32 changes: 23 additions & 9 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
defmodule EctoSoftDelete.Mixfile do
use Mix.Project

@source_url "https://github.com/revelrylabs/ecto_soft_delete"
@version "2.0.4"

def project do
[
app: :ecto_soft_delete,
version: "2.0.4",
version: @version,
elixir: "~> 1.11",
elixirc_paths: elixirc_paths(Mix.env()),
build_embedded: Mix.env() == :prod,
Expand All @@ -17,8 +20,8 @@ defmodule EctoSoftDelete.Mixfile do
"coveralls.html": :test
],
deps: deps(),
docs: docs(),
package: package(),
description: description()
]
end

Expand All @@ -33,20 +36,15 @@ defmodule EctoSoftDelete.Mixfile do
[
{:ecto_sql, "~> 3.5"},
{:postgrex, ">= 0.0.0", only: [:test]},
{:ex_doc, "~> 0.16", only: [:dev, :test]},
{:ex_doc, ">= 0.0.0", only: [:dev, :test]},
{:credo, "~> 1.0", only: [:dev, :test]},
{:excoveralls, "~> 0.8", only: [:dev, :test]}
]
end

defp description do
"""
Soft deletion with Ecto.
"""
end

defp package do
[
description: "Soft deletion with Ecto.",
files: ["lib", "mix.exs", "README.md", "LICENSE", "CHANGELOG.md"],
maintainers: ["Bryan Joseph", "Luke Ledet"],
licenses: ["MIT"],
Expand All @@ -56,4 +54,20 @@ defmodule EctoSoftDelete.Mixfile do
build_tools: ["mix"]
]
end

defp docs do
[
extras: [
"CHANGELOG.md": [title: "Changelog"],
"CONTRIBUTING.md": [title: "Contributing"],
"CODE_OF_CONDUCT.md": [title: "Code of Conduct"],
"LICENSE.md": [title: "License"],
"README.md": [title: "Overview"]
],
main: "readme",
source_url: @source_url,
source_ref: "v#{@version}",
formatters: ["html"]
]
end
end