Skip to content

Commit

Permalink
Merge pull request #10 from worksome/sql-views-docs
Browse files Browse the repository at this point in the history
Adjust documentation regarding SQL views usage
  • Loading branch information
jeremynikolic authored Jan 25, 2023
2 parents 8cb121f + d5c0c2b commit 3d95dd2
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Foggy - Database scrubbing
Foggy is a package which creates a database dump of your database, but with scrubbed data.
Foggy is a package which creates a database dump of your database, but with scrubbed data.
Perfect for taking a production database and use locally.

## Installation
Expand All @@ -18,8 +18,8 @@ For usage with Laravel, read more in [Laravel Foggy docs](https://github.com/wor


## Configuration
The configuration lies in a JSON file, which has to adhere to the `schema.json` file.
You can validate your configuration file on [jsonschemavalidator.net](https://www.jsonschemavalidator.net/) or directly in phpstorm.
The configuration lies in a JSON file, which has to adhere to the `schema.json` file.
You can validate your configuration file on [jsonschemavalidator.net](https://www.jsonschemavalidator.net/) or directly in phpstorm.

For the most basic configuration, where all tables are dumped, but no data is scrubbed, we simply do
```json
Expand All @@ -31,11 +31,11 @@ For the most basic configuration, where all tables are dumped, but no data is sc
}
}
```
Here we have specified that all tables (`*`) should be dumped with data by default.
Here we have specified that all tables and views (`*`) should be dumped with data by default.
A more secure default would be to set `withData` to `false`, so only schema definitions are exported, if nothing specific is specified.

### Defining rules for a table
All table definitions live inside `database` key in the json object.
All table definitions live inside `database` key in the json object.
Each table can have an array of rules. A rule consist of the following
- `column` - Which column to apply the rule to.
- `type` - Which rule type to use.
Expand Down Expand Up @@ -82,11 +82,11 @@ Each table can have an array of rules. Rules are applied to a specific column an
the values in that column per row.

#### Faker
The faker rule is to replace the value with a new fake value.
The faker rule is to replace the value with a new fake value.
It uses the [faker library](https://github.com/fzaninotto/Faker) underneath, so all formatters
available in faker can be used here.
available in faker can be used here.

For calling a simple faker property, simply specify `value` as the property you want to use.
For calling a simple faker property, simply specify `value` as the property you want to use.
In the following example we are calling the `email` faker.

```json
Expand All @@ -98,7 +98,7 @@ In the following example we are calling the `email` faker.
```

Sometimes you might want to use faker formatters which takes arguments. Arguments can be
supplied by using the `params` key in the json object.
supplied by using the `params` key in the json object.
In the following example we specify that we only want to generate `female` names.

```json
Expand All @@ -111,10 +111,10 @@ In the following example we specify that we only want to generate `female` names
```

#### Replacer
The replacer rule replaces a column with the given value.
The replacer rule replaces a column with the given value.
It's a simple rule for when you just want all entries to have the same value. A great use-case is for
setting all passwords to the same value, so when using the scrubbed database, you can log in on all user's
with the same password.
with the same password.
In the following example we replace all passwords with `secret`, but a hashed edition of it.

```json
Expand All @@ -127,7 +127,7 @@ In the following example we replace all passwords with `secret`, but a hashed ed

#### PHP
The PHP rule is a basic, but really powerful rule. It allows you to define a PHP string which will be applied
to the column.
to the column.
This string has a few variables which can be accessed.
- `value` - this variable will hold the current value of the column which the rule should be applied to.
- `row` - This variable will hold the current values of the whole row which the rule should be applied to.
Expand All @@ -147,4 +147,19 @@ not needed to write `return`, as the statement is wrapped in a `return` automati

#### Times
It is possible to limit a column to only be applied `x` amount of times, by supplying an argument named
`times`. This will limit, so the rule is only applied until the `times` are hit.
`times`. This will limit, so the rule is only applied until the `times` are hit.

### SQL Views
All views definitions live inside `database` key in the json object.
In opposition to tables, views do not have any particular rules applicable to them.

Only requirement is for them to be listed in the json object to be included in the import.
The wildcard configuration `*` will include them all.

```json
{
"database": {
"stock_quantity_view": {}
}
}
```

0 comments on commit 3d95dd2

Please sign in to comment.