@oktis-works/database 0.4.14 → 0.4.16
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.
- package/dist/schema/schema.sql +27 -0
- package/package.json +1 -1
package/dist/schema/schema.sql
CHANGED
|
@@ -511,10 +511,17 @@ CREATE TABLE IF NOT EXISTS sessions (
|
|
|
511
511
|
created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
|
|
512
512
|
);
|
|
513
513
|
|
|
514
|
+
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS refresh_token_hash VARCHAR(128);
|
|
515
|
+
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS refresh_family_id UUID;
|
|
516
|
+
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS revoked_at TIMESTAMP WITH TIME ZONE;
|
|
517
|
+
ALTER TABLE sessions ADD COLUMN IF NOT EXISTS replaced_by_session_id UUID;
|
|
518
|
+
|
|
514
519
|
CREATE INDEX IF NOT EXISTS idx_sessions_user ON sessions(user_id);
|
|
515
520
|
CREATE INDEX IF NOT EXISTS idx_sessions_tenant ON sessions(tenant_id);
|
|
516
521
|
CREATE INDEX IF NOT EXISTS idx_sessions_token ON sessions(token);
|
|
517
522
|
CREATE INDEX IF NOT EXISTS idx_sessions_expires ON sessions(expires_at);
|
|
523
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_refresh_hash ON sessions(refresh_token_hash);
|
|
524
|
+
CREATE INDEX IF NOT EXISTS idx_sessions_refresh_family ON sessions(refresh_family_id);
|
|
518
525
|
|
|
519
526
|
-- ============================================================
|
|
520
527
|
-- Custom Taxonomies (SDD ENTI-025)
|
|
@@ -853,6 +860,26 @@ BEGIN
|
|
|
853
860
|
END IF;
|
|
854
861
|
END $$;
|
|
855
862
|
|
|
863
|
+
-- Refresh token lookup happens before the access-token tenant context exists.
|
|
864
|
+
-- The application sets this transaction-local hash only during auth operations,
|
|
865
|
+
-- so RLS still permits exactly one opaque token lookup without exposing the
|
|
866
|
+
-- sessions table to requests from another tenant.
|
|
867
|
+
DO $$
|
|
868
|
+
BEGIN
|
|
869
|
+
IF NOT EXISTS (
|
|
870
|
+
SELECT 1 FROM pg_policies
|
|
871
|
+
WHERE policyname = 'session_refresh_token_access' AND tablename = 'sessions'
|
|
872
|
+
) THEN
|
|
873
|
+
CREATE POLICY session_refresh_token_access ON sessions
|
|
874
|
+
USING (
|
|
875
|
+
refresh_token_hash = NULLIF(current_setting('app.current_refresh_token_hash', true), '')
|
|
876
|
+
)
|
|
877
|
+
WITH CHECK (
|
|
878
|
+
tenant_id = current_setting('app.current_tenant_id', true)::uuid
|
|
879
|
+
);
|
|
880
|
+
END IF;
|
|
881
|
+
END $$;
|
|
882
|
+
|
|
856
883
|
DO $$
|
|
857
884
|
BEGIN
|
|
858
885
|
IF NOT EXISTS (
|