dzql 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,92 +0,0 @@
1
-
2
- -- DZQL V2 Core Schema
3
- CREATE SCHEMA IF NOT EXISTS dzql_v2;
4
- CREATE EXTENSION IF NOT EXISTS pgcrypto;
5
-
6
- -- Migrations Table
7
- CREATE TABLE IF NOT EXISTS dzql_v2.migrations (
8
- id text PRIMARY KEY,
9
- applied_at timestamptz DEFAULT now(),
10
- checksum text NOT NULL,
11
- name text NOT NULL
12
- );
13
-
14
- -- Events Table (Normalized Row Events)
15
- CREATE TABLE IF NOT EXISTS dzql_v2.events (
16
- id bigserial PRIMARY KEY,
17
- commit_id bigint NOT NULL,
18
- table_name text NOT NULL,
19
- op text NOT NULL,
20
- pk jsonb NOT NULL,
21
- data jsonb,
22
- old_data jsonb,
23
- user_id int,
24
- created_at timestamptz DEFAULT now()
25
- );
26
-
27
- -- Commit Sequence
28
- CREATE SEQUENCE IF NOT EXISTS dzql_v2.commit_seq;
29
-
30
- -- === AUTH FUNCTIONS ===
31
-
32
- -- Register User
33
- CREATE OR REPLACE FUNCTION dzql_v2.register_user(p_params jsonb)
34
- RETURNS jsonb
35
- LANGUAGE plpgsql
36
- SECURITY DEFINER
37
- SET search_path = dzql_v2, public
38
- AS $$
39
- DECLARE
40
- v_user_id int;
41
- v_email text;
42
- v_password text;
43
- v_name text;
44
- v_options jsonb;
45
- BEGIN
46
- v_email := p_params->>'email';
47
- v_password := p_params->>'password';
48
- v_name := COALESCE(p_params->>'name', v_email);
49
- v_options := COALESCE(p_params->'options', '{}'::jsonb);
50
-
51
- IF v_email IS NULL OR v_password IS NULL THEN
52
- RAISE EXCEPTION 'validation_error: email and password required';
53
- END IF;
54
-
55
- INSERT INTO users (email, password_hash, name)
56
- VALUES (v_email, crypt(v_password, gen_salt('bf')), v_name)
57
- RETURNING id INTO v_user_id;
58
-
59
- -- TODO: Handle v_options if needed (e.g. creating orgs)
60
-
61
- -- Return minimal profile (Token generation happens in Runtime layer)
62
- RETURN jsonb_build_object(
63
- 'user_id', v_user_id,
64
- 'email', v_email,
65
- 'name', v_name
66
- );
67
- END;
68
- $$;
69
-
70
- -- Login User
71
- CREATE OR REPLACE FUNCTION dzql_v2.login_user(p_params jsonb)
72
- RETURNS jsonb
73
- LANGUAGE plpgsql
74
- SECURITY DEFINER
75
- SET search_path = dzql_v2, public
76
- AS $$
77
- DECLARE
78
- v_user record;
79
- BEGIN
80
- SELECT * INTO v_user FROM users WHERE email = p_params->>'email';
81
-
82
- IF v_user IS NULL OR v_user.password_hash != crypt(p_params->>'password', v_user.password_hash) THEN
83
- RAISE EXCEPTION 'permission_denied: invalid credentials';
84
- END IF;
85
-
86
- RETURN jsonb_build_object(
87
- 'user_id', v_user.id,
88
- 'email', v_user.email,
89
- 'name', v_user.name
90
- );
91
- END;
92
- $$;