Skip to content
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

Add users table to db #1052

Merged
merged 4 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions indexers/db/docker-entrypoint-initdb.d/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ ALTER SCHEMA dictionary OWNER TO postgres;
CREATE SCHEMA leaderboard;
ALTER SCHEMA leaderboard OWNER TO postgres;

CREATE SCHEMA users;
ALTER SCHEMA users OWNER TO postgres;

CREATE EXTENSION IF NOT EXISTS btree_gist WITH SCHEMA public;
COMMENT ON EXTENSION btree_gist IS 'support for indexing common datatypes in GiST';

Expand Down Expand Up @@ -83,6 +86,126 @@ CREATE TABLE leaderboard._metadata (
);
ALTER TABLE leaderboard._metadata OWNER TO postgres;


CREATE TABLE users.profiles (
id uuid NOT NULL,
account_id text NOT NULL,
name text NOT NULL,
description text NOT NULL,
avatar_url text NOT NULL,
banner_url text NOT NULL,
email text NOT NULL,
email_is_verified boolean NOT NULL,
email_is_public boolean NOT NULL,
website text NOT NULL,
website_is_verified boolean NOT NULL,
website_is_public boolean NOT NULL,
discord text NOT NULL,
discord_is_verified boolean NOT NULL,
discord_is_public boolean NOT NULL,
github text NOT NULL,
github_is_verified boolean NOT NULL,
github_is_public boolean NOT NULL,
twitter text NOT NULL,
twitter_is_verified boolean NOT NULL,
twitter_is_public boolean NOT NULL,
proof_message text NOT NULL,
proof_signature text NOT NULL,
api_total_requests numeric NOT NULL,
api_total_requests_remaining numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
ALTER TABLE users.profiles OWNER TO postgres;
ALTER TABLE users.profiles ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.profiles ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.profiles ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.api_keys (
id uuid NOT NULL,
profile_id uuid NOT NULL,
description text NOT NULL,
total_requests numeric NOT NULL,
total_requests_remaining numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
ALTER TABLE users.api_keys OWNER TO postgres;
ALTER TABLE users.api_keys ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.api_keys ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.api_keys ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.api_keys_daily_usage (
id uuid NOT NULL,
api_key_id uuid NOT NULL,
total_requests numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);

ALTER TABLE users.api_keys_daily_usage OWNER TO postgres;
ALTER TABLE users.api_keys_daily_usage ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.api_keys_daily_usage ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.api_keys_daily_usage ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.api_keys_monthly_usage (
id uuid NOT NULL,
api_key_id uuid NOT NULL,
total_requests numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
ALTER TABLE users.api_keys_monthly_usage OWNER TO postgres;
ALTER TABLE users.api_keys_monthly_usage ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.api_keys_monthly_usage ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.api_keys_monthly_usage ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.api_daily_usage (
id uuid NOT NULL,
profile_id uuid NOT NULL,
total_requests numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);

ALTER TABLE users.api_daily_usage OWNER TO postgres;
ALTER TABLE users.api_daily_usage ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.api_daily_usage ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.api_daily_usage ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.api_monthly_usage (
id uuid NOT NULL,
profile_id uuid NOT NULL,
total_requests numeric NOT NULL,
total_requests_remaining numeric NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
ALTER TABLE users.api_monthly_usage OWNER TO postgres;
ALTER TABLE users.api_monthly_usage ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.api_monthly_usage ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.api_monthly_usage ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE users.wallets (
id uuid NOT NULL,
profile_id uuid NOT NULL,
wallet_address text NOT NULL,
type text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
deleted_at timestamp with time zone
);
ALTER TABLE users.wallets OWNER TO postgres;
ALTER TABLE users.wallets ALTER COLUMN id SET DEFAULT gen_random_uuid();
ALTER TABLE users.wallets ALTER COLUMN created_at SET DEFAULT now();
ALTER TABLE users.wallets ALTER COLUMN updated_at SET DEFAULT now();

CREATE TABLE consensus.account_histories (
id text NOT NULL,
nonce numeric NOT NULL,
Expand Down
7 changes: 7 additions & 0 deletions indexers/db/metadata/databases/default/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@
- "!include staking_nominators.yaml"
- "!include staking_operators.yaml"
- "!include staking_withdrawals.yaml"
- "!include users_api_daily_usage.yaml"
- "!include users_api_keys.yaml"
- "!include users_api_keys_daily_usage.yaml"
- "!include users_api_keys_monthly_usage.yaml"
- "!include users_api_monthly_usage.yaml"
- "!include users_profiles.yaml"
- "!include users_wallets.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
table:
name: api_daily_usage
schema: users
object_relationships:
- name: profile
using:
manual_configuration:
column_mapping:
profile_id: id
insertion_order: null
remote_table:
name: profiles
schema: users
insert_permissions:
- role: indexers-api
permission:
check: {}
columns:
- profile_id
- total_requests
comment: ""
select_permissions:
- role: astral-api
permission:
columns:
- created_at
- deleted_at
- id
- profile_id
- total_requests
- updated_at
filter: {}
allow_aggregations: true
comment: ""
62 changes: 62 additions & 0 deletions indexers/db/metadata/databases/default/tables/users_api_keys.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
table:
name: api_keys
schema: users
object_relationships:
- name: profile
using:
manual_configuration:
column_mapping:
profile_id: id
insertion_order: null
remote_table:
name: profiles
schema: users
array_relationships:
- name: daily_usage
using:
manual_configuration:
column_mapping:
id: api_key_id
insertion_order: null
remote_table:
name: api_daily_usage
schema: users
- name: monthly_usage
using:
manual_configuration:
column_mapping:
id: api_key_id
insertion_order: null
remote_table:
name: api_monthly_usage
schema: users
insert_permissions:
- role: astral-api
permission:
check: {}
columns:
- description
- profile_id
comment: ""
select_permissions:
- role: astral-api
permission:
columns:
- total_requests
- total_requests_remaining
- description
- created_at
- deleted_at
- updated_at
- id
- profile_id
filter: {}
comment: ""
update_permissions:
- role: astral-api
permission:
columns:
- deleted_at
filter: {}
check: null
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
table:
name: api_keys_daily_usage
schema: users
object_relationships:
- name: api_key
using:
manual_configuration:
column_mapping:
api_key_id: id
insertion_order: null
remote_table:
name: api_keys
schema: users
insert_permissions:
- role: indexers-api
permission:
check: {}
columns:
- api_key_id
- total_requests
comment: ""
select_permissions:
- role: astral-api
permission:
columns:
- total_requests
- created_at
- deleted_at
- updated_at
- api_key_id
- id
filter: {}
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
table:
name: api_keys_monthly_usage
schema: users
object_relationships:
- name: api_key
using:
manual_configuration:
column_mapping:
api_key_id: id
insertion_order: null
remote_table:
name: api_keys
schema: users
insert_permissions:
- role: indexers-api
permission:
check: {}
columns:
- api_key_id
- total_requests
comment: ""
select_permissions:
- role: astral-api
permission:
columns:
- total_requests
- created_at
- deleted_at
- updated_at
- api_key_id
- id
filter: {}
comment: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
table:
name: api_monthly_usage
schema: users
object_relationships:
- name: profile
using:
manual_configuration:
column_mapping:
profile_id: id
insertion_order: null
remote_table:
name: profiles
schema: users
insert_permissions:
- role: indexers-api
permission:
check: {}
columns:
- profile_id
- total_requests
- total_requests_remaining
comment: ""
select_permissions:
- role: astral-api
permission:
columns:
- created_at
- deleted_at
- id
- profile_id
- total_requests
- total_requests_remaining
- updated_at
filter: {}
comment: ""
Loading
Loading