Skip to content

Commit c1e8090

Browse files
committed
✨ feat: migrate from litecart cli
1 parent 0682c86 commit c1e8090

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

.vscode/launch.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
"request": "launch",
88
"mode": "auto",
99
"program": "${workspaceFolder}/cmd",
10-
"args": ["serve", "--dev"]
10+
//"args": ["serve", "--dev"]
1111
//"args": ["init"]
1212
//"args": ["update"]
13+
"args": ["migrate"]
1314
//"args": ["serve", "--no-site"]
1415
//"args": ["serve"]
1516
//"args": ["serve", "--help"]

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,10 @@ Usage:
125125

126126
Available commands:
127127
```
128-
init Init structure
128+
init Creating the basic structure
129+
migrate Migrate on the latest version of database schema
129130
serve Starts the web server (default to 0.0.0.0:8080)
130-
update Update app to the latest version
131+
update Updating the application to the latest version
131132
```
132133

133134
Global flags `./litecart [flags]`:
@@ -139,7 +140,7 @@ Global flags `./litecart [flags]`:
139140
Serve flags `./litecart serve [flags]`:
140141
```
141142
--http string server address (default "0.0.0.0:8080")
142-
--https string HTTPS server address (auto TLS)
143+
--https string https server address (auto TLS)
143144
--no-site disable create site
144145
```
145146

cmd/main.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func main() {
4040
rootCmd.AddCommand(cmdInit())
4141
rootCmd.AddCommand(cmdServe())
4242
rootCmd.AddCommand(cmdUpdate())
43+
rootCmd.AddCommand(cmdMigrate())
4344

4445
if err := rootCmd.Execute(); err != nil {
4546
os.Exit(1)
@@ -74,7 +75,7 @@ func cmdServe() *cobra.Command {
7475
&httpsAddr,
7576
"https",
7677
"",
77-
"HTTPS server address (auto TLS)",
78+
"https server address (auto TLS)",
7879
)
7980

8081
cmd.PersistentFlags().BoolVar(&noSite, "no-site", false, "disable create site")
@@ -88,7 +89,7 @@ func cmdServe() *cobra.Command {
8889
func cmdInit() *cobra.Command {
8990
cmd := &cobra.Command{
9091
Use: "init",
91-
Short: "Init structure",
92+
Short: "Creating the basic structure",
9293
Run: func(serveCmd *cobra.Command, args []string) {
9394
app.Init()
9495
},
@@ -100,7 +101,7 @@ func cmdInit() *cobra.Command {
100101
func cmdUpdate() *cobra.Command {
101102
cmd := &cobra.Command{
102103
Use: "update",
103-
Short: "Update app to the latest version",
104+
Short: "Updating the application to the latest version",
104105
Run: func(serveCmd *cobra.Command, args []string) {
105106
cfg := &update.Config{
106107
Owner: "shurco",
@@ -118,3 +119,18 @@ func cmdUpdate() *cobra.Command {
118119

119120
return cmd
120121
}
122+
123+
func cmdMigrate() *cobra.Command {
124+
cmd := &cobra.Command{
125+
Use: "migrate",
126+
Short: "Migrate on the latest version of database schema",
127+
Run: func(serveCmd *cobra.Command, args []string) {
128+
if err := app.Migrate(); err != nil {
129+
fmt.Print(err)
130+
os.Exit(1)
131+
}
132+
},
133+
}
134+
135+
return cmd
136+
}

internal/init.go

+9
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,12 @@ func Init() error {
3030

3131
return nil
3232
}
33+
34+
// Migrate is ...
35+
func Migrate() error {
36+
if err := queries.Migrate("./lc_base/data.db", migrations.Embed()); err != nil {
37+
return err
38+
}
39+
40+
return nil
41+
}

0 commit comments

Comments
 (0)