verify successful database interactions with test endpoint
This commit is contained in:
parent
c1930d6821
commit
51a34008f1
5 changed files with 38 additions and 13 deletions
|
@ -10,11 +10,11 @@ import (
|
|||
"github.com/vingarcia/ksql/adapters/kpgx"
|
||||
)
|
||||
|
||||
var ProductsTable = ksql.NewTable("products", "product_id")
|
||||
var ProductsTable = ksql.NewTable("products", "id")
|
||||
|
||||
var UserClaimsTable = ksql.NewTable("user_claims", "user_claim_id")
|
||||
var UserClaimsTable = ksql.NewTable("user_claims", "id")
|
||||
|
||||
var AutomatedClaimsTable = ksql.NewTable("automated_claims", "automated_claim_id")
|
||||
var AutomatedClaimsTable = ksql.NewTable("automated_claims", "id")
|
||||
|
||||
// initializeDatabase creates the database and calls createTables.
|
||||
func InitializeDatabase() *ksql.DB {
|
||||
|
@ -36,9 +36,10 @@ func InitializeDatabase() *ksql.DB {
|
|||
|
||||
// createTables adds the product, automated_claims, and user_claims tables to the initialized database.
|
||||
func createTables(ctx context.Context, db ksql.DB) {
|
||||
|
||||
_, err := db.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS products (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
system TEXT,
|
||||
barcode TEXT,
|
||||
created_at TIMESTAMPTZ
|
||||
|
@ -49,7 +50,7 @@ func createTables(ctx context.Context, db ksql.DB) {
|
|||
}
|
||||
_, err = db.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS user_claims (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
product_id INTEGER,
|
||||
evidence_type INTEGER,
|
||||
evidence JSONB,
|
||||
|
@ -61,14 +62,14 @@ func createTables(ctx context.Context, db ksql.DB) {
|
|||
CONSTRAINT fk_product_id FOREIGN KEY(product_id) REFERENCES products(id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_user_claims_product_id ON user_claims USING HASH (product_id);
|
||||
-- CREATE INDEX idx_user_claims_product_id ON user_claims USING HASH (product_id);
|
||||
`)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
_, err = db.Exec(ctx, `
|
||||
CREATE TABLE IF NOT EXISTS automated_claims (
|
||||
id INTEGER PRIMARY KEY,
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
product_id INTEGER,
|
||||
worker_type INTEGER,
|
||||
evidence JSONB,
|
||||
|
@ -79,7 +80,7 @@ func createTables(ctx context.Context, db ksql.DB) {
|
|||
CONSTRAINT fk_product_id FOREIGN KEY(product_id) REFERENCES products(id)
|
||||
);
|
||||
|
||||
CREATE INDEX idx_automated_claims_product_id ON automated_claims USING HASH (product_id);
|
||||
-- CREATE INDEX idx_automated_claims_product_id ON automated_claims USING HASH (product_id);
|
||||
`)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -5,10 +5,10 @@ import (
|
|||
)
|
||||
|
||||
type Product struct {
|
||||
id int `ksql:"id"`
|
||||
system string `ksql:"system"`
|
||||
barcode string `ksql:"barcode"`
|
||||
created_at time.Time `ksql:"created_at,timeNowUTC"`
|
||||
Id int `ksql:"id"`
|
||||
System string `ksql:"system"`
|
||||
Barcode string `ksql:"barcode"`
|
||||
Created_at time.Time `ksql:"created_at,timeNowUTC"`
|
||||
}
|
||||
|
||||
type WorkerType int
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue