-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9c2091
commit 911faf4
Showing
7 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Go migration | ||
Now you can create your own migration, to do that you can run the following command: | ||
|
||
```sh | ||
amigo create create_users_table | ||
``` | ||
|
||
This command will create a new migration file `{DATE}_create_users_table.go` in the `migrations` folder. | ||
|
||
This migration is in go, you have two kinds of migration files: | ||
- classic: they are up and down migrations as they implement [DetailedMigration](https://github.com/alexisvisco/amigo/blob/main/pkg/schema/migrator.go#L40) interface | ||
- change: they are up migrations as they implement [ChangeMigration](https://github.com/alexisvisco/amigo/blob/main/pkg/schema/migrator.go#L48) interface | ||
|
||
(more information on the cli [here](../03-cli/03-create.md)) | ||
|
||
|
||
### Example of a `change` migration file: | ||
|
||
```go | ||
package migrations | ||
|
||
import ( | ||
"github.com/alexisvisco/amigo/pkg/schema/pg" | ||
) | ||
|
||
type Migration20240524090434CreateUserTable struct {} | ||
|
||
func (m Migration20240524090434CreateUserTable) Change(s *pg.Schema) { | ||
s.CreateTable("users", func(def *pg.PostgresTableDef) { | ||
def.Serial("id") | ||
def.String("name") | ||
def.String("email") | ||
def.Timestamps() | ||
def.Index([]string{"name"}) | ||
}) | ||
} | ||
``` | ||
|
||
### Example of a `classic` migration file: | ||
|
||
```go | ||
package migrations | ||
|
||
import ( | ||
"github.com/alexisvisco/amigo/pkg/schema/pg" | ||
) | ||
|
||
type Migration20240524090434CreateUserTable struct {} | ||
|
||
func (m Migration20240524090434CreateUserTable) Up(s *pg.Schema) { | ||
s.CreateTable("users", func(def *pg.PostgresTableDef) { | ||
def.Serial("id") | ||
def.String("name") | ||
def.String("email") | ||
def.Timestamps() | ||
def.Index([]string{"name"}) | ||
}) | ||
} | ||
|
||
func (m Migration20240524090434CreateUserTable) Down(s *pg.Schema) { | ||
s.DropTable("users") | ||
} | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SQL Migration | ||
|
||
If you have a custom SQL to execute like materialized view, procedures and you want autocompletion and IDE support from | ||
SQL, you can use the `--type sql` flag. | ||
|
||
```sh | ||
amigo create my_migration --type sql | ||
``` | ||
|
||
### Example of a `sql` migration file: | ||
|
||
```sql | ||
-- todo: write up migrations here | ||
-- migrate:down | ||
-- todo: write down migrations here | ||
``` | ||
|
||
It act as a classic migration, you can write your SQL in the `-- todo: write up migrations here` section. | ||
|
||
All code below the `-- migrate:down` comment will be used to rollback the migration. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters