Skip to content

Commit

Permalink
✨ feat: migrate from litecart cli
Browse files Browse the repository at this point in the history
  • Loading branch information
shurco committed Sep 29, 2023
1 parent 0682c86 commit c1e8090
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/cmd",
"args": ["serve", "--dev"]
//"args": ["serve", "--dev"]
//"args": ["init"]
//"args": ["update"]
"args": ["migrate"]
//"args": ["serve", "--no-site"]
//"args": ["serve"]
//"args": ["serve", "--help"]
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ Usage:

Available commands:
```
init Init structure
init Creating the basic structure
migrate Migrate on the latest version of database schema
serve Starts the web server (default to 0.0.0.0:8080)
update Update app to the latest version
update Updating the application to the latest version
```

Global flags `./litecart [flags]`:
Expand All @@ -139,7 +140,7 @@ Global flags `./litecart [flags]`:
Serve flags `./litecart serve [flags]`:
```
--http string server address (default "0.0.0.0:8080")
--https string HTTPS server address (auto TLS)
--https string https server address (auto TLS)
--no-site disable create site
```

Expand Down
22 changes: 19 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func main() {
rootCmd.AddCommand(cmdInit())
rootCmd.AddCommand(cmdServe())
rootCmd.AddCommand(cmdUpdate())
rootCmd.AddCommand(cmdMigrate())

if err := rootCmd.Execute(); err != nil {
os.Exit(1)
Expand Down Expand Up @@ -74,7 +75,7 @@ func cmdServe() *cobra.Command {
&httpsAddr,
"https",
"",
"HTTPS server address (auto TLS)",
"https server address (auto TLS)",
)

cmd.PersistentFlags().BoolVar(&noSite, "no-site", false, "disable create site")
Expand All @@ -88,7 +89,7 @@ func cmdServe() *cobra.Command {
func cmdInit() *cobra.Command {
cmd := &cobra.Command{
Use: "init",
Short: "Init structure",
Short: "Creating the basic structure",
Run: func(serveCmd *cobra.Command, args []string) {
app.Init()
},
Expand All @@ -100,7 +101,7 @@ func cmdInit() *cobra.Command {
func cmdUpdate() *cobra.Command {
cmd := &cobra.Command{
Use: "update",
Short: "Update app to the latest version",
Short: "Updating the application to the latest version",
Run: func(serveCmd *cobra.Command, args []string) {
cfg := &update.Config{
Owner: "shurco",
Expand All @@ -118,3 +119,18 @@ func cmdUpdate() *cobra.Command {

return cmd
}

func cmdMigrate() *cobra.Command {
cmd := &cobra.Command{
Use: "migrate",
Short: "Migrate on the latest version of database schema",
Run: func(serveCmd *cobra.Command, args []string) {
if err := app.Migrate(); err != nil {
fmt.Print(err)
os.Exit(1)
}
},
}

return cmd
}
9 changes: 9 additions & 0 deletions internal/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,12 @@ func Init() error {

return nil
}

// Migrate is ...
func Migrate() error {
if err := queries.Migrate("./lc_base/data.db", migrations.Embed()); err != nil {
return err
}

return nil
}

0 comments on commit c1e8090

Please sign in to comment.