Skip to content

Commit 3f013f3

Browse files
committed
Add migrations to remove features table
1 parent ff30b2c commit 3f013f3

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

cli/migrations/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ go run cli/migrations/*.go uast-import internal.db source.db
2727
# prepares the current "internal.db". Remove "diff" col
2828
go run cli/migrations/*.go diff-rm-col internal.db
2929
```
30+
31+
- [Remove features table from a database](command-features-drop-table.go)
32+
```shell
33+
# drops the 'features' table from the current "internal.db"
34+
go run cli/migrations/*.go features-drop-table internal.db
35+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"log"
6+
7+
"github.com/src-d/code-annotation/server/dbutil"
8+
)
9+
10+
type featureDropCmd struct {
11+
commandDesc
12+
Args struct {
13+
InternalDBPath string `description:"filepath to the internal SQLite database"`
14+
} `positional-args:"yes" required:"yes"`
15+
}
16+
17+
var featureDropOpts = featureDropCmd{
18+
commandDesc: commandDesc{
19+
name: "features-drop-table",
20+
shortDesc: "Drop Features table",
21+
longDesc: "Removes the Features table from the sqlite://InternalDBPath database",
22+
},
23+
}
24+
25+
// queries
26+
const (
27+
dropFeaturesTableQuery = "DROP TABLE features"
28+
)
29+
30+
func (c *featureDropCmd) Execute(args []string) error {
31+
internalDb, err := dbutil.Open(fmt.Sprintf(sqliteDSN, c.Args.InternalDBPath), false)
32+
if err != nil {
33+
log.Fatal(err)
34+
}
35+
36+
defer internalDb.Close()
37+
38+
if err := dropFeaturesTable(internalDb); err != nil {
39+
log.Fatal(err)
40+
}
41+
42+
log.Println("Features table was deleted")
43+
return nil
44+
}
45+
46+
func dropFeaturesTable(db dbutil.DB) error {
47+
if _, err := db.Exec(dropFeaturesTableQuery); err != nil {
48+
return err
49+
}
50+
51+
return nil
52+
}

cli/migrations/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func main() {
1818
addCommand(parser, &uastColsOpts)
1919
addCommand(parser, &uastImportOpts)
2020
addCommand(parser, &diffRmColOpts)
21+
addCommand(parser, &featureDropOpts)
2122
addCommand(parser, &vacuumOpts)
2223
parse(parser, description)
2324
}

0 commit comments

Comments
 (0)