Merge remote-tracking branch 'upstream/master' into itn/tables-quotes-2
# Conflicts: # pkg/client/client.go
This commit is contained in:
commit
9bb3afe6ce
@ -14,10 +14,7 @@ go:
|
|||||||
- 1.7.6
|
- 1.7.6
|
||||||
- 1.8.7
|
- 1.8.7
|
||||||
- 1.9.3
|
- 1.9.3
|
||||||
- 1.10.0
|
- 1.10.1
|
||||||
|
|
||||||
env:
|
|
||||||
- GO15VENDOREXPERIMENT=1
|
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- ./script/check_formatting.sh
|
- ./script/check_formatting.sh
|
||||||
|
@ -1,3 +1,9 @@
|
|||||||
|
## 0.9.12 - 2018-04-23
|
||||||
|
|
||||||
|
- Add link to view database connection string format on login page
|
||||||
|
- Include constraint name under "constraints" tab, GH-343
|
||||||
|
- Misc CI and config changes
|
||||||
|
|
||||||
## 0.9.11 - 2017-12-07
|
## 0.9.11 - 2017-12-07
|
||||||
|
|
||||||
- Fix ssl mode for the connection url in the bookmarks, GH-320
|
- Fix ssl mode for the connection url in the bookmarks, GH-320
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
FROM alpine:3.6
|
FROM alpine:3.6
|
||||||
MAINTAINER Dan Sosedoff <dan.sosedoff@gmail.com>
|
LABEL maintainer="Dan Sosedoff <dan.sosedoff@gmail.com>"
|
||||||
|
ENV PGWEB_VERSION 0.9.12
|
||||||
ENV PGWEB_VERSION 0.9.11
|
|
||||||
|
|
||||||
RUN \
|
RUN \
|
||||||
apk update && \
|
apk add --no-cache ca-certificates openssl postgresql && \
|
||||||
apk add --update ca-certificates openssl && \
|
|
||||||
update-ca-certificates && \
|
update-ca-certificates && \
|
||||||
cd /tmp && \
|
cd /tmp && \
|
||||||
wget https://github.com/sosedoff/pgweb/releases/download/v$PGWEB_VERSION/pgweb_linux_amd64.zip && \
|
wget https://github.com/sosedoff/pgweb/releases/download/v$PGWEB_VERSION/pgweb_linux_amd64.zip && \
|
||||||
|
11
Makefile
11
Makefile
@ -25,10 +25,11 @@ usage:
|
|||||||
@echo ""
|
@echo ""
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -cover ./pkg/...
|
go test -race -cover ./pkg/...
|
||||||
|
|
||||||
test-all:
|
test-all:
|
||||||
@./script/test_all.sh
|
@./script/test_all.sh
|
||||||
|
@./script/test_cockroach.sh
|
||||||
|
|
||||||
assets: static/
|
assets: static/
|
||||||
go-bindata -o pkg/data/bindata.go -pkg data $(BINDATA_OPTS) $(BINDATA_IGNORE) -ignore=[.]gitignore -ignore=[.]gitkeep $<...
|
go-bindata -o pkg/data/bindata.go -pkg data $(BINDATA_OPTS) $(BINDATA_IGNORE) -ignore=[.]gitignore -ignore=[.]gitkeep $<...
|
||||||
@ -63,10 +64,10 @@ bootstrap:
|
|||||||
gox -build-toolchain
|
gox -build-toolchain
|
||||||
|
|
||||||
setup:
|
setup:
|
||||||
go get github.com/tools/godep
|
go get -u github.com/tools/godep
|
||||||
go get golang.org/x/tools/cmd/cover
|
go get -u golang.org/x/tools/cmd/cover
|
||||||
go get github.com/mitchellh/gox
|
go get -u github.com/mitchellh/gox
|
||||||
go get github.com/jteeuwen/go-bindata/...
|
go get -u github.com/jteeuwen/go-bindata/...
|
||||||
godep restore
|
godep restore
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
43
data/roach.sql
Normal file
43
data/roach.sql
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
DROP DATABASE IF EXISTS "roach";
|
||||||
|
CREATE DATABASE "roach";
|
||||||
|
USE "roach";
|
||||||
|
|
||||||
|
CREATE TABLE product_information (
|
||||||
|
product_id INT PRIMARY KEY NOT NULL,
|
||||||
|
product_name STRING(50) UNIQUE NOT NULL,
|
||||||
|
product_description STRING(2000),
|
||||||
|
category_id STRING(1) NOT NULL CHECK (category_id IN ('A','B','C')),
|
||||||
|
weight_class INT,
|
||||||
|
warranty_period INT CONSTRAINT valid_warranty CHECK (warranty_period BETWEEN 0 AND 24),
|
||||||
|
supplier_id INT,
|
||||||
|
product_status STRING(20),
|
||||||
|
list_price DECIMAL(8,2),
|
||||||
|
min_price DECIMAL(8,2),
|
||||||
|
catalog_url STRING(50) UNIQUE,
|
||||||
|
date_added DATE DEFAULT CURRENT_DATE(),
|
||||||
|
misc JSONB,
|
||||||
|
CONSTRAINT price_check CHECK (list_price >= min_price),
|
||||||
|
INDEX date_added_idx (date_added),
|
||||||
|
INDEX supp_id_prod_status_idx (supplier_id, product_status),
|
||||||
|
INVERTED INDEX details (misc)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO product_information VALUES
|
||||||
|
(1, 'Product A', 'Text', 'A', NULL, 1),
|
||||||
|
(2, 'Product B', 'Text', 'B', NULL, 2),
|
||||||
|
(3, 'Product C', 'Text', 'C', NULL, 3);
|
||||||
|
|
||||||
|
CREATE TABLE customers (
|
||||||
|
id INT PRIMARY KEY,
|
||||||
|
name STRING
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE orders (
|
||||||
|
id INT PRIMARY KEY,
|
||||||
|
customer_id INT REFERENCES customers(id) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO customers VALUES (1, 'Lauren');
|
||||||
|
INSERT INTO orders VALUES (1,1);
|
||||||
|
DELETE FROM customers WHERE id = 1;
|
||||||
|
SELECT * FROM orders;
|
@ -472,6 +472,13 @@ func DataExport(c *gin.Context) {
|
|||||||
Table: strings.TrimSpace(c.Request.FormValue("table")),
|
Table: strings.TrimSpace(c.Request.FormValue("table")),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If pg_dump is not available the following code will not show an error in browser.
|
||||||
|
// This is due to the headers being written first.
|
||||||
|
if !dump.CanExport() {
|
||||||
|
c.JSON(400, Error{"pg_dump is not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
formattedInfo := info.Format()[0]
|
formattedInfo := info.Format()[0]
|
||||||
filename := formattedInfo["current_database"].(string)
|
filename := formattedInfo["current_database"].(string)
|
||||||
if dump.Table != "" {
|
if dump.Table != "" {
|
||||||
|
@ -18,13 +18,13 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetupRoutes(router *gin.Engine) {
|
func SetupRoutes(router *gin.Engine) {
|
||||||
group := router.Group(command.Opts.Prefix)
|
root := router.Group(command.Opts.Prefix)
|
||||||
|
|
||||||
group.GET("/", GetHome)
|
root.GET("/", GetHome)
|
||||||
group.GET("/static/*path", GetAsset)
|
root.GET("/static/*path", GetAsset)
|
||||||
|
root.GET("/connect/:resource", ConnectWithBackend)
|
||||||
|
|
||||||
api := group.Group("/api")
|
api := root.Group("/api")
|
||||||
{
|
|
||||||
SetupMiddlewares(api)
|
SetupMiddlewares(api)
|
||||||
|
|
||||||
if command.Opts.Sessions {
|
if command.Opts.Sessions {
|
||||||
@ -52,7 +52,4 @@ func SetupRoutes(router *gin.Engine) {
|
|||||||
api.GET("/history", GetHistory)
|
api.GET("/history", GetHistory)
|
||||||
api.GET("/bookmarks", GetBookmarks)
|
api.GET("/bookmarks", GetBookmarks)
|
||||||
api.GET("/export", DataExport)
|
api.GET("/export", DataExport)
|
||||||
}
|
|
||||||
|
|
||||||
group.GET("/connect/:resource", ConnectWithBackend)
|
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,7 @@ func initClient() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !command.Opts.Sessions {
|
if !command.Opts.Sessions {
|
||||||
fmt.Printf("Server runs PostgreSQL v%s\n", cl.ServerVersion())
|
fmt.Printf("Conneced to %s\n", cl.ServerVersion())
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Checking database objects...")
|
fmt.Println("Checking database objects...")
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -17,10 +18,19 @@ import (
|
|||||||
"github.com/sosedoff/pgweb/pkg/statements"
|
"github.com/sosedoff/pgweb/pkg/statements"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
postgresSignature = regexp.MustCompile(`(?i)postgresql ([\d\.]+)\s`)
|
||||||
|
postgresType = "PostgreSQL"
|
||||||
|
|
||||||
|
cockroachSignature = regexp.MustCompile(`(?i)cockroachdb ccl v([\d\.]+)\s`)
|
||||||
|
cockroachType = "CockroachDB"
|
||||||
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
tunnel *Tunnel
|
tunnel *Tunnel
|
||||||
serverVersion string
|
serverVersion string
|
||||||
|
serverType string
|
||||||
lastQueryTime time.Time
|
lastQueryTime time.Time
|
||||||
External bool
|
External bool
|
||||||
History []history.Record `json:"history"`
|
History []history.Record `json:"history"`
|
||||||
@ -109,6 +119,11 @@ func NewFromUrl(url string, sshInfo *shared.SSHInfo) (*Client, error) {
|
|||||||
fmt.Println("Creating a new client for:", url)
|
fmt.Println("Creating a new client for:", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uri, err := neturl.Parse(url)
|
||||||
|
if err == nil && uri.Path == "" {
|
||||||
|
return nil, fmt.Errorf("Database name is not provided")
|
||||||
|
}
|
||||||
|
|
||||||
db, err := sqlx.Open("postgres", url)
|
db, err := sqlx.Open("postgres", url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -132,7 +147,22 @@ func (client *Client) setServerVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
version := res.Rows[0][0].(string)
|
version := res.Rows[0][0].(string)
|
||||||
client.serverVersion = strings.Split(version, " ")[1]
|
|
||||||
|
// Detect postgresql
|
||||||
|
matches := postgresSignature.FindAllStringSubmatch(version, 1)
|
||||||
|
if len(matches) > 0 {
|
||||||
|
client.serverType = postgresType
|
||||||
|
client.serverVersion = matches[0][1]
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect cockroachdb
|
||||||
|
matches = cockroachSignature.FindAllStringSubmatch(version, 1)
|
||||||
|
if len(matches) > 0 {
|
||||||
|
client.serverType = cockroachType
|
||||||
|
client.serverVersion = matches[0][1]
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Test() error {
|
func (client *Client) Test() error {
|
||||||
@ -191,18 +221,45 @@ func (client *Client) TableRows(table string, opts RowsOptions) (*Result, error)
|
|||||||
return client.query(sql)
|
return client.query(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (client *Client) EstimatedTableRowsCount(table string, opts RowsOptions) (*Result, error) {
|
||||||
|
schema, table := getSchemaAndTable(table)
|
||||||
|
sql := fmt.Sprintf(`SELECT reltuples FROM pg_class WHERE oid = '%s.%s'::regclass;`, schema, table)
|
||||||
|
|
||||||
|
result, err := client.query(sql)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
// float64 to int64 conversion
|
||||||
|
estimatedRowsCount := result.Rows[0][0].(float64)
|
||||||
|
result.Rows[0] = Row{int64(estimatedRowsCount)}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (client *Client) TableRowsCount(table string, opts RowsOptions) (*Result, error) {
|
func (client *Client) TableRowsCount(table string, opts RowsOptions) (*Result, error) {
|
||||||
schema, table := getSchemaAndTable(table)
|
schema, table := getSchemaAndTable(table)
|
||||||
sql := fmt.Sprintf(`SELECT COUNT(1) FROM "%s"."%s"`, schema, table)
|
sql := fmt.Sprintf(`SELECT COUNT(1) FROM "%s"."%s"`, schema, table)
|
||||||
|
|
||||||
if opts.Where != "" {
|
if opts.Where != "" {
|
||||||
sql += fmt.Sprintf(" WHERE %s", opts.Where)
|
sql += fmt.Sprintf(" WHERE %s", opts.Where)
|
||||||
|
} else if client.serverType == postgresType {
|
||||||
|
tableInfo, err := client.TableInfo(table)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
estimatedRowsCount := tableInfo.Rows[0][3].(float64)
|
||||||
|
if estimatedRowsCount > 100000 {
|
||||||
|
return client.EstimatedTableRowsCount(table, opts)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client.query(sql)
|
return client.query(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) TableInfo(table string) (*Result, error) {
|
func (client *Client) TableInfo(table string) (*Result, error) {
|
||||||
|
if client.serverType == cockroachType {
|
||||||
|
return client.query(statements.TableInfoCockroach)
|
||||||
|
}
|
||||||
schema, table := getSchemaAndTable(table)
|
schema, table := getSchemaAndTable(table)
|
||||||
return client.query(statements.TableInfo, fmt.Sprintf(`"%s"."%s"`, schema, table))
|
return client.query(statements.TableInfo, fmt.Sprintf(`"%s"."%s"`, schema, table))
|
||||||
}
|
}
|
||||||
@ -231,9 +288,11 @@ func (client *Client) TableConstraints(table string) (*Result, error) {
|
|||||||
|
|
||||||
// Returns all active queriers on the server
|
// Returns all active queriers on the server
|
||||||
func (client *Client) Activity() (*Result, error) {
|
func (client *Client) Activity() (*Result, error) {
|
||||||
chunks := strings.Split(client.serverVersion, ".")
|
if client.serverType == cockroachType {
|
||||||
version := strings.Join(chunks[0:2], ".")
|
return client.query("SHOW QUERIES")
|
||||||
|
}
|
||||||
|
|
||||||
|
version := getMajorMinorVersion(client.serverVersion)
|
||||||
query := statements.Activity[version]
|
query := statements.Activity[version]
|
||||||
if query == "" {
|
if query == "" {
|
||||||
query = statements.Activity["default"]
|
query = statements.Activity["default"]
|
||||||
@ -268,7 +327,7 @@ func (client *Client) SetReadOnlyMode() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) ServerVersion() string {
|
func (client *Client) ServerVersion() string {
|
||||||
return client.serverVersion
|
return fmt.Sprintf("%s %s", client.serverType, client.serverVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) query(query string, args ...interface{}) (*Result, error) {
|
func (client *Client) query(query string, args ...interface{}) (*Result, error) {
|
||||||
|
@ -278,6 +278,35 @@ func test_TableInfo(t *testing.T) {
|
|||||||
assert.Equal(t, 1, len(res.Rows))
|
assert.Equal(t, 1, len(res.Rows))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func test_EstimatedTableRowsCount(t *testing.T) {
|
||||||
|
var count int64 = 15
|
||||||
|
res, err := testClient.EstimatedTableRowsCount("books", RowsOptions{})
|
||||||
|
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
assert.Equal(t, []string{"reltuples"}, res.Columns)
|
||||||
|
assert.Equal(t, []Row{Row{count}}, res.Rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_TableRowsCount(t *testing.T) {
|
||||||
|
var count int64 = 15
|
||||||
|
res, err := testClient.TableRowsCount("books", RowsOptions{})
|
||||||
|
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
assert.Equal(t, []string{"count"}, res.Columns)
|
||||||
|
assert.Equal(t, []Row{Row{count}}, res.Rows)
|
||||||
|
}
|
||||||
|
|
||||||
|
func test_TableRowsCountWithLargeTable(t *testing.T) {
|
||||||
|
var count int64 = 100010
|
||||||
|
testClient.db.MustExec(`create table large_table as select s from generate_Series(1,100010) s;`)
|
||||||
|
testClient.db.MustExec(`VACUUM large_table;`)
|
||||||
|
res, err := testClient.TableRowsCount("large_table", RowsOptions{})
|
||||||
|
|
||||||
|
assert.Equal(t, nil, err)
|
||||||
|
assert.Equal(t, []string{"reltuples"}, res.Columns)
|
||||||
|
assert.Equal(t, []Row{Row{count}}, res.Rows)
|
||||||
|
}
|
||||||
|
|
||||||
func test_TableIndexes(t *testing.T) {
|
func test_TableIndexes(t *testing.T) {
|
||||||
res, err := testClient.TableIndexes("books")
|
res, err := testClient.TableIndexes("books")
|
||||||
|
|
||||||
@ -400,6 +429,9 @@ func TestAll(t *testing.T) {
|
|||||||
test_Table(t)
|
test_Table(t)
|
||||||
test_TableRows(t)
|
test_TableRows(t)
|
||||||
test_TableInfo(t)
|
test_TableInfo(t)
|
||||||
|
test_EstimatedTableRowsCount(t)
|
||||||
|
test_TableRowsCount(t)
|
||||||
|
test_TableRowsCountWithLargeTable(t)
|
||||||
test_TableIndexes(t)
|
test_TableIndexes(t)
|
||||||
test_TableConstraints(t)
|
test_TableConstraints(t)
|
||||||
test_Query(t)
|
test_Query(t)
|
||||||
|
@ -11,6 +11,11 @@ type Dump struct {
|
|||||||
Table string
|
Table string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Dump) CanExport() bool {
|
||||||
|
err := exec.Command("pg_dump", "--version").Run()
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
func (d *Dump) Export(url string, writer io.Writer) error {
|
func (d *Dump) Export(url string, writer io.Writer) error {
|
||||||
errOutput := bytes.NewBuffer(nil)
|
errOutput := bytes.NewBuffer(nil)
|
||||||
|
|
||||||
|
@ -24,8 +24,12 @@ func test_DumpExport(t *testing.T) {
|
|||||||
os.Remove(savePath)
|
os.Remove(savePath)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Test full db dump
|
|
||||||
dump := Dump{}
|
dump := Dump{}
|
||||||
|
|
||||||
|
// Test for pg_dump presence
|
||||||
|
assert.True(t, dump.CanExport())
|
||||||
|
|
||||||
|
// Test full db dump
|
||||||
err = dump.Export(url, saveFile)
|
err = dump.Export(url, saveFile)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
15
pkg/client/util.go
Normal file
15
pkg/client/util.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Get short version from the string
|
||||||
|
// Example: 10.2.3.1 -> 10.2
|
||||||
|
func getMajorMinorVersion(str string) string {
|
||||||
|
chunks := strings.Split(str, ".")
|
||||||
|
if len(chunks) == 0 {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return strings.Join(chunks[0:2], ".")
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package command
|
package command
|
||||||
|
|
||||||
const VERSION = "0.9.11"
|
const VERSION = "0.9.12"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
GitCommit string
|
GitCommit string
|
||||||
|
@ -361,7 +361,7 @@ func staticJsAppJs() (*asset, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
info := bindataFileInfo{name: "static/js/app.js", size: 34563, mode: os.FileMode(420), modTime: time.Unix(1517374041, 0)}
|
info := bindataFileInfo{name: "static/js/app.js", size: 34563, mode: os.FileMode(420), modTime: time.Unix(1520524190, 0)}
|
||||||
a := &asset{bytes: bytes, info: info}
|
a := &asset{bytes: bytes, info: info}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
|
@ -73,6 +73,13 @@ SELECT
|
|||||||
pg_size_pretty(pg_total_relation_size($1)) AS total_size,
|
pg_size_pretty(pg_total_relation_size($1)) AS total_size,
|
||||||
(SELECT reltuples FROM pg_class WHERE oid = $1::regclass) AS rows_count`
|
(SELECT reltuples FROM pg_class WHERE oid = $1::regclass) AS rows_count`
|
||||||
|
|
||||||
|
TableInfoCockroach = `
|
||||||
|
SELECT
|
||||||
|
'n/a' AS data_size,
|
||||||
|
'n/a' AS index_size,
|
||||||
|
'n/a' AS total_size,
|
||||||
|
'n/a' AS rows_count`
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
TableSchema = `
|
TableSchema = `
|
||||||
|
@ -31,3 +31,4 @@ do
|
|||||||
make test
|
make test
|
||||||
echo "-------------------------------- END TEST --------------------------------"
|
echo "-------------------------------- END TEST --------------------------------"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
58
script/test_cockroach.sh
Executable file
58
script/test_cockroach.sh
Executable file
@ -0,0 +1,58 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
function killproc() {
|
||||||
|
if [[ $(lsof -i tcp:8888) ]]; then
|
||||||
|
lsof -i tcp:8888 | grep pgweb | awk '{print $2}' | xargs kill
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Nuke the old container if exists.
|
||||||
|
docker rm -f cockroach || true
|
||||||
|
|
||||||
|
# Start cockroach on 26258 so we dont mess with local server.
|
||||||
|
docker run \
|
||||||
|
--name=cockroach \
|
||||||
|
-d \
|
||||||
|
-t \
|
||||||
|
-p 26258:26257 \
|
||||||
|
cockroachdb/cockroach \
|
||||||
|
start --insecure
|
||||||
|
|
||||||
|
sleep 3
|
||||||
|
|
||||||
|
# Load the demo database.
|
||||||
|
docker exec -i cockroach ./cockroach sql --insecure < ./data/roach.sql
|
||||||
|
|
||||||
|
# Find and destroy the existing pgweb process.
|
||||||
|
# Would be great if pgweb had --pid option.
|
||||||
|
killproc
|
||||||
|
|
||||||
|
# Start pgweb and connect to cockroach.
|
||||||
|
make build
|
||||||
|
|
||||||
|
./pgweb \
|
||||||
|
--url=postgres://root@localhost:26258/roach?sslmode=disable \
|
||||||
|
--listen=8888 \
|
||||||
|
--skip-open &
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
# Run smoke tests
|
||||||
|
base="-w \"\n\" -f http://localhost:8888/api"
|
||||||
|
table="product_information"
|
||||||
|
|
||||||
|
curl $base/info
|
||||||
|
curl $base/connection
|
||||||
|
curl $base/schemas
|
||||||
|
curl $base/objects
|
||||||
|
curl $base/query -F query='select * from product_information;'
|
||||||
|
curl $base/tables/$table
|
||||||
|
curl $base/tables/$table/rows
|
||||||
|
curl $base/tables/$table/info
|
||||||
|
curl $base/tables/$table/indexes
|
||||||
|
curl $base/tables/$table/constraints
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
killproc
|
Loading…
x
Reference in New Issue
Block a user