Skip to content

Commit fef5945

Browse files
committed
chore: remove the auth. namespace mess
1 parent 7f42eaa commit fef5945

File tree

47 files changed

+400
-445
lines changed

Some content is hidden

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

47 files changed

+400
-445
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,6 @@ Connection string for the database.
262262

263263
Sets the maximum number of open connections to the database. Defaults to 0 which is equivalent to an "unlimited" number of connections.
264264

265-
`DB_NAMESPACE` - `string`
266-
267-
Adds a prefix to all table names.
268-
269265
**Migrations Note**
270266

271267
Migrations are applied automatically when you run `./gotrue`. However, you also have the option to rerun the migrations via the following methods:

app.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
"GOTRUE_DB_AUTOMIGRATE": {
1212
"value": true
1313
},
14-
"GOTRUE_DB_NAMESPACE": {
15-
"value": "auth"
16-
},
1714
"GOTRUE_JWT_SECRET": {
1815
"required": true
1916
},

cmd/migrate_cmd.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func migrate(cmd *cobra.Command, args []string) {
6363
}
6464
deets.Options = map[string]string{
6565
"migration_table_name": "schema_migrations",
66-
"Namespace": globalConfig.DB.Namespace,
6766
}
6867

6968
db, err := pop.NewConnection(deets)

docker-compose-dev.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,5 @@ services:
2828
- POSTGRES_USER=postgres
2929
- POSTGRES_PASSWORD=root
3030
- POSTGRES_DB=postgres
31-
# sets the schema name, this should match the `NAMESPACE` env var set in your .env file
32-
- DB_NAMESPACE=auth
3331
volumes:
3432
postgres_data:

example.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ GOTRUE_JWT_ADMIN_ROLES="supabase_admin,service_role"
99

1010
# Database & API connection details
1111
GOTRUE_DB_DRIVER="postgres"
12-
DB_NAMESPACE="auth"
1312
DATABASE_URL="postgres://supabase_auth_admin:root@localhost:5432/postgres"
1413
API_EXTERNAL_URL="http://localhost:9999"
1514
GOTRUE_API_HOST="localhost"

gotrue.exe

32.4 MB
Binary file not shown.

hack/test.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ GOTRUE_JWT_AUD="authenticated"
44
GOTRUE_JWT_ADMIN_ROLES="supabase_admin,service_role"
55
GOTRUE_JWT_DEFAULT_GROUP_NAME="authenticated"
66
GOTRUE_DB_DRIVER=postgres
7-
DB_NAMESPACE="auth"
87
GOTRUE_DB_AUTOMIGRATE=true
98
DATABASE_URL="postgres://supabase_auth_admin:root@localhost:5432/postgres"
109
GOTRUE_API_HOST=localhost

init_postgres.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,5 @@ psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-E
66
77
-- Supabase super admin
88
CREATE USER supabase_auth_admin NOINHERIT CREATEROLE LOGIN NOREPLICATION PASSWORD 'root';
9-
CREATE SCHEMA IF NOT EXISTS $DB_NAMESPACE AUTHORIZATION supabase_auth_admin;
109
GRANT CREATE ON DATABASE postgres TO supabase_auth_admin;
11-
ALTER USER supabase_auth_admin SET search_path = '$DB_NAMESPACE';
1210
EOSQL

internal/api/mfa_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (ts *MFATestSuite) TestMFAVerifyFactor() {
237237
// Set challenge creation so that it has expired in present time.
238238
newCreatedAt := time.Now().UTC().Add(-1 * time.Second * time.Duration(ts.Config.MFA.ChallengeExpiryDuration+1))
239239
// created_at is managed by buffalo(ORM) needs to be raw query to be updated
240-
err := ts.API.db.RawQuery("UPDATE auth.mfa_challenges SET created_at = ? WHERE factor_id = ?", newCreatedAt, f.ID).Exec()
240+
err := ts.API.db.RawQuery("UPDATE mfa_challenges SET created_at = ? WHERE factor_id = ?", newCreatedAt, f.ID).Exec()
241241
require.NoError(ts.T(), err, "Error updating new test challenge")
242242
}
243243

