-
Notifications
You must be signed in to change notification settings - Fork 584
feat: clickhouse schemas v2 #3914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+4,669
−997
Merged
Changes from 15 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2b1c838
wip
chronark b35512f
feat: WIP clean up clickhouse
chronark 42c1c7a
test: key_verifications_xxx_v2
chronark c162855
fix: bugs
chronark a2bcdc8
fix: tests
chronark 2442ec3
Apply suggestions from code review
chronark f7cea6e
Apply suggestions from code review
chronark dba518b
Apply suggestions from code review
chronark f65cbc2
fix: aggregate staes
chronark d2d3ebf
Merge branch 'clickhouse-schemas' of https://github.com/unkeyed/unkey…
chronark ab798b3
fix: migration end date
chronark 0b8878d
Merge branch 'main' into clickhouse-schemas
chronark 655a7c7
Merge branch 'main' into clickhouse-schemas
Flo4604 edd3765
merge
chronark 9c58c22
docs: tone down the verbosity
chronark bf1c68b
fix: date type and missing table
chronark a574233
fix: schema
chronark eace087
Merge branch 'main' of https://github.com/unkeyed/unkey into clickhou…
chronark 52fe434
[autofix.ci] apply automated fixes
autofix-ci[bot] dfda639
Merge branch 'main' of https://github.com/unkeyed/unkey into clickhou…
chronark c59ab80
Merge branch 'clickhouse-schemas' of https://github.com/unkeyed/unkey…
chronark File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,6 @@ jobs: | |
uses: ./.github/actions/setup-go | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Install Goose | ||
run: go install github.com/pressly/goose/v3/cmd/goose@latest | ||
- name: Build | ||
run: pnpm turbo run build --filter=./apps/api... | ||
env: | ||
|
@@ -42,12 +40,6 @@ jobs: | |
env: | ||
DRIZZLE_DATABASE_URL: "mysql://unkey:password@localhost:3306/unkey" | ||
CI: 1 | ||
- name: Migrate ClickHouse | ||
run: goose up | ||
env: | ||
GOOSE_DRIVER: clickhouse | ||
GOOSE_DBSTRING: "tcp://default:[email protected]:9000" | ||
GOOSE_MIGRATION_DIR: ./internal/clickhouse/schema | ||
- name: Test | ||
run: pnpm vitest run -c vitest.integration.ts --bail=1 | ||
working-directory: apps/api | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,18 +12,6 @@ down: | |
up: down build | ||
docker compose -f ./deployment/docker-compose.yaml up -d | ||
|
||
migrate-clickhouse: | ||
@export GOOSE_DRIVER=clickhouse && \ | ||
export GOOSE_DBSTRING="tcp://default:[email protected]:9000" && \ | ||
export GOOSE_MIGRATION_DIR=./internal/clickhouse/schema && \ | ||
goose up | ||
|
||
migrate-clickhouse-reset: | ||
@export GOOSE_DRIVER=clickhouse && \ | ||
export GOOSE_DBSTRING="tcp://default:[email protected]:9000" && \ | ||
export GOOSE_MIGRATION_DIR=./internal/clickhouse/schema && \ | ||
goose down-to 0 | ||
|
||
integration: up | ||
@cd apps/api && \ | ||
$(MAKE) seed && \ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM bitnami/clickhouse:25.6.4 | ||
|
||
# Copy ClickHouse schemas | ||
COPY go/pkg/clickhouse/migrations /opt/clickhouse-schemas/ | ||
|
||
# Create initialization script that will execute our SQL files on first run | ||
# (script is already made executable on host) | ||
COPY deployment/init-clickhouse.sh /docker-entrypoint-initdb.d/init-clickhouse.sh | ||
chronark marked this conversation as resolved.
Show resolved
Hide resolved
chronark marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
echo "Initializing ClickHouse schemas..." | ||
|
||
# Execute SQL files in order from our schemas directory | ||
|
||
# Execute SQL files in numerical order | ||
for sql_file in /opt/clickhouse-schemas/*.sql; do | ||
echo "Executing: $sql_file" | ||
|
||
if ! clickhouse-client --host localhost --user "$CLICKHOUSE_ADMIN_USER" --password "$CLICKHOUSE_ADMIN_PASSWORD" --queries-file "$sql_file"; then | ||
echo "Error executing $sql_file - stopping initialization" | ||
exit 1 | ||
fi | ||
done | ||
|
||
echo "ClickHouse schema initialization complete!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Package array provides generic utility functions for slice generation and manipulation. | ||
// | ||
// The package implements core operations for test data generation: creating slices with | ||
// generated values ([Fill]), selecting random elements ([Random]), transforming slices ([Map]), | ||
// and aggregating slice data ([Reduce]). | ||
// | ||
// All functions use Go generics for type safety and are optimized for high-frequency use | ||
// in test data generation scenarios. | ||
// | ||
// # Usage | ||
// | ||
// Generate slices with [Fill]: | ||
// | ||
// userIDs := array.Fill(1000, func() string { | ||
// return fmt.Sprintf("user_%d", rand.Intn(100000)) | ||
// }) | ||
// | ||
// Select random elements with [Random]: | ||
// | ||
// outcomes := []string{"VALID", "INVALID", "EXPIRED"} | ||
// outcome := array.Random(outcomes) | ||
// | ||
// Transform data with [Map]: | ||
// | ||
// numbers := []int{1, 2, 3} | ||
// strings := array.Map(numbers, strconv.Itoa) | ||
// | ||
// Aggregate data with [Reduce]: | ||
// | ||
// sum := array.Reduce(numbers, func(acc, val int) int { return acc + val }, 0) | ||
// | ||
// # Performance | ||
// | ||
// [Fill] uses single allocation with O(n) time complexity. [Random] operates in O(1) constant time. | ||
// [Map] and [Reduce] both use O(n) time with single allocation where applicable. | ||
// | ||
// # Concurrency | ||
// | ||
// All functions are safe for concurrent use when operating on different slices. [Random] uses | ||
// Go's global RNG which may become a bottleneck under extreme concurrency. | ||
package array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package array | ||
|
||
// Fill creates a new slice with the specified length where each element is generated by calling the provided function. | ||
// | ||
// The generator function is called exactly length times in sequential order. Returns an empty slice | ||
// for zero or negative length. | ||
// | ||
// Parameters: | ||
// - length: Number of elements to create | ||
// - generator: Function called once per element to generate the value | ||
// | ||
// The returned slice has capacity equal to length for optimal memory allocation. | ||
// | ||
// // Generate test data | ||
// userIDs := array.Fill(1000, func() string { | ||
// return fmt.Sprintf("user_%d", rand.Intn(10000)) | ||
// }) | ||
// | ||
// // Create structs with varying properties | ||
// testCases := array.Fill(100, func() TestCase { | ||
// return TestCase{ID: rand.Int(), Created: time.Now()} | ||
// }) | ||
func Fill[T any](length int, generator func() T) []T { | ||
if length <= 0 { | ||
return []T{} | ||
} | ||
|
||
slice := make([]T, length) | ||
for i := range length { | ||
slice[i] = generator() | ||
} | ||
return slice | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.