Skip to content

Commit f0c16d0

Browse files
committed
Add tests and wrap migrations in transactions
- Add unit tests for config module (17 tests) - Add unit tests for workers commands with mock backend (15 tests) - Fix password masking for URLs with @ in password - Wrap all migrations in BEGIN/COMMIT for atomicity - Add tempfile dev dependency for tests - Remove unused get_default_alias method
1 parent db724ff commit f0c16d0

25 files changed

Lines changed: 725 additions & 19 deletions

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ uuid = { version = "1", features = ["serde"] }
2222
reqwest = { version = "0.12", features = ["json"] }
2323
sha2 = "0.10"
2424
hex = "0.4"
25+
26+
[dev-dependencies]
27+
tempfile = "3"
28+
uuid = { version = "1", features = ["v4"] }

migrations/00_init.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
-- OpenWorkers Database Schema - Initial Schema
33
--
44

5+
BEGIN;
6+
57
SET client_encoding = 'UTF8';
68

79
-- ============================================================================
@@ -153,3 +155,5 @@ CREATE TRIGGER cron_update
153155
AFTER INSERT OR DELETE OR UPDATE ON crons
154156
FOR EACH ROW
155157
EXECUTE FUNCTION cron_update();
158+
159+
COMMIT;

migrations/01_add_scheduled_events_cascade.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-- when their parent worker is deleted.
77
--
88

9+
BEGIN;
10+
911
-- Drop the existing constraint
1012
ALTER TABLE scheduled_events
1113
DROP CONSTRAINT IF EXISTS scheduled_events_worker_id_fkey;
@@ -17,3 +19,5 @@ ALTER TABLE scheduled_events
1719
REFERENCES workers(id)
1820
ON UPDATE CASCADE
1921
ON DELETE CASCADE;
22+
23+
COMMIT;

migrations/02_auto_timestamps_and_uuids.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
-- 3. Auto-updated updated_at timestamps via trigger function
88
--
99

10+
BEGIN;
11+
1012
-- ============================================================================
1113
-- FUNCTION: Auto update updated_at
1214
-- ============================================================================
@@ -105,3 +107,5 @@ CREATE TRIGGER update_crons_updated_at_trigger
105107
BEFORE UPDATE ON crons
106108
FOR EACH ROW
107109
EXECUTE FUNCTION auto_updated_at();
110+
111+
COMMIT;

migrations/03_databases.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
-- Links openworkers users to postgate databases
44
--
55

6+
BEGIN;
7+
68
-- Databases (references to postgate)
79
CREATE TABLE databases (
810
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
@@ -23,3 +25,5 @@ CREATE TRIGGER update_databases_updated_at_trigger
2325
BEFORE UPDATE ON databases
2426
FOR EACH ROW
2527
EXECUTE FUNCTION auto_updated_at();
28+
29+
COMMIT;

migrations/04_add_databases_resource_limit.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
-- OpenWorkers Database Schema - Add databases to resource_limits
33
--
44

5+
BEGIN;
6+
57
-- Update default for resource_limits column
68
ALTER TABLE users
79
ALTER COLUMN resource_limits SET DEFAULT '{"workers": 5, "environments": 5, "databases": 3}'::jsonb;
@@ -10,3 +12,5 @@ ALTER COLUMN resource_limits SET DEFAULT '{"workers": 5, "environments": 5, "dat
1012
UPDATE users
1113
SET resource_limits = resource_limits || '{"databases": 3}'::jsonb
1214
WHERE NOT resource_limits ? 'databases';
15+
16+
COMMIT;

migrations/05_add_token_id.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
-- This stores the postgate token ID (not the secret) for reference
44
--
55

6+
BEGIN;
7+
68
ALTER TABLE databases ADD COLUMN token_id uuid;
79

810
-- Create index for token lookup
911
CREATE INDEX idx_databases_token_id ON databases(token_id);
12+
13+
COMMIT;

migrations/06_endpoints_and_projects.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
-- and points to either a worker (direct dispatch) or a project (route matching).
77
--
88

9+
BEGIN;
10+
911
-- ============================================================================
1012
-- ENUMS
1113
-- ============================================================================
@@ -85,3 +87,5 @@ CREATE INDEX idx_endpoints_type ON endpoints(type);
8587
CREATE INDEX idx_projects_user_id ON projects(user_id);
8688
CREATE INDEX idx_project_routes_project_id ON project_routes(project_id);
8789
CREATE INDEX idx_project_routes_priority ON project_routes(project_id, priority DESC);
90+
91+
COMMIT;

migrations/07_binding_types.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
-- of the corresponding config table. No FK constraint, validated by CHECK.
99
--
1010

11+
BEGIN;
12+
1113
-- ============================================================================
1214
-- ENUMS
1315
-- ============================================================================
@@ -122,3 +124,5 @@ COMMENT ON COLUMN storage_configs.public_url IS 'Optional CDN URL for public acc
122124

123125
COMMENT ON COLUMN environment_values.type IS 'Binding type: var, secret, assets, storage, kv';
124126
COMMENT ON COLUMN environment_values.value IS 'For var/secret: the value. For bindings: UUID of config table';
127+
128+
COMMIT;

0 commit comments

Comments
 (0)