Skip to content

Commit 6b67c3f

Browse files
committed
cmd/gitbase: add readonly flag
Signed-off-by: Miguel Molina <[email protected]>
1 parent 99c828e commit 6b67c3f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cmd/gitbase/command/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/uber/jaeger-client-go/config"
1919
sqle "gopkg.in/src-d/go-mysql-server.v0"
2020
"gopkg.in/src-d/go-mysql-server.v0/server"
21+
"gopkg.in/src-d/go-mysql-server.v0/sql"
2122
"gopkg.in/src-d/go-mysql-server.v0/sql/analyzer"
2223
"gopkg.in/src-d/go-mysql-server.v0/sql/index/pilosa"
2324
"gopkg.in/src-d/go-vitess.v0/mysql"
@@ -45,7 +46,7 @@ type Server struct {
4546
IndexDir string `short:"i" long:"index" default:"/var/lib/gitbase/index" description:"Directory where the gitbase indexes information will be persisted." env:"GITBASE_INDEX_DIR"`
4647
DisableSquash bool `long:"no-squash" description:"Disables the table squashing."`
4748
TraceEnabled bool `long:"trace" env:"GITBASE_TRACE" description:"Enables jaeger tracing"`
48-
49+
ReadOnly bool `short:"r" long:"readonly" description:"Only allow read queries. This disables creating and deleting indexes as well." env:"GITBASE_READONLY"`
4950
// SkipGitErrors disables failing when Git errors are found.
5051
SkipGitErrors bool
5152

@@ -143,7 +144,13 @@ func (c *Server) Execute(args []string) error {
143144

144145
func (c *Server) buildDatabase() error {
145146
if c.engine == nil {
146-
c.engine = sqle.NewDefault()
147+
catalog := sql.NewCatalog()
148+
ab := analyzer.NewBuilder(catalog)
149+
if c.ReadOnly {
150+
ab = ab.ReadOnly()
151+
}
152+
a := ab.Build()
153+
c.engine = sqle.New(catalog, a)
147154
}
148155

149156
c.pool = gitbase.NewRepositoryPool()

0 commit comments

Comments
 (0)