Skip to content

Commit 87294ba

Browse files
authored
DB Query Engine (#2265)
* changes * read and write working * add lightstream example * query wip * EOD wip * add db types, modular bucket, auth * remove duplicates * remove noop store * remove unit ls-fast test command * remove units fast from the client * remove WAL setup * remove unnecessary * adjust auth * wip - mssql fix * enable NULL for lock time * some changes to documentation * Test Suite for query engine, adjustments to stores Discovered a flaw in sqlstore's handling of wildcard perms during testing, adjusted Adjustd the s3 store to enable testing with this definition instead of separate mock Added tests for different aspects of the query engine, especially rbac and unit management. * fix docker warnings and build fail * add missing syncs for rbac * adjust docs, silence SQL logs, check for existence before sync * adjust docs - PATH to DB_PATH, add prefix * refactor with repository in mind * make test guide more minimal * make sure tfe can't create units
1 parent 26f70cb commit 87294ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+7149
-1336
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ __azurite*
1717
*.out
1818
go.work.sum
1919

20+
2021
# Build directories
2122
dist/
2223
build/
@@ -30,5 +31,9 @@ bin/
3031
*.swo
3132
*~
3233

33-
# data
34-
taco/data/
34+
35+
#data
36+
data/
37+
38+
39+
taco/data/
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
---
2+
title: "Query Backend"
3+
---
4+
5+
OpenTaco supports using a query backend to speed up the retrieval of objects from S3. By default SQLite will initialize, but other SQL databases can be configured if desired. If the backend is not SQLite you need to setup the database first before attempting to run statesman and populate the correct environment variables.
6+
7+
## Configuration
8+
9+
Set the backend type using:
10+
11+
```bash
12+
TACO_QUERY_BACKEND=sqlite # Options: sqlite, postgres, mssql, mysql
13+
```
14+
15+
## SQLite (Default)
16+
17+
SQLite is the default query backend and requires no external database server and no configuration. We expose settings for convenience but you should not need to configure SQLite in most circumstances.
18+
19+
### Environment Variables
20+
21+
```bash
22+
# Backend selection
23+
TACO_QUERY_BACKEND=sqlite
24+
25+
# SQLite-specific configuration
26+
TACO_SQLITE_DB_PATH=./data/taco.db
27+
TACO_SQLITE_CACHE=shared
28+
TACO_SQLITE_BUSY_TIMEOUT=5s
29+
TACO_SQLITE_MAX_OPEN_CONNS=1
30+
TACO_SQLITE_MAX_IDLE_CONNS=1
31+
TACO_SQLITE_PRAGMA_JOURNAL_MODE=WAL
32+
TACO_SQLITE_PRAGMA_FOREIGN_KEYS=ON
33+
TACO_SQLITE_PRAGMA_BUSY_TIMEOUT=5000
34+
```
35+
36+
### Defaults
37+
- **Path**: `./data/taco.db`
38+
- **Cache**: `shared`
39+
- **Busy Timeout**: `5s`
40+
- **Max Open Connections**: `1`
41+
- **Max Idle Connections**: `1`
42+
- **Journal Mode**: `WAL`
43+
- **Foreign Keys**: `ON`
44+
45+
## PostgreSQL
46+
47+
Use PostgreSQL for better concurrency and performance in production environments.
48+
49+
### Environment Variables
50+
51+
```bash
52+
# Backend selection
53+
TACO_QUERY_BACKEND=postgres
54+
55+
# PostgreSQL-specific configuration
56+
TACO_POSTGRES_HOST=localhost
57+
TACO_POSTGRES_PORT=5432
58+
TACO_POSTGRES_USER=postgres
59+
TACO_POSTGRES_PASSWORD=your_password
60+
TACO_POSTGRES_DBNAME=taco
61+
TACO_POSTGRES_SSLMODE=disable
62+
```
63+
64+
### Defaults
65+
- **Host**: `localhost`
66+
- **Port**: `5432`
67+
- **User**: `postgres`
68+
- **Database Name**: `taco`
69+
- **SSL Mode**: `disable`
70+
71+
### Example Connection
72+
73+
```bash
74+
export TACO_QUERY_BACKEND=postgres
75+
export TACO_POSTGRES_HOST=my-postgres-server.example.com
76+
export TACO_POSTGRES_PORT=5432
77+
export TACO_POSTGRES_USER=taco_user
78+
export TACO_POSTGRES_PASSWORD=secure_password
79+
export TACO_POSTGRES_DBNAME=taco_prod
80+
export TACO_POSTGRES_SSLMODE=require
81+
```
82+
83+
## Microsoft SQL Server (MSSQL)
84+
85+
Use MSSQL for enterprise environments with existing SQL Server infrastructure.
86+
87+
### Environment Variables
88+
89+
```bash
90+
# Backend selection
91+
TACO_QUERY_BACKEND=mssql
92+
93+
# MSSQL-specific configuration
94+
TACO_MSSQL_HOST=localhost
95+
TACO_MSSQL_PORT=1433
96+
TACO_MSSQL_USER=sa
97+
TACO_MSSQL_PASSWORD=your_password
98+
TACO_MSSQL_DBNAME=taco
99+
```
100+
101+
### Defaults
102+
- **Host**: `localhost`
103+
- **Port**: `1433`
104+
- **Database Name**: `taco`
105+
106+
### Example Connection
107+
108+
```bash
109+
export TACO_QUERY_BACKEND=mssql
110+
export TACO_MSSQL_HOST=sqlserver.example.com
111+
export TACO_MSSQL_PORT=1433
112+
export TACO_MSSQL_USER=taco_admin
113+
export TACO_MSSQL_PASSWORD=secure_password
114+
export TACO_MSSQL_DBNAME=taco_db
115+
```
116+
117+
## MySQL
118+
119+
Use MySQL for compatibility with existing MySQL infrastructure.
120+
121+
As an example I used `CREATE DATABASE taco CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;` when testing the MySQL setup.
122+
123+
### Environment Variables
124+
125+
```bash
126+
# Backend selection
127+
TACO_QUERY_BACKEND=mysql
128+
129+
# MySQL-specific configuration
130+
TACO_MYSQL_HOST=localhost
131+
TACO_MYSQL_PORT=3306
132+
TACO_MYSQL_USER=root
133+
TACO_MYSQL_PASSWORD=your_password
134+
TACO_MYSQL_DBNAME=taco
135+
TACO_MYSQL_CHARSET=utf8mb4
136+
```
137+
138+
### Defaults
139+
- **Host**: `localhost`
140+
- **Port**: `3306`
141+
- **User**: `root`
142+
- **Database Name**: `taco`
143+
- **Charset**: `utf8mb4`
144+
145+
### Example Connection
146+
147+
```bash
148+
export TACO_QUERY_BACKEND=mysql
149+
export TACO_MYSQL_HOST=mysql.example.com
150+
export TACO_MYSQL_PORT=3306
151+
export TACO_MYSQL_USER=taco_user
152+
export TACO_MYSQL_PASSWORD=secure_password
153+
export TACO_MYSQL_DBNAME=taco_production
154+
export TACO_MYSQL_CHARSET=utf8mb4
155+
```
156+
157+
## Quick Start Examples
158+
159+
### Development (SQLite)
160+
161+
```bash
162+
# No configuration needed - SQLite is the default
163+
./taco
164+
```
165+
166+
### Production (PostgreSQL)
167+
168+
```bash
169+
export TACO_QUERY_BACKEND=postgres
170+
export TACO_POSTGRES_HOST=prod-db.example.com
171+
export TACO_POSTGRES_USER=taco_prod
172+
export TACO_POSTGRES_PASSWORD=$PROD_DB_PASSWORD
173+
export TACO_POSTGRES_DBNAME=taco
174+
export TACO_POSTGRES_SSLMODE=require
175+
176+
./taco
177+
```
178+
179+
## Notes
180+
181+
- **SQLite** is best for local development and testing
182+
- **PostgreSQL** is recommended for production deployments
183+
- **MSSQL** and **MySQL** are available for enterprise compatibility
184+
- Database schemas are automatically initialized on first run

docs/mint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"ce/state-management/digger-integration",
6060
"ce/state-management/development",
6161
"ce/state-management/analytics",
62+
"ce/state-management/query-backend",
6263
"ce/state-management/versioning",
6364
"ce/state-management/gcp-quickstart",
6465
"ce/state-management/aws-fargate-ad-quickstart"

go.mod

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
module github.com/diggerhq/digger
22

33
go 1.24.0
4+
5+
require (
6+
filippo.io/edwards25519 v1.1.0 // indirect
7+
github.com/go-sql-driver/mysql v1.8.1 // indirect
8+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
9+
github.com/golang-sql/sqlexp v0.1.0 // indirect
10+
github.com/google/uuid v1.6.0 // indirect
11+
github.com/jackc/pgpassfile v1.0.0 // indirect
12+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
13+
github.com/jackc/pgx/v5 v5.6.0 // indirect
14+
github.com/jackc/puddle/v2 v2.2.2 // indirect
15+
github.com/jinzhu/inflection v1.0.0 // indirect
16+
github.com/jinzhu/now v1.1.5 // indirect
17+
github.com/kelseyhightower/envconfig v1.4.0 // indirect
18+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
19+
github.com/microsoft/go-mssqldb v1.8.2 // indirect
20+
golang.org/x/crypto v0.31.0 // indirect
21+
golang.org/x/sync v0.10.0 // indirect
22+
golang.org/x/text v0.21.0 // indirect
23+
gorm.io/driver/mysql v1.6.0 // indirect
24+
gorm.io/driver/postgres v1.6.0 // indirect
25+
gorm.io/driver/sqlite v1.6.0 // indirect
26+
gorm.io/driver/sqlserver v1.6.1 // indirect
27+
gorm.io/gorm v1.31.0 // indirect
28+
)

0 commit comments

Comments
 (0)