Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeljesus committed Mar 7, 2018
1 parent 33e9929 commit c293c03
Showing 1 changed file with 59 additions and 35 deletions.
94 changes: 59 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,45 +50,12 @@ klepto steal \
MySQL:
```sh
klepto steal \
--from 'user:pass@tcp(localhost:3306)/fromDB?sslmode=disable' \
--to 'user:pass@tcp(localhost:3306)/toDB?sslmode=disable' \
--from="user:pass@tcp(localhost:3306)/fromDB?sslmode=disable" \
--to="user:pass@tcp(localhost:3306)/toDB?sslmode=disable" \
--concurrency=4 \
--read-max-conns=8
```

## Anonymisation

Each column can be set to anonymise. Anonymisation is performed by running a Faker against the specified column.

By specifying anonymisation config in your `.klepto.toml` file, you can define which tables' fields require anonymisation. This is done as follows:

```toml
[[Tables]]
Name = "customers"
[Tables.Anonymise]
email = "EmailAddress"
firstName = "FirstName"

[[Tables]]
Name = "users"
[Tables.Anonymise]
email = "EmailAddress"
password = "literal:1234"
```

This would replace these 4 columns from the `customer` and `users` tables and run `fake.EmailAddress` and `fake.FirstName` against them respectively. We can use `literal:[some-constant-value]` to specify a constant we want to write for a column. In this case, `password = "literal:1234"` would write `1234` for every row in the password column of the users table.

### Available data types for anonymisation

Available data types can be found in [fake.go](pkg/anonymiser/fake.go). This file is generated from https://github.com/icrowley/fake (it must be generated because it is written in such a way that Go cannot reflect upon it).

We generate the file with the following:

```sh
$ go get github.com/ungerik/pkgreflect
$ fake master pkgreflect -notypes -novars -norecurs vendor/github.com/icrowley/fake/
```

## Relationships

Dump the latest 100 users with their orders:
Expand All @@ -103,6 +70,7 @@ Dump the latest 100 users with their orders:
[[Tables]]
Name = "orders"
[[Tables.Relationships]]
# behind the scenes klepto will create a inner join between orders and users
ForeignKey = "user_id"
ReferencedTable = "users"
ReferencedKey = "id"
Expand All @@ -112,6 +80,28 @@ Dump the latest 100 users with their orders:
created_at = "desc"
```

## Matchers

You can declare a filter once and reuse it among tables:
```toml
[[Matchers]]
Latest100Users = "ORDER BY users.created_at DESC LIMIT 100"

[[Tables]]
Name = "users"
[Tables.Filter]
Match = "Latest100Users"

[[Tables]]
Name = "orders"
[[Tables.Relationships]]
ForeignKey = "user_id"
ReferencedTable = "users"
ReferencedKey = "id"
[Tables.Filter]
Match = "Latest100Users"
```

See [examples](./examples) for more.

## Ignore data
Expand All @@ -123,6 +113,40 @@ Additionally you can dump the database structure without importing data
IgnoreData = true
```

## Anonymisation

Each column can be set to anonymise. Anonymisation is performed by running a Faker against the specified column.

By specifying anonymisation config in your `.klepto.toml` file, you can define which tables' fields require anonymisation. This is done as follows:

```toml
[[Tables]]
Name = "customers"
[Tables.Anonymise]
email = "EmailAddress"
firstName = "FirstName"

[[Tables]]
Name = "users"
[Tables.Anonymise]
email = "EmailAddress"
password = "literal:1234"
```

This would replace these 4 columns from the `customer` and `users` tables and run `fake.EmailAddress` and `fake.FirstName` against them respectively. We can use `literal:[some-constant-value]` to specify a constant we want to write for a column. In this case, `password = "literal:1234"` would write `1234` for every row in the password column of the users table.

### Available data types for anonymisation

Available data types can be found in [fake.go](pkg/anonymiser/fake.go). This file is generated from https://github.com/icrowley/fake (it must be generated because it is written in such a way that Go cannot reflect upon it).

We generate the file with the following:

```sh
$ go get github.com/ungerik/pkgreflect
$ fake master pkgreflect -notypes -novars -norecurs vendor/github.com/icrowley/fake/
```


## Installing

Klepto is written in Go with support for multiple platforms. Pre-built binaries are provided for the following:
Expand Down

0 comments on commit c293c03

Please sign in to comment.