1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use ;
/// The `deleted_at` column for a migration: nullable `timestamp with time zone`.
///
/// ```
/// use sea_orm::sea_query::{PostgresQueryBuilder, Table};
/// use sea_orm_soft_delete::deleted_at_column;
///
/// // In a SeaORM migration, pass this to `manager.alter_table(...)`.
/// let statement = Table::alter()
/// .table("posts")
/// .add_column(deleted_at_column("deleted_at"))
/// .to_owned();
///
/// assert_eq!(
/// statement.to_string(PostgresQueryBuilder),
/// r#"ALTER TABLE "posts" ADD COLUMN "deleted_at" timestamp with time zone NULL"#
/// );
/// ```
/// A unique index that only covers rows outside the trash:
/// `CREATE UNIQUE INDEX ... WHERE deleted_at IS NULL`.
///
/// A trashed `hello` then no longer blocks a new `hello`. This is cleaner than the
/// usual `UNIQUE (slug, deleted_at)`, which lets two live rows share a slug in
/// databases where `NULL` values never conflict. Works in Postgres and SQLite;
/// MySQL has no partial indexes.
///
/// ```
/// use sea_orm::sea_query::PostgresQueryBuilder;
/// use sea_orm_soft_delete::unique_while_kept;
///
/// // In a SeaORM migration, pass this to `manager.create_index(...)`.
/// let index = unique_while_kept("posts_slug_kept", "posts", ["slug"], "deleted_at");
///
/// assert_eq!(
/// index.to_string(PostgresQueryBuilder),
/// r#"CREATE UNIQUE INDEX "posts_slug_kept" ON "posts" ("slug") WHERE "deleted_at" IS NULL"#
/// );
/// ```