-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add usage documentation and one example project of using goseeder
- Loading branch information
1 parent
4566f4c
commit dac5610
Showing
15 changed files
with
503 additions
and
3 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,8 @@ | ||
#LOCAL DB | ||
|
||
DB_DRIVER=mysql | ||
DB_HOST=127.0.0.1 | ||
DB_PORT=3306 | ||
DB_DATABASE=goseeder_simpleshop | ||
DB_USERNAME=root | ||
DB_PASSWORD=verySecretPassword |
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,3 @@ | ||
/.idea | ||
|
||
.env |
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,25 @@ | ||
# simpleshop example | ||
|
||
This is one project example of using github.com/kristijorgji/goseeder | ||
|
||
To have this example project up and running follow these steps: | ||
1. you need to only create the database, just by executing the content of | ||
`db/migrations/000001_init_schema.up.sql` against your database server | ||
2. Then you need to create one .env file by copying the example .env.dist, and inside update the db credentials | ||
|
||
|
||
Then in order to seed against run | ||
```bash | ||
go run main.go --gseed | ||
``` | ||
|
||
and you will run all seeds in this example project. | ||
|
||
If you do not want to seed, but run the original main logic of the project run without the gseed argument like: | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
|
||
For full documentation of usage check the main documentation of github.com/kristijorgji/goseeder |
19 changes: 19 additions & 0 deletions
19
examples/simpleshop/db/migrations/000001_init_schema.up.sql
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,19 @@ | ||
create schema if not exists goseeder_simpleshop collate utf8_general_ci; | ||
|
||
create table categories | ||
( | ||
id smallint unsigned auto_increment | ||
primary key, | ||
name json not null, | ||
created_at timestamp default CURRENT_TIMESTAMP not null, | ||
updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP | ||
); | ||
|
||
create table products | ||
( | ||
id char(36) not null | ||
primary key, | ||
name json not null, | ||
created_at timestamp default CURRENT_TIMESTAMP not null, | ||
updated_at timestamp default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP | ||
); |
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,21 @@ | ||
package seeds | ||
|
||
import ( | ||
"fmt" | ||
"github.com/kristijorgji/goseeder" | ||
"simpleshop/util" | ||
) | ||
|
||
func categoriesSeeder(s goseeder.Seeder) { | ||
goseeder.FromJson(s, "categories") | ||
} | ||
|
||
func testCategoriesSeeder(s goseeder.Seeder) { | ||
for i := 0; i < 100; i++ { | ||
stmt, _ := s.DB.Prepare(`INSERT INTO categories(id, name) VALUES (?,?)`) | ||
_, err := stmt.Exec(util.RandomInt(1, int64(^uint16(0))), []byte(fmt.Sprintf(`{"en": "%s"}`, util.RandomString(7)))) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
} |
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,8 @@ | ||
package seeds | ||
|
||
import "github.com/kristijorgji/goseeder" | ||
|
||
func init() { | ||
goseeder.Register(categoriesSeeder) | ||
goseeder.Register(productsSeeder) | ||
} |
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,10 @@ | ||
[ | ||
{ | ||
"id": "1", | ||
"name": "{\"en\": \"Push\"}" | ||
}, | ||
{ | ||
"id": "2", | ||
"name": "{\"en\": \"Pull\"}" | ||
} | ||
] |
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,10 @@ | ||
[ | ||
{ | ||
"id": "0055bd0b-8629-490d-8552-906d04dfca84", | ||
"name": "{\"en\": \"Super Smartphone\"}" | ||
}, | ||
{ | ||
"id": "0162e545-2678-4cde-a291-665dcf6251a4", | ||
"name": "{\"en\": \"Fitness Tracker Fitbit Charge 4, black\"}" | ||
} | ||
] |
Oops, something went wrong.