mirror of
https://github.com/ilyakooo0/reshape.git
synced 2024-11-25 23:13:29 +03:00
Improve README
This commit is contained in:
parent
1a28a4ffdf
commit
101a414e00
38
README.md
38
README.md
@ -94,6 +94,8 @@ reshape migrate
|
|||||||
|
|
||||||
As this is the first migration, Reshape will automatically complete it. For subsequent migrations, you will need to first run `reshape migrate`, roll out your application and then complete the migration using `reshape complete`.
|
As this is the first migration, Reshape will automatically complete it. For subsequent migrations, you will need to first run `reshape migrate`, roll out your application and then complete the migration using `reshape complete`.
|
||||||
|
|
||||||
|
If nothing else is specified, Reshape will try to connect to a Postgres database running on `localhost` using `postgres` as both username and password. See [Connection options](#connection-options) for details on how to change the connection settings.
|
||||||
|
|
||||||
## Writing migrations
|
## Writing migrations
|
||||||
|
|
||||||
### Basics
|
### Basics
|
||||||
@ -180,37 +182,6 @@ primary_key = "id"
|
|||||||
referenced_columns = ["id"]
|
referenced_columns = ["id"]
|
||||||
```
|
```
|
||||||
|
|
||||||
*Example: create `users` and `items` tables with a foreign key between them*
|
|
||||||
|
|
||||||
```toml
|
|
||||||
[[actions]]
|
|
||||||
type = "create_table"
|
|
||||||
table = "users"
|
|
||||||
primary_key = "id"
|
|
||||||
|
|
||||||
[[actions.columns]]
|
|
||||||
name = "id"
|
|
||||||
type = "SERIAL"
|
|
||||||
|
|
||||||
[[actions]]
|
|
||||||
type = "create_table"
|
|
||||||
table = "items"
|
|
||||||
primary_key = "id"
|
|
||||||
|
|
||||||
[[actions.columns]]
|
|
||||||
name = "id"
|
|
||||||
type = "SERIAL"
|
|
||||||
|
|
||||||
[[actions.columns]]
|
|
||||||
name = "user_id"
|
|
||||||
type = "INTEGER"
|
|
||||||
|
|
||||||
[[actions.foreign_keys]]
|
|
||||||
columns = ["user_id"]
|
|
||||||
referenced_table = "users"
|
|
||||||
referenced_columns = ["id"]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Rename table
|
#### Rename table
|
||||||
|
|
||||||
The `rename_table` action will change the name of an existing table.
|
The `rename_table` action will change the name of an existing table.
|
||||||
@ -297,7 +268,7 @@ down = "first_name || ' ' || last_name"
|
|||||||
|
|
||||||
The `alter_column` action enables many different changes to an existing column, for example renaming, changing type and changing existing values.
|
The `alter_column` action enables many different changes to an existing column, for example renaming, changing type and changing existing values.
|
||||||
|
|
||||||
When performing more complex changes than a rename, `up` and `down` must be provided. These should be set to SQL expressions which determine how to transform between the new and old version of the column. Inside those expressions, you can reference the current column value by the column name.
|
When performing more complex changes than a rename, `up` and `down` must be provided. These should be SQL expressions which determine how to transform between the new and old version of the column. Inside those expressions, you can reference the current column value by the column name.
|
||||||
|
|
||||||
*Example: rename `last_name` column on `users` table to `family_name`*
|
*Example: rename `last_name` column on `users` table to `family_name`*
|
||||||
|
|
||||||
@ -326,7 +297,7 @@ down = "CAST(reference AS INTEGER)" # Converts from text value to integer
|
|||||||
type = "TEXT" # Previous type was 'INTEGER'
|
type = "TEXT" # Previous type was 'INTEGER'
|
||||||
```
|
```
|
||||||
|
|
||||||
*Example: increment all values of a `index` column by one*
|
*Example: increment all values of an `index` column by one*
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[[actions]]
|
[[actions]]
|
||||||
@ -338,7 +309,6 @@ down = "index - 1" # Decrement to revert for old schema
|
|||||||
|
|
||||||
[actions.changes]
|
[actions.changes]
|
||||||
name = "index"
|
name = "index"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Remove column
|
#### Remove column
|
||||||
|
Loading…
Reference in New Issue
Block a user