internal/api/samlacs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ func (a *API) SAMLACS(w http.ResponseWriter, r *http.Request) error {
266266
var terr error
267267
var user *models.User
268268

269-
// accounts potentially created via SAML can contain non-unique email addresses in the auth.users table
269+
// accounts potentially created via SAML can contain non-unique email addresses in the users table
270270
if user, terr = a.createAccountFromExternalIdentity(tx, r, &userProvidedData, "sso:"+ssoProvider.ID.String()); terr != nil {
271271
return terr
272272
}

migrations/00_init_auth_schema.up.sql

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
-- auth.users definition
2-
3-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.users (
1+
-- users definition
2+
CREATE TABLE IF NOT EXISTS users (
43
instance_id uuid NULL,
54
id uuid NOT NULL UNIQUE,
65
aud varchar(255) NULL,
@@ -24,13 +23,11 @@ CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.users (
2423
updated_at timestamptz NULL,
2524
CONSTRAINT users_pkey PRIMARY KEY (id)
2625
);
27-
CREATE INDEX IF NOT EXISTS users_instance_id_email_idx ON {{ index .Options "Namespace" }}.users USING btree (instance_id, email);
28-
CREATE INDEX IF NOT EXISTS users_instance_id_idx ON {{ index .Options "Namespace" }}.users USING btree (instance_id);
29-
comment on table {{ index .Options "Namespace" }}.users is 'Auth: Stores user login data within a secure schema.';
30-
31-
-- auth.refresh_tokens definition
32-
33-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.refresh_tokens (
26+
CREATE INDEX IF NOT EXISTS users_instance_id_email_idx ON users USING btree (instance_id, email);
27+
CREATE INDEX IF NOT EXISTS users_instance_id_idx ON users USING btree (instance_id);
28+
comment on table users is 'Auth: Stores user login data within a secure schema.';
29+
-- refresh_tokens definition
30+
CREATE TABLE IF NOT EXISTS refresh_tokens (
3431
instance_id uuid NULL,
3532
id bigserial NOT NULL,
3633
"token" varchar(255) NULL,
@@ -40,49 +37,47 @@ CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.refresh_tokens (
4037
updated_at timestamptz NULL,
4138
CONSTRAINT refresh_tokens_pkey PRIMARY KEY (id)
4239
);
43-
CREATE INDEX IF NOT EXISTS refresh_tokens_instance_id_idx ON {{ index .Options "Namespace" }}.refresh_tokens USING btree (instance_id);
44-
CREATE INDEX IF NOT EXISTS refresh_tokens_instance_id_user_id_idx ON {{ index .Options "Namespace" }}.refresh_tokens USING btree (instance_id, user_id);
45-
CREATE INDEX IF NOT EXISTS refresh_tokens_token_idx ON {{ index .Options "Namespace" }}.refresh_tokens USING btree (token);
46-
comment on table {{ index .Options "Namespace" }}.refresh_tokens is 'Auth: Store of tokens used to refresh JWT tokens once they expire.';
47-
48-
-- auth.instances definition
49-
50-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.instances (
40+
CREATE INDEX IF NOT EXISTS refresh_tokens_instance_id_idx ON refresh_tokens USING btree (instance_id);
41+
CREATE INDEX IF NOT EXISTS refresh_tokens_instance_id_user_id_idx ON refresh_tokens USING btree (instance_id, user_id);
42+
CREATE INDEX IF NOT EXISTS refresh_tokens_token_idx ON refresh_tokens USING btree (token);
43+
comment on table refresh_tokens is 'Auth: Store of tokens used to refresh JWT tokens once they expire.';
44+
-- instances definition
45+
CREATE TABLE IF NOT EXISTS instances (
5146
id uuid NOT NULL,
5247
uuid uuid NULL,
5348
raw_base_config text NULL,
5449
created_at timestamptz NULL,
5550
updated_at timestamptz NULL,
5651
CONSTRAINT instances_pkey PRIMARY KEY (id)
5752
);
58-
comment on table {{ index .Options "Namespace" }}.instances is 'Auth: Manages users across multiple sites.';
59-
60-
-- auth.audit_log_entries definition
61-
62-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.audit_log_entries (
53+
comment on table instances is 'Auth: Manages users across multiple sites.';
54+
-- audit_log_entries definition
55+
CREATE TABLE IF NOT EXISTS audit_log_entries (
6356
instance_id uuid NULL,
6457
id uuid NOT NULL,
6558
payload json NULL,
6659
created_at timestamptz NULL,
6760
CONSTRAINT audit_log_entries_pkey PRIMARY KEY (id)
6861
);
69-
CREATE INDEX IF NOT EXISTS audit_logs_instance_id_idx ON {{ index .Options "Namespace" }}.audit_log_entries USING btree (instance_id);
70-
comment on table {{ index .Options "Namespace" }}.audit_log_entries is 'Auth: Audit trail for user actions.';
71-
72-
-- auth.schema_migrations definition
73-
74-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.schema_migrations (
62+
CREATE INDEX IF NOT EXISTS audit_logs_instance_id_idx ON audit_log_entries USING btree (instance_id);
63+
comment on table audit_log_entries is 'Auth: Audit trail for user actions.';
64+
-- schema_migrations definition
65+
CREATE TABLE IF NOT EXISTS schema_migrations (
7566
"version" varchar(255) NOT NULL,
7667
CONSTRAINT schema_migrations_pkey PRIMARY KEY ("version")
7768
);
78-
comment on table auth.schema_migrations is 'Auth: Manages updates to the auth system.';
79-
69+
comment on table schema_migrations is 'Auth: Manages updates to the auth system.';
8070
-- Gets the User ID from the request cookie
81-
create or replace function {{ index .Options "Namespace" }}.uid() returns uuid as $$
82-
select nullif(current_setting('request.jwt.claim.sub', true), '')::uuid;
71+
create or replace function uid() returns uuid as $$
72+
select nullif(
73+
current_setting('request.jwt.claim.sub', true),
74+
''
75+
)::uuid;
8376
$$ language sql stable;
84-
8577
-- Gets the User ID from the request cookie
86-
create or replace function {{ index .Options "Namespace" }}.role() returns text as $$
87-
select nullif(current_setting('request.jwt.claim.role', true), '')::text;
88-
$$ language sql stable;
78+
create or replace function role() returns text as $$
79+
select nullif(
80+
current_setting('request.jwt.claim.role', true),
81+
''
82+
)::text;
83+
$$ language sql stable;
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
-- alter user schema
2-
3-
ALTER TABLE {{ index .Options "Namespace" }}.users
2+
ALTER TABLE users
43
ADD COLUMN IF NOT EXISTS phone VARCHAR(15) NULL UNIQUE DEFAULT NULL,
5-
ADD COLUMN IF NOT EXISTS phone_confirmed_at timestamptz NULL DEFAULT NULL,
6-
ADD COLUMN IF NOT EXISTS phone_change VARCHAR(15) NULL DEFAULT '',
7-
ADD COLUMN IF NOT EXISTS phone_change_token VARCHAR(255) NULL DEFAULT '',
8-
ADD COLUMN IF NOT EXISTS phone_change_sent_at timestamptz NULL DEFAULT NULL;
9-
10-
DO $$
11-
BEGIN
12-
IF NOT EXISTS(SELECT *
13-
FROM information_schema.columns
14-
WHERE table_schema = '{{ index .Options "Namespace" }}' and table_name='users' and column_name='email_confirmed_at')
15-
THEN
16-
ALTER TABLE "{{ index .Options "Namespace" }}"."users" RENAME COLUMN "confirmed_at" TO "email_confirmed_at";
17-
END IF;
18-
END $$;
19-
4+
ADD COLUMN IF NOT EXISTS phone_confirmed_at timestamptz NULL DEFAULT NULL,
5+
ADD COLUMN IF NOT EXISTS phone_change VARCHAR(15) NULL DEFAULT '',
6+
ADD COLUMN IF NOT EXISTS phone_change_token VARCHAR(255) NULL DEFAULT '',
7+
ADD COLUMN IF NOT EXISTS phone_change_sent_at timestamptz NULL DEFAULT NULL;
8+
DO $$ BEGIN IF NOT EXISTS(
9+
SELECT *
10+
FROM information_schema.columns
11+
WHERE table_name = 'users'
12+
and column_name = 'email_confirmed_at'
13+
) THEN
14+
ALTER TABLE "users"
15+
RENAME COLUMN "confirmed_at" TO "email_confirmed_at";
16+
END IF;
17+
END $$;
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
-- adds confirmed at
2-
3-
ALTER TABLE {{ index .Options "Namespace" }}.users
4-
ADD COLUMN IF NOT EXISTS confirmed_at timestamptz GENERATED ALWAYS AS (LEAST (users.email_confirmed_at, users.phone_confirmed_at)) STORED;
2+
ALTER TABLE users
3+
ADD COLUMN IF NOT EXISTS confirmed_at timestamptz GENERATED ALWAYS AS (
4+
LEAST (
5+
users.email_confirmed_at,
6+
users.phone_confirmed_at
7+
)
8+
) STORED;
Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
-- adds email_change_confirmed
2-
3-
ALTER TABLE {{ index .Options "Namespace" }}.users
4-
ADD COLUMN IF NOT EXISTS email_change_token_current varchar(255) null DEFAULT '',
5-
ADD COLUMN IF NOT EXISTS email_change_confirm_status smallint DEFAULT 0 CHECK (email_change_confirm_status >= 0 AND email_change_confirm_status <= 2);
6-
7-
DO $$
8-
BEGIN
9-
IF NOT EXISTS(SELECT *
10-
FROM information_schema.columns
11-
WHERE table_schema = '{{ index .Options "Namespace" }}' and table_name='users' and column_name='email_change_token_new')
12-
THEN
13-
ALTER TABLE "{{ index .Options "Namespace" }}"."users" RENAME COLUMN "email_change_token" TO "email_change_token_new";
14-
END IF;
15-
END $$;
2+
ALTER TABLE users
3+
ADD COLUMN IF NOT EXISTS email_change_token_current varchar(255) null DEFAULT '',
4+
ADD COLUMN IF NOT EXISTS email_change_confirm_status smallint DEFAULT 0 CHECK (
5+
email_change_confirm_status >= 0
6+
AND email_change_confirm_status <= 2
7+
);
8+
DO $$ BEGIN IF NOT EXISTS(
9+
SELECT *
10+
FROM information_schema.columns
11+
WHERE table_name = 'users'
12+
and column_name = 'email_change_token_new'
13+
) THEN
14+
ALTER TABLE "users"
15+
RENAME COLUMN "email_change_token" TO "email_change_token_new";
16+
END IF;
17+
END $$;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
-- adds identities table
2-
3-
CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.identities (
2+
CREATE TABLE IF NOT EXISTS identities (
43
id text NOT NULL,
54
user_id uuid NOT NULL,
65
identity_data JSONB NOT NULL,
@@ -9,6 +8,6 @@ CREATE TABLE IF NOT EXISTS {{ index .Options "Namespace" }}.identities (
98
created_at timestamptz NULL,
109
updated_at timestamptz NULL,
1110
CONSTRAINT identities_pkey PRIMARY KEY (provider, id),
12-
CONSTRAINT identities_user_id_fkey FOREIGN KEY (user_id) REFERENCES {{ index .Options "Namespace" }}.users(id) ON DELETE CASCADE
11+
CONSTRAINT identities_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
1312
);
14-
COMMENT ON TABLE {{ index .Options "Namespace" }}.identities is 'Auth: Stores identities associated to a user.';
13+
COMMENT ON TABLE identities is 'Auth: Stores identities associated to a user.';
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
-- adds parent column
2-
3-
ALTER TABLE {{ index .Options "Namespace" }}.refresh_tokens
2+
ALTER TABLE refresh_tokens
43
ADD COLUMN IF NOT EXISTS parent varchar(255) NULL;
5-
6-
DO $$
7-
BEGIN
8-
IF NOT EXISTS(SELECT *
9-
FROM information_schema.constraint_column_usage
10-
WHERE table_schema = '{{ index .Options "Namespace" }}' and table_name='refresh_tokens' and constraint_name='refresh_tokens_token_unique')
11-
THEN
12-
ALTER TABLE "{{ index .Options "Namespace" }}"."refresh_tokens" ADD CONSTRAINT refresh_tokens_token_unique UNIQUE ("token");
13-
END IF;
14-
15-
IF NOT EXISTS(SELECT *
16-
FROM information_schema.constraint_column_usage
17-
WHERE table_schema = '{{ index .Options "Namespace" }}' and table_name='refresh_tokens' and constraint_name='refresh_tokens_parent_fkey')
18-
THEN
19-
ALTER TABLE "{{ index .Options "Namespace" }}"."refresh_tokens" ADD CONSTRAINT refresh_tokens_parent_fkey FOREIGN KEY (parent) REFERENCES {{ index .Options "Namespace" }}.refresh_tokens("token");
20-
END IF;
21-
22-
CREATE INDEX IF NOT EXISTS refresh_tokens_parent_idx ON "{{ index .Options "Namespace" }}"."refresh_tokens" USING btree (parent);
23-
END $$;
24-
4+
DO $$ BEGIN IF NOT EXISTS(
5+
SELECT *
6+
FROM information_schema.constraint_column_usage
7+
WHERE table_name = 'refresh_tokens'
8+
and constraint_name = 'refresh_tokens_token_unique'
9+
) THEN
10+
ALTER TABLE "refresh_tokens"
11+
ADD CONSTRAINT refresh_tokens_token_unique UNIQUE ("token");
12+
END IF;
13+
IF NOT EXISTS(
14+
SELECT *
15+
FROM information_schema.constraint_column_usage
16+
WHERE table_name = 'refresh_tokens'
17+
and constraint_name = 'refresh_tokens_parent_fkey'
18+
) THEN
19+
ALTER TABLE "refresh_tokens"
20+
ADD CONSTRAINT refresh_tokens_parent_fkey FOREIGN KEY (parent) REFERENCES refresh_tokens("token");
21+
END IF;
22+
CREATE INDEX IF NOT EXISTS refresh_tokens_parent_idx ON "refresh_tokens" USING btree (parent);
23+
END $$;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
-- create index on identities.user_id
2-
3-
CREATE INDEX IF NOT EXISTS identities_user_id_idx ON "{{ index .Options "Namespace" }}".identities using btree (user_id);
2+
CREATE INDEX IF NOT EXISTS identities_user_id_idx ON identities using btree (user_id);
Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,22 @@
11
-- update auth functions
2-
3-
create or replace function {{ index .Options "Namespace" }}.uid()
4-
returns uuid
5-
language sql stable
6-
as $$
7-
select
8-
coalesce(
2+
create or replace function uid() returns uuid language sql stable as $$
3+
select coalesce(
94
current_setting('request.jwt.claim.sub', true),
10-
(current_setting('request.jwt.claims', true)::jsonb ->> 'sub')
11-
)::uuid
12-
$$;
13-
14-
create or replace function {{ index .Options "Namespace" }}.role()
15-
returns text
16-
language sql stable
17-
as $$
18-
select
19-
coalesce(
5+
(
6+
current_setting('request.jwt.claims', true)::jsonb->>'sub'
7+
)
8+
)::uuid $$;
9+
create or replace function role() returns text language sql stable as $$
10+
select coalesce(
2011
current_setting('request.jwt.claim.role', true),
21-
(current_setting('request.jwt.claims', true)::jsonb ->> 'role')
22-
)::text
23-
$$;
24-
25-
create or replace function {{ index .Options "Namespace" }}.email()
26-
returns text
27-
language sql stable
28-
as $$
29-
select
30-
coalesce(
12+
(
13+
current_setting('request.jwt.claims', true)::jsonb->>'role'
14+
)
15+
)::text $$;
16+
create or replace function email() returns text language sql stable as $$
17+
select coalesce(
3118
current_setting('request.jwt.claim.email', true),
32-
(current_setting('request.jwt.claims', true)::jsonb ->> 'email')
33-
)::text
34-
$$;
19+
(
20+
current_setting('request.jwt.claims', true)::jsonb->>'email'
21+
)
22+
)::text $$;

0 commit comments

Comments
 (0)