diff --git a/indexers/db/docker-entrypoint-initdb.d/init-db.sql b/indexers/db/docker-entrypoint-initdb.d/init-db.sql index 666358ef..17bfe37c 100644 --- a/indexers/db/docker-entrypoint-initdb.d/init-db.sql +++ b/indexers/db/docker-entrypoint-initdb.d/init-db.sql @@ -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'; @@ -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, diff --git a/indexers/db/metadata/databases/default/tables/tables.yaml b/indexers/db/metadata/databases/default/tables/tables.yaml index 5059b844..764643be 100644 --- a/indexers/db/metadata/databases/default/tables/tables.yaml +++ b/indexers/db/metadata/databases/default/tables/tables.yaml @@ -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" diff --git a/indexers/db/metadata/databases/default/tables/users_api_daily_usage.yaml b/indexers/db/metadata/databases/default/tables/users_api_daily_usage.yaml new file mode 100644 index 00000000..53522bdd --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_api_daily_usage.yaml @@ -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: "" diff --git a/indexers/db/metadata/databases/default/tables/users_api_keys.yaml b/indexers/db/metadata/databases/default/tables/users_api_keys.yaml new file mode 100644 index 00000000..00e28fa4 --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_api_keys.yaml @@ -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: "" diff --git a/indexers/db/metadata/databases/default/tables/users_api_keys_daily_usage.yaml b/indexers/db/metadata/databases/default/tables/users_api_keys_daily_usage.yaml new file mode 100644 index 00000000..489fe755 --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_api_keys_daily_usage.yaml @@ -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: "" diff --git a/indexers/db/metadata/databases/default/tables/users_api_keys_monthly_usage.yaml b/indexers/db/metadata/databases/default/tables/users_api_keys_monthly_usage.yaml new file mode 100644 index 00000000..4aff5112 --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_api_keys_monthly_usage.yaml @@ -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: "" diff --git a/indexers/db/metadata/databases/default/tables/users_api_monthly_usage.yaml b/indexers/db/metadata/databases/default/tables/users_api_monthly_usage.yaml new file mode 100644 index 00000000..a55f5c40 --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_api_monthly_usage.yaml @@ -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: "" diff --git a/indexers/db/metadata/databases/default/tables/users_profiles.yaml b/indexers/db/metadata/databases/default/tables/users_profiles.yaml new file mode 100644 index 00000000..e15e93eb --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_profiles.yaml @@ -0,0 +1,137 @@ +table: + name: profiles + schema: users +object_relationships: + - name: api_keys + using: + manual_configuration: + column_mapping: + id: profile_id + insertion_order: null + remote_table: + name: api_keys + schema: users +array_relationships: + - name: api_daily_usage + using: + manual_configuration: + column_mapping: + id: profile_id + insertion_order: null + remote_table: + name: api_daily_usage + schema: users + - name: api_monthly_usage + using: + manual_configuration: + column_mapping: + id: profile_id + insertion_order: null + remote_table: + name: api_monthly_usage + schema: users + - name: wallets + using: + manual_configuration: + column_mapping: + id: profile_id + insertion_order: null + remote_table: + name: wallets + schema: users +insert_permissions: + - role: astral-api + permission: + check: {} + columns: + - account_id + - api_total_requests + - api_total_requests_remaining + - avatar_url + - banner_url + - description + - discord + - discord_is_public + - discord_is_verified + - email + - email_is_public + - email_is_verified + - github + - github_is_public + - github_is_verified + - name + - proof_message + - proof_signature + - twitter + - twitter_is_public + - twitter_is_verified + - website + - website_is_public + - website_is_verified + comment: "" +select_permissions: + - role: astral-api + permission: + columns: + - discord_is_public + - discord_is_verified + - email_is_public + - email_is_verified + - github_is_public + - github_is_verified + - twitter_is_public + - twitter_is_verified + - website_is_public + - website_is_verified + - api_total_requests + - api_total_requests_remaining + - account_id + - avatar_url + - banner_url + - description + - discord + - email + - github + - name + - proof_message + - proof_signature + - twitter + - website + - created_at + - deleted_at + - updated_at + - id + filter: {} + comment: "" +update_permissions: + - role: astral-api + permission: + columns: + - account_id + - api_total_requests + - api_total_requests_remaining + - avatar_url + - banner_url + - deleted_at + - description + - discord + - discord_is_public + - discord_is_verified + - email + - email_is_public + - email_is_verified + - github + - github_is_public + - github_is_verified + - name + - proof_message + - proof_signature + - twitter + - twitter_is_public + - twitter_is_verified + - website + - website_is_public + - website_is_verified + filter: {} + check: null + comment: "" diff --git a/indexers/db/metadata/databases/default/tables/users_wallets.yaml b/indexers/db/metadata/databases/default/tables/users_wallets.yaml new file mode 100644 index 00000000..ab952101 --- /dev/null +++ b/indexers/db/metadata/databases/default/tables/users_wallets.yaml @@ -0,0 +1,43 @@ +table: + name: wallets + 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: astral-api + permission: + check: {} + columns: + - profile_id + - type + - wallet_address + comment: "" +select_permissions: + - role: astral-api + permission: + columns: + - created_at + - deleted_at + - id + - profile_id + - type + - updated_at + - wallet_address + filter: {} + comment: "" +update_permissions: + - role: astral-api + permission: + columns: + - deleted_at + filter: {} + check: null + comment: ""