From df28fc596d2f32652e5d27ca00d2c0c88c5a62cb Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 25 Jan 2023 15:57:46 -0700 Subject: [PATCH 01/17] adding platform DB stuff --- ...-member_role_member-role_invite_apikey.sql | 115 ++++++++++++++++++ pkg/model/entity.go | 65 +++++++++- 2 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql diff --git a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql new file mode 100644 index 00000000..a8d85291 --- /dev/null +++ b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql @@ -0,0 +1,115 @@ +------------------------------------------------------------------------- +-- +goose Up + +------------------------------------------------------------------------- +-- PLATFORM ----------------------------------------------------- +CREATE TABLE platform ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users + name TEXT NOT NULL, + description TEXT NOT NULL, + domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) + ip_addresses TEXT[] DEFAULT NULL, -- define which API ips can make calls (API-to-API) +); + +------------------------------------------------------------------------- +-- MEMBER ----------------------------------------------------- +CREATE TABLE member ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + email TEXT NOT NULL, + password TEXT NOT NULL, -- how do we maintain this? +); + +------------------------------------------------------------------------- +-- PLATFORM_MEMBER ----------------------------------------------------- +CREATE TABLE platform_member ( + platform_id UUID REFERENCES platform (id), + member_id UUID REFERENCES member (id) +); + +CREATE UNIQUE INDEX platform_member_platform_id_member_id_idx ON platform_member(platform_id, member_id); + +------------------------------------------------------------------------- +-- ROLE ----------------------------------------------------- +CREATE TABLE role ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + name TEXT NOT NULL, +); + +------------------------------------------------------------------------- +-- MEMBER_ROLE ----------------------------------------------------- +CREATE TABLE member_role ( + member_id UUID REFERENCES member (id) + role_id UUID REFERENCES role (id), +); + +CREATE UNIQUE INDEX member_role_member_id_role_id_idx ON member_role(member_id, role_id); + +------------------------------------------------------------------------- +-- INVITE ----------------------------------------------------- +CREATE TABLE invite ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + expired_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + accepted_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + email TEXT NOT NULL, + invited_by UUID REFERENCES member (id), + platform_id UUID REFERENCES platform (id), +); + +------------------------------------------------------------------------- +-- APIKEY ----------------------------------------------------- +CREATE TABLE apikey ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + type TEXT NOT NULL, -- [public,private] for now all public? + data TEXT NOT NULL, -- the key itself + description TEXT NOT NULL, + created_by UUID REFERENCES member (id), + platform_id UUID REFERENCES platform (id), +); + + +------------------------------------------------------------------------- +-- +goose Down + +------------------------------------------------------------------------- +-- CONTACT_PLATFORM ----------------------------------------------------- +DROP TABLE IF EXISTS platform; + +------------------------------------------------------------------------- +-- MEMBER ----------------------------------------------------- +DROP TABLE IF EXISTS member; + +------------------------------------------------------------------------- +-- PLATFORM_MEMBER ----------------------------------------------------- +DROP TABLE IF EXISTS platform_member; + +------------------------------------------------------------------------- +-- ROLE ----------------------------------------------------- +DROP TABLE IF EXISTS role; + +------------------------------------------------------------------------- +-- MEMBER_ROLE ----------------------------------------------------- +DROP TABLE IF EXISTS member_role; + +------------------------------------------------------------------------- +-- INVITE ----------------------------------------------------- +DROP TABLE IF EXISTS invite; + +------------------------------------------------------------------------- +-- APIKEY ----------------------------------------------------- +DROP TABLE IF EXISTS apikey; \ No newline at end of file diff --git a/pkg/model/entity.go b/pkg/model/entity.go index 0908e048..0a53dcd2 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -23,7 +23,7 @@ type User struct { } // See PLATFORM in Migrations 0001 -type Platform struct { +type Platform_DEPRECATED struct { ID string `json:"id" db:"id"` CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` @@ -205,3 +205,66 @@ type AuthStrategy struct { func (a AuthStrategy) MarshalBinary() ([]byte, error) { return json.Marshal(a) } + +type Platform struct { + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + ActivatedAt *time.Time `json:"activatedAt,omitempty" db:"activated_at"` + Name string `json:"name" db:"name"` + Description string `json:"description" db:"description"` + Domains pq.StringArray `json:"domains" db:"domains"` + IPAddresses pq.StringArray `json:"ipAddresses" db:"ip_addresses"` +} + +type Member struct { + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + Email string `json:"email" db:"email"` + Password string `json:"password" db:"password"` +} + +type PlatformMember struct { + PlatformID string `json:"platformId" db:"platform_id"` + MemberID string `json:"memberId" db:"member_id"` +} + +type Role struct { + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + Name string `json:"name" db:"name"` +} + +type MemberRole struct { + MemberID string `json:"memberId" db:"member_id"` + RoleID string `json:"roleId" db:"role_id"` +} + +type Invite struct { + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + ExpiredAt *time.Time `json:"expiredAt,omitempty" db:"expired_at"` + AcceptedAt *time.Time `json:"acceptedAt,omitempty" db:"accepted_at"` + Email string `json:"email" db:"email"` + InvitedBy string `json:"invitedBy" db:"invited_by"` + PlatformID string `json:"platformId" db:"platform_id"` +} + +type Apikey struct { + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + Type string `json:"type" db:"type"` + Data string `json:"data" db:"data"` + Description string `json:"description" db:"description"` + CreatedBy string `json:"createdBy" db:"created_by"` + PlatformID string `json:"platformId" db:"platform_id"` +} From 03424df35bddabe434d79b20911cd60bd66329f5 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 14:28:56 -0700 Subject: [PATCH 02/17] move admin api entities into admin api --- pkg/model/entity.go | 67 ++------------------------------------------- 1 file changed, 2 insertions(+), 65 deletions(-) diff --git a/pkg/model/entity.go b/pkg/model/entity.go index 0a53dcd2..bb2fa7f6 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -22,8 +22,8 @@ type User struct { LastName string `json:"lastName" db:"last_name"` } -// See PLATFORM in Migrations 0001 -type Platform_DEPRECATED struct { +// See PLATFORM in Migrations 0001 -- THIS IS DEPRECATED +type Platform struct { ID string `json:"id" db:"id"` CreatedAt time.Time `json:"createdAt" db:"created_at"` UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` @@ -205,66 +205,3 @@ type AuthStrategy struct { func (a AuthStrategy) MarshalBinary() ([]byte, error) { return json.Marshal(a) } - -type Platform struct { - ID string `json:"id,omitempty" db:"id"` - CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - ActivatedAt *time.Time `json:"activatedAt,omitempty" db:"activated_at"` - Name string `json:"name" db:"name"` - Description string `json:"description" db:"description"` - Domains pq.StringArray `json:"domains" db:"domains"` - IPAddresses pq.StringArray `json:"ipAddresses" db:"ip_addresses"` -} - -type Member struct { - ID string `json:"id,omitempty" db:"id"` - CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - Email string `json:"email" db:"email"` - Password string `json:"password" db:"password"` -} - -type PlatformMember struct { - PlatformID string `json:"platformId" db:"platform_id"` - MemberID string `json:"memberId" db:"member_id"` -} - -type Role struct { - ID string `json:"id,omitempty" db:"id"` - CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - Name string `json:"name" db:"name"` -} - -type MemberRole struct { - MemberID string `json:"memberId" db:"member_id"` - RoleID string `json:"roleId" db:"role_id"` -} - -type Invite struct { - ID string `json:"id,omitempty" db:"id"` - CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - ExpiredAt *time.Time `json:"expiredAt,omitempty" db:"expired_at"` - AcceptedAt *time.Time `json:"acceptedAt,omitempty" db:"accepted_at"` - Email string `json:"email" db:"email"` - InvitedBy string `json:"invitedBy" db:"invited_by"` - PlatformID string `json:"platformId" db:"platform_id"` -} - -type Apikey struct { - ID string `json:"id,omitempty" db:"id"` - CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - Type string `json:"type" db:"type"` - Data string `json:"data" db:"data"` - Description string `json:"description" db:"description"` - CreatedBy string `json:"createdBy" db:"created_by"` - PlatformID string `json:"platformId" db:"platform_id"` -} From 9ae4940846e4389d15ac4ca3ecae79293143a078 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 15:13:41 -0700 Subject: [PATCH 03/17] deprecate old 'platform' --- .../0001_string-user_platform_asset_network.sql | 10 +++++----- ...platform_device_contact_location_instrument.sql | 2 +- ...atform_device-instrument_tx-leg_transaction.sql | 4 ++-- ...tform-member_role_member-role_invite_apikey.sql | 14 +++++++------- pkg/repository/platform.go | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/migrations/0001_string-user_platform_asset_network.sql b/migrations/0001_string-user_platform_asset_network.sql index 06590b6d..bbd157f5 100644 --- a/migrations/0001_string-user_platform_asset_network.sql +++ b/migrations/0001_string-user_platform_asset_network.sql @@ -43,7 +43,7 @@ EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- -- PLATFORM ------------------------------------------------------------- -CREATE TABLE platform ( +CREATE TABLE platform_deprecated ( id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -54,9 +54,9 @@ CREATE TABLE platform ( api_key TEXT DEFAULT '', authentication TEXT DEFAULT '' --enum [email, phone, wallet] ); -CREATE OR REPLACE TRIGGER update_platform_updated_at +CREATE OR REPLACE TRIGGER update_platform_deprecated_updated_at BEFORE UPDATE - ON platform + ON platform_deprecated FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); @@ -121,8 +121,8 @@ DROP TABLE IF EXISTS network; ------------------------------------------------------------------------- -- PLATFORM ------------------------------------------------------------- -DROP TRIGGER IF EXISTS update_platform_updated_at ON platfom; -DROP TABLE IF EXISTS platform; +DROP TRIGGER IF EXISTS update_platform_deprecated_updated_at ON platform_deprecated; +DROP TABLE IF EXISTS platform_deprecated; ------------------------------------------------------------------------- -- STRING_USER ---------------------------------------------------------- diff --git a/migrations/0002_user-platform_device_contact_location_instrument.sql b/migrations/0002_user-platform_device_contact_location_instrument.sql index 8d7e009b..4820ad57 100644 --- a/migrations/0002_user-platform_device_contact_location_instrument.sql +++ b/migrations/0002_user-platform_device_contact_location_instrument.sql @@ -5,7 +5,7 @@ -- USER_PLATFORM -------------------------------------------------------- CREATE TABLE user_platform ( user_id UUID REFERENCES string_user (id), - platform_id UUID REFERENCES platform (id) + platform_id UUID REFERENCES platform_deprecated (id) ); CREATE UNIQUE INDEX user_platform_user_id_platform_id_idx ON user_platform(user_id, platform_id); diff --git a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql index a981ef0b..cd6e73ab 100644 --- a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql +++ b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql @@ -5,7 +5,7 @@ -- CONTACT_PLATFORM ----------------------------------------------------- CREATE TABLE contact_platform ( contact_id UUID REFERENCES contact (id), - platform_id UUID REFERENCES platform (id) + platform_id UUID REFERENCES platform_deprecated (id) ); CREATE UNIQUE INDEX contact_platform_contact_id_platform_id_idx ON contact_platform(contact_id, platform_id); @@ -67,7 +67,7 @@ CREATE TABLE transaction ( tags JSONB DEFAULT '{}'::JSONB, -- Empty but will be used for Unit21. These are key-val pairs for flagging transactions device_id UUID REFERENCES device (id), -- id that correlates to end-users device in our Device table, we get the data from fingerprint.com -- TODO: Get this with fingerprint integration ip_address TEXT DEFAULT '', -- we get this data from fingerprint.com, whatever is being used at time of transaction - platform_id UUID REFERENCES platform (id), -- id that correlates to CUSTOMER in our Platform table (ie gamefi.xyz) + platform_id UUID REFERENCES platform_deprecated (id), -- id that correlates to CUSTOMER in our Platform table (ie gamefi.xyz) transaction_hash TEXT DEFAULT '', -- EVM/network TX ID after it is generated by executor network_id UUID NOT NULL REFERENCES network (id), -- id that correlates to the Network (Chain) in our Network table network_fee TEXT DEFAULT '', -- The true amount of gas in wei that was used to facilitate the transaction diff --git a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql index a8d85291..daa8dede 100644 --- a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql +++ b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql @@ -12,7 +12,7 @@ CREATE TABLE platform ( name TEXT NOT NULL, description TEXT NOT NULL, domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) - ip_addresses TEXT[] DEFAULT NULL, -- define which API ips can make calls (API-to-API) + ip_addresses TEXT[] DEFAULT NULL -- define which API ips can make calls (API-to-API) ); ------------------------------------------------------------------------- @@ -23,7 +23,7 @@ CREATE TABLE member ( updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, email TEXT NOT NULL, - password TEXT NOT NULL, -- how do we maintain this? + password TEXT NOT NULL -- how do we maintain this? ); ------------------------------------------------------------------------- @@ -42,14 +42,14 @@ CREATE TABLE role ( created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - name TEXT NOT NULL, + name TEXT NOT NULL ); ------------------------------------------------------------------------- -- MEMBER_ROLE ----------------------------------------------------- CREATE TABLE member_role ( - member_id UUID REFERENCES member (id) - role_id UUID REFERENCES role (id), + member_id UUID REFERENCES member (id), + role_id UUID REFERENCES role (id) ); CREATE UNIQUE INDEX member_role_member_id_role_id_idx ON member_role(member_id, role_id); @@ -65,7 +65,7 @@ CREATE TABLE invite ( accepted_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, email TEXT NOT NULL, invited_by UUID REFERENCES member (id), - platform_id UUID REFERENCES platform (id), + platform_id UUID REFERENCES platform (id) ); ------------------------------------------------------------------------- @@ -79,7 +79,7 @@ CREATE TABLE apikey ( data TEXT NOT NULL, -- the key itself description TEXT NOT NULL, created_by UUID REFERENCES member (id), - platform_id UUID REFERENCES platform (id), + platform_id UUID REFERENCES platform (id) ); diff --git a/pkg/repository/platform.go b/pkg/repository/platform.go index 8313cbee..f4c712e6 100644 --- a/pkg/repository/platform.go +++ b/pkg/repository/platform.go @@ -32,13 +32,13 @@ type platform[T any] struct { } func NewPlatform(db *sqlx.DB) Platform { - return &platform[model.Platform]{base: base[model.Platform]{store: db, table: "platform"}} + return &platform[model.Platform]{base: base[model.Platform]{store: db, table: "platform_deprecated"}} } func (p platform[T]) Create(m model.Platform) (model.Platform, error) { plat := model.Platform{} rows, err := p.store.NamedQuery(` - INSERT INTO platform (type, authentication, api_key, status) + INSERT INTO platform_deprecated (type, authentication, api_key, status) VALUES(:type, :authentication, :api_key, :status) RETURNING *`, m) if err != nil { From 53d4dffa692ff0d56fd260d5b6a96ea1d4cb4172 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 16:06:19 -0700 Subject: [PATCH 04/17] alter platform table instead of dropping it --- ...001_string-user_platform_asset_network.sql | 10 +++--- ...orm_device_contact_location_instrument.sql | 2 +- ...m_device-instrument_tx-leg_transaction.sql | 4 +-- ...-member_role_member-role_invite_apikey.sql | 36 ++++++++++++------- pkg/repository/platform.go | 4 +-- 5 files changed, 33 insertions(+), 23 deletions(-) diff --git a/migrations/0001_string-user_platform_asset_network.sql b/migrations/0001_string-user_platform_asset_network.sql index bbd157f5..265d424b 100644 --- a/migrations/0001_string-user_platform_asset_network.sql +++ b/migrations/0001_string-user_platform_asset_network.sql @@ -43,7 +43,7 @@ EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- -- PLATFORM ------------------------------------------------------------- -CREATE TABLE platform_deprecated ( +CREATE TABLE platform ( id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, @@ -54,9 +54,9 @@ CREATE TABLE platform_deprecated ( api_key TEXT DEFAULT '', authentication TEXT DEFAULT '' --enum [email, phone, wallet] ); -CREATE OR REPLACE TRIGGER update_platform_deprecated_updated_at +CREATE OR REPLACE TRIGGER update_platform_updated_at BEFORE UPDATE - ON platform_deprecated + ON platform FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); @@ -121,8 +121,8 @@ DROP TABLE IF EXISTS network; ------------------------------------------------------------------------- -- PLATFORM ------------------------------------------------------------- -DROP TRIGGER IF EXISTS update_platform_deprecated_updated_at ON platform_deprecated; -DROP TABLE IF EXISTS platform_deprecated; +DROP TRIGGER IF EXISTS update_platform_updated_at ON platform; +DROP TABLE IF EXISTS platform; ------------------------------------------------------------------------- -- STRING_USER ---------------------------------------------------------- diff --git a/migrations/0002_user-platform_device_contact_location_instrument.sql b/migrations/0002_user-platform_device_contact_location_instrument.sql index 4820ad57..8d7e009b 100644 --- a/migrations/0002_user-platform_device_contact_location_instrument.sql +++ b/migrations/0002_user-platform_device_contact_location_instrument.sql @@ -5,7 +5,7 @@ -- USER_PLATFORM -------------------------------------------------------- CREATE TABLE user_platform ( user_id UUID REFERENCES string_user (id), - platform_id UUID REFERENCES platform_deprecated (id) + platform_id UUID REFERENCES platform (id) ); CREATE UNIQUE INDEX user_platform_user_id_platform_id_idx ON user_platform(user_id, platform_id); diff --git a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql index cd6e73ab..a981ef0b 100644 --- a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql +++ b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql @@ -5,7 +5,7 @@ -- CONTACT_PLATFORM ----------------------------------------------------- CREATE TABLE contact_platform ( contact_id UUID REFERENCES contact (id), - platform_id UUID REFERENCES platform_deprecated (id) + platform_id UUID REFERENCES platform (id) ); CREATE UNIQUE INDEX contact_platform_contact_id_platform_id_idx ON contact_platform(contact_id, platform_id); @@ -67,7 +67,7 @@ CREATE TABLE transaction ( tags JSONB DEFAULT '{}'::JSONB, -- Empty but will be used for Unit21. These are key-val pairs for flagging transactions device_id UUID REFERENCES device (id), -- id that correlates to end-users device in our Device table, we get the data from fingerprint.com -- TODO: Get this with fingerprint integration ip_address TEXT DEFAULT '', -- we get this data from fingerprint.com, whatever is being used at time of transaction - platform_id UUID REFERENCES platform_deprecated (id), -- id that correlates to CUSTOMER in our Platform table (ie gamefi.xyz) + platform_id UUID REFERENCES platform (id), -- id that correlates to CUSTOMER in our Platform table (ie gamefi.xyz) transaction_hash TEXT DEFAULT '', -- EVM/network TX ID after it is generated by executor network_id UUID NOT NULL REFERENCES network (id), -- id that correlates to the Network (Chain) in our Network table network_fee TEXT DEFAULT '', -- The true amount of gas in wei that was used to facilitate the transaction diff --git a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql index daa8dede..c78e0678 100644 --- a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql +++ b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql @@ -3,17 +3,17 @@ ------------------------------------------------------------------------- -- PLATFORM ----------------------------------------------------- -CREATE TABLE platform ( - id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users - name TEXT NOT NULL, - description TEXT NOT NULL, - domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) - ip_addresses TEXT[] DEFAULT NULL -- define which API ips can make calls (API-to-API) -); +ALTER TABLE platform + DROP COLUMN IF EXISTS type, + DROP COLUMN IF EXISTS status, + DROP COLUMN IF EXISTS name, + DROP COLUMN IF EXISTS api_key, + DROP COLUMN IF EXISTS authentication, + ADD COLUMN activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users + ADD COLUMN name TEXT NOT NULL, + ADD COLUMN description TEXT NOT NULL, + ADD COLUMN domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) + ADD COLUMN ip_addresses TEXT[] DEFAULT NULL; -- define which API ips can make calls (API-to-API) ------------------------------------------------------------------------- -- MEMBER ----------------------------------------------------- @@ -87,8 +87,18 @@ CREATE TABLE apikey ( -- +goose Down ------------------------------------------------------------------------- --- CONTACT_PLATFORM ----------------------------------------------------- -DROP TABLE IF EXISTS platform; +-- PLATFORM ----------------------------------------------------- +ALTER TABLE platform + DROP COLUMN IF EXISTS activated_at, + DROP COLUMN IF EXISTS name, + DROP COLUMN IF EXISTS description, + DROP COLUMN IF EXISTS domains, + DROP COLUMN IF EXISTS ip_addresses + ADD COLUMN type TEXT NOT NULL, -- enum: to be defined at struct level in Go + ADD COLUMN status TEXT NOT NULL, -- enum: to be defined at struct level in Go + ADD COLUMN name TEXT DEFAULT '', + ADD COLUMN api_key TEXT DEFAULT '', + ADD COLUMN authentication TEXT DEFAULT ''; --enum [email, phone, wallet] ------------------------------------------------------------------------- -- MEMBER ----------------------------------------------------- diff --git a/pkg/repository/platform.go b/pkg/repository/platform.go index f4c712e6..8313cbee 100644 --- a/pkg/repository/platform.go +++ b/pkg/repository/platform.go @@ -32,13 +32,13 @@ type platform[T any] struct { } func NewPlatform(db *sqlx.DB) Platform { - return &platform[model.Platform]{base: base[model.Platform]{store: db, table: "platform_deprecated"}} + return &platform[model.Platform]{base: base[model.Platform]{store: db, table: "platform"}} } func (p platform[T]) Create(m model.Platform) (model.Platform, error) { plat := model.Platform{} rows, err := p.store.NamedQuery(` - INSERT INTO platform_deprecated (type, authentication, api_key, status) + INSERT INTO platform (type, authentication, api_key, status) VALUES(:type, :authentication, :api_key, :status) RETURNING *`, m) if err != nil { From 4373877b0f01c948fa67d054b334b1a9bcc933e2 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 17:04:41 -0700 Subject: [PATCH 05/17] change tabs to 2 spaces in migrations 5 --- ...rm_member_platform-member_role_member-role_invite_apikey.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql index c78e0678..5c51c85e 100644 --- a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql +++ b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql @@ -2,7 +2,7 @@ -- +goose Up ------------------------------------------------------------------------- --- PLATFORM ----------------------------------------------------- +-- PLATFORM ---------------------------------------------------- ALTER TABLE platform DROP COLUMN IF EXISTS type, DROP COLUMN IF EXISTS status, From 1970863108f8cde1cba5d0f088c060ef32c8e3a7 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 18:06:22 -0700 Subject: [PATCH 06/17] Updated this_to_that naming convention in entities, repos --- api/config.go | 24 +++++++-------- pkg/internal/unit21/entity.go | 8 ++--- pkg/model/entity.go | 6 ++-- pkg/repository/base.go | 24 +++++++-------- pkg/repository/contact_platform.go | 42 -------------------------- pkg/repository/contact_to_platform.go | 42 ++++++++++++++++++++++++++ pkg/repository/user_platform.go | 43 --------------------------- pkg/repository/user_to_platform.go | 43 +++++++++++++++++++++++++++ pkg/service/user.go | 12 ++++---- 9 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 pkg/repository/contact_platform.go create mode 100644 pkg/repository/contact_to_platform.go delete mode 100644 pkg/repository/user_platform.go create mode 100644 pkg/repository/user_to_platform.go diff --git a/api/config.go b/api/config.go index a783a3fd..22a974b5 100644 --- a/api/config.go +++ b/api/config.go @@ -10,18 +10,18 @@ import ( func NewRepos(config APIConfig) repository.Repositories { // TODO: Make sure all of the repos are initialized here return repository.Repositories{ - Auth: repository.NewAuth(config.Redis, config.DB), - User: repository.NewUser(config.DB), - Contact: repository.NewContact(config.DB), - Instrument: repository.NewInstrument(config.DB), - Device: repository.NewDevice(config.DB), - UserPlatform: repository.NewUserPlatform(config.DB), - Asset: repository.NewAsset(config.DB), - Network: repository.NewNetwork(config.DB), - Platform: repository.NewPlatform(config.DB), - Transaction: repository.NewTransaction(config.DB), - TxLeg: repository.NewTxLeg(config.DB), - Location: repository.NewLocation(config.DB), + Auth: repository.NewAuth(config.Redis, config.DB), + User: repository.NewUser(config.DB), + Contact: repository.NewContact(config.DB), + Instrument: repository.NewInstrument(config.DB), + Device: repository.NewDevice(config.DB), + UserToPlatform: repository.NewUserToPlatform(config.DB), + Asset: repository.NewAsset(config.DB), + Network: repository.NewNetwork(config.DB), + Platform: repository.NewPlatform(config.DB), + Transaction: repository.NewTransaction(config.DB), + TxLeg: repository.NewTxLeg(config.DB), + Location: repository.NewLocation(config.DB), } } diff --git a/pkg/internal/unit21/entity.go b/pkg/internal/unit21/entity.go index 958ba091..3437e593 100644 --- a/pkg/internal/unit21/entity.go +++ b/pkg/internal/unit21/entity.go @@ -17,9 +17,9 @@ type Entity interface { } type EntityRepos struct { - Device repository.Device - Contact repository.Contact - UserPlatform repository.UserPlatform + Device repository.Device + Contact repository.Contact + UserToPlatform repository.UserToPlatform } type entity struct { @@ -176,7 +176,7 @@ func (e entity) getEntityDigitalData(userId string) (deviceData entityDigitalDat } func (e entity) getCustomData(userId string) (customData entityCustomData, err error) { - devices, err := e.repo.UserPlatform.ListByUserId(userId, 100, 0) + devices, err := e.repo.UserToPlatform.ListByUserId(userId, 100, 0) if err != nil { log.Printf("Failed to get user platforms: %s", err) err = common.StringError(err) diff --git a/pkg/model/entity.go b/pkg/model/entity.go index bb2fa7f6..96382a7f 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -65,7 +65,7 @@ type Asset struct { } // See USER_PLATFORM in Migrations 0002 -type UserPlatform struct { +type UserToPlatform struct { UserID string `json:"userId" db:"user_id"` PlatformID string `json:"platformId" db:"platform_id"` } @@ -135,13 +135,13 @@ type Instrument struct { } // See CONTACT_PLATFORM in Migrations 0003 -type ContactPlatform struct { +type ContactToPlatform struct { ContactID string `json:"contactId" db:"contact_id"` PlatformID string `json:"platformId" db:"platform_id"` } // See DEVICE_INSTRUMENT in Migrations 0003 -type DeviceInstrument struct { +type DeviceToInstrument struct { DeviceID string `json:"deviceId" db:"device_id"` InstrumentID string `json:"instrumentId" db:"instrument_id"` } diff --git a/pkg/repository/base.go b/pkg/repository/base.go index 87b5ccb9..8f78d12a 100644 --- a/pkg/repository/base.go +++ b/pkg/repository/base.go @@ -15,18 +15,18 @@ import ( var ErrNotFound = errors.New("not found") type Repositories struct { - Auth AuthStrategy - User User - Contact Contact - Instrument Instrument - Device Device - UserPlatform UserPlatform - Asset Asset - Network Network - Platform Platform - Transaction Transaction - TxLeg TxLeg - Location Location + Auth AuthStrategy + User User + Contact Contact + Instrument Instrument + Device Device + UserToPlatform UserToPlatform + Asset Asset + Network Network + Platform Platform + Transaction Transaction + TxLeg TxLeg + Location Location } type Queryable interface { diff --git a/pkg/repository/contact_platform.go b/pkg/repository/contact_platform.go deleted file mode 100644 index 8f4a29d0..00000000 --- a/pkg/repository/contact_platform.go +++ /dev/null @@ -1,42 +0,0 @@ -package repository - -import ( - "github.com/String-xyz/string-api/pkg/internal/common" - "github.com/String-xyz/string-api/pkg/model" - "github.com/jmoiron/sqlx" -) - -type ContactPlatform interface { - Transactable - Readable - Create(model.ContactPlatform) (model.ContactPlatform, error) - GetById(ID string) (model.ContactPlatform, error) - List(limit int, offset int) ([]model.ContactPlatform, error) - Update(ID string, updates any) error -} - -type contactPlatform[T any] struct { - base[T] -} - -func NewContactPlatform(db *sqlx.DB) ContactPlatform { - return &contactPlatform[model.ContactPlatform]{base: base[model.ContactPlatform]{store: db, table: "contact_platform"}} -} - -func (u contactPlatform[T]) Create(insert model.ContactPlatform) (model.ContactPlatform, error) { - m := model.ContactPlatform{} - rows, err := u.store.NamedQuery(` - INSERT INTO contact_platform (contact_id, platform_id) - VALUES(:contact_id, :platform_id) RETURNING *`, insert) - if err != nil { - return m, common.StringError(err) - } - for rows.Next() { - err = rows.StructScan(&m) - if err != nil { - return m, common.StringError(err) - } - } - defer rows.Close() - return m, nil -} diff --git a/pkg/repository/contact_to_platform.go b/pkg/repository/contact_to_platform.go new file mode 100644 index 00000000..ca0d1543 --- /dev/null +++ b/pkg/repository/contact_to_platform.go @@ -0,0 +1,42 @@ +package repository + +import ( + "github.com/String-xyz/string-api/pkg/internal/common" + "github.com/String-xyz/string-api/pkg/model" + "github.com/jmoiron/sqlx" +) + +type ContactToPlatform interface { + Transactable + Readable + Create(model.ContactToPlatform) (model.ContactToPlatform, error) + GetById(ID string) (model.ContactToPlatform, error) + List(limit int, offset int) ([]model.ContactToPlatform, error) + Update(ID string, updates any) error +} + +type contactToPlatform[T any] struct { + base[T] +} + +func NewContactPlatform(db *sqlx.DB) ContactToPlatform { + return &contactToPlatform[model.ContactToPlatform]{base: base[model.ContactToPlatform]{store: db, table: "contact_to_platform"}} +} + +func (u contactToPlatform[T]) Create(insert model.ContactToPlatform) (model.ContactToPlatform, error) { + m := model.ContactToPlatform{} + rows, err := u.store.NamedQuery(` + INSERT INTO contact_to_platform (contact_id, platform_id) + VALUES(:contact_id, :platform_id) RETURNING *`, insert) + if err != nil { + return m, common.StringError(err) + } + for rows.Next() { + err = rows.StructScan(&m) + if err != nil { + return m, common.StringError(err) + } + } + defer rows.Close() + return m, nil +} diff --git a/pkg/repository/user_platform.go b/pkg/repository/user_platform.go deleted file mode 100644 index b098150d..00000000 --- a/pkg/repository/user_platform.go +++ /dev/null @@ -1,43 +0,0 @@ -package repository - -import ( - "github.com/String-xyz/string-api/pkg/internal/common" - "github.com/String-xyz/string-api/pkg/model" - "github.com/jmoiron/sqlx" -) - -type UserPlatform interface { - Transactable - Readable - Create(model.UserPlatform) (model.UserPlatform, error) - GetById(ID string) (model.UserPlatform, error) - List(limit int, offset int) ([]model.UserPlatform, error) - ListByUserId(userID string, imit int, offset int) ([]model.UserPlatform, error) - Update(ID string, updates any) error -} - -type userPlatform[T any] struct { - base[T] -} - -func NewUserPlatform(db *sqlx.DB) UserPlatform { - return &userPlatform[model.UserPlatform]{base: base[model.UserPlatform]{store: db, table: "user_platform"}} -} - -func (u userPlatform[T]) Create(insert model.UserPlatform) (model.UserPlatform, error) { - m := model.UserPlatform{} - rows, err := u.store.NamedQuery(` - INSERT INTO user_platform (user_id, platform_id) - VALUES(:user_id, :platform_id) RETURNING *`, insert) - if err != nil { - return m, common.StringError(err) - } - for rows.Next() { - err = rows.StructScan(&m) - if err != nil { - return m, common.StringError(err) - } - } - defer rows.Close() - return m, nil -} diff --git a/pkg/repository/user_to_platform.go b/pkg/repository/user_to_platform.go new file mode 100644 index 00000000..c3fc066b --- /dev/null +++ b/pkg/repository/user_to_platform.go @@ -0,0 +1,43 @@ +package repository + +import ( + "github.com/String-xyz/string-api/pkg/internal/common" + "github.com/String-xyz/string-api/pkg/model" + "github.com/jmoiron/sqlx" +) + +type UserToPlatform interface { + Transactable + Readable + Create(model.UserToPlatform) (model.UserToPlatform, error) + GetById(ID string) (model.UserToPlatform, error) + List(limit int, offset int) ([]model.UserToPlatform, error) + ListByUserId(userID string, imit int, offset int) ([]model.UserToPlatform, error) + Update(ID string, updates any) error +} + +type userToPlatform[T any] struct { + base[T] +} + +func NewUserToPlatform(db *sqlx.DB) UserToPlatform { + return &userToPlatform[model.UserToPlatform]{base: base[model.UserToPlatform]{store: db, table: "user_to_platform"}} +} + +func (u userToPlatform[T]) Create(insert model.UserToPlatform) (model.UserToPlatform, error) { + m := model.UserToPlatform{} + rows, err := u.store.NamedQuery(` + INSERT INTO user_to_platform (user_id, platform_id) + VALUES(:user_id, :platform_id) RETURNING *`, insert) + if err != nil { + return m, common.StringError(err) + } + for rows.Next() { + err = rows.StructScan(&m) + if err != nil { + return m, common.StringError(err) + } + } + defer rows.Close() + return m, nil +} diff --git a/pkg/service/user.go b/pkg/service/user.go index 13d485f9..f30e53e1 100644 --- a/pkg/service/user.go +++ b/pkg/service/user.go @@ -173,9 +173,9 @@ func (u user) Update(userID string, request UserUpdates) (model.User, error) { func (u user) createUnit21Entity(user model.User) { // Createing a User Entity in Unit21 u21Repo := unit21.EntityRepos{ - Device: u.repos.Device, - Contact: u.repos.Contact, - UserPlatform: u.repos.UserPlatform, + Device: u.repos.Device, + Contact: u.repos.Contact, + UserToPlatform: u.repos.UserToPlatform, } u21Entity := unit21.NewEntity(u21Repo) // TODO: Make it an injected dependency @@ -188,9 +188,9 @@ func (u user) createUnit21Entity(user model.User) { func (u user) updateUnit21Entity(user model.User) { // Createing a User Entity in Unit21 u21Repo := unit21.EntityRepos{ - Device: u.repos.Device, - Contact: u.repos.Contact, - UserPlatform: u.repos.UserPlatform, + Device: u.repos.Device, + Contact: u.repos.Contact, + UserToPlatform: u.repos.UserToPlatform, } u21Entity := unit21.NewEntity(u21Repo) From 6f7e9249cb00a1399a94b22a3e2eb649dc1c8a2f Mon Sep 17 00:00:00 2001 From: Ocasta Date: Thu, 26 Jan 2023 19:08:24 -0600 Subject: [PATCH 07/17] fixed some spacing, renamed many-to-many relationships as table-to-table --- ...001_string-user_platform_asset_network.sql | 30 ++--- ...orm_device_contact_location_instrument.sql | 24 ++-- ...m_device-instrument_tx-leg_transaction.sql | 12 +- migrations/0004_auth_key.sql | 6 +- ...-member_role_member-role_invite_apikey.sql | 125 ------------------ ...platform_device-to-instrument_platform.sql | 94 +++++++++++++ ...le_member-to-role_member-invite_apikey.sql | 97 ++++++++++++++ 7 files changed, 227 insertions(+), 161 deletions(-) delete mode 100644 migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql create mode 100644 migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql create mode 100644 migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql diff --git a/migrations/0001_string-user_platform_asset_network.sql b/migrations/0001_string-user_platform_asset_network.sql index 265d424b..d816e3c3 100644 --- a/migrations/0001_string-user_platform_asset_network.sql +++ b/migrations/0001_string-user_platform_asset_network.sql @@ -10,11 +10,11 @@ CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; ------------------------------------------------------------------------- -- +goose StatementBegin CREATE OR REPLACE FUNCTION update_updated_at_column() - RETURNS TRIGGER AS + RETURNS TRIGGER AS $$ BEGIN - NEW.updated_at = now(); - RETURN NEW; + NEW.updated_at = now(); + RETURN NEW; END; $$ language 'plpgsql'; -- +goose StatementEnd @@ -36,9 +36,9 @@ CREATE TABLE string_user ( ); CREATE OR REPLACE TRIGGER update_string_user_updated_at - BEFORE UPDATE - ON string_user - FOR EACH ROW + BEFORE UPDATE + ON string_user + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -55,9 +55,9 @@ CREATE TABLE platform ( authentication TEXT DEFAULT '' --enum [email, phone, wallet] ); CREATE OR REPLACE TRIGGER update_platform_updated_at - BEFORE UPDATE - ON platform - FOR EACH ROW + BEFORE UPDATE + ON platform + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -76,9 +76,9 @@ CREATE TABLE network ( explorer_url TEXT DEFAULT '' -- The Block Explorer URL used to view transactions and entities in the browser ); CREATE OR REPLACE TRIGGER update_network_updated_at - BEFORE UPDATE - ON network - FOR EACH ROW + BEFORE UPDATE + ON network + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -97,9 +97,9 @@ CREATE TABLE asset ( -- We will write sql commands to add/update these in bulk. ); CREATE OR REPLACE TRIGGER update_asset_updated_at - BEFORE UPDATE - ON asset - FOR EACH ROW + BEFORE UPDATE + ON asset + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); CREATE INDEX network_gas_token_id_fk ON network (gas_token_id); diff --git a/migrations/0002_user-platform_device_contact_location_instrument.sql b/migrations/0002_user-platform_device_contact_location_instrument.sql index 8d7e009b..4315b060 100644 --- a/migrations/0002_user-platform_device_contact_location_instrument.sql +++ b/migrations/0002_user-platform_device_contact_location_instrument.sql @@ -27,9 +27,9 @@ CREATE TABLE device ( ); CREATE OR REPLACE TRIGGER update_device_updated_at - BEFORE UPDATE - ON device - FOR EACH ROW + BEFORE UPDATE + ON device + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); CREATE UNIQUE INDEX device_fingerprint_id_idx ON device(fingerprint, user_id); @@ -49,9 +49,9 @@ CREATE TABLE contact ( ); CREATE OR REPLACE TRIGGER update_contact_updated_at - BEFORE UPDATE - ON contact - FOR EACH ROW + BEFORE UPDATE + ON contact + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -74,9 +74,9 @@ CREATE TABLE location ( ); CREATE OR REPLACE TRIGGER update_location_updated_at - BEFORE UPDATE - ON location - FOR EACH ROW + BEFORE UPDATE + ON location + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -97,9 +97,9 @@ CREATE TABLE instrument ( ); CREATE OR REPLACE TRIGGER update_instrument_updated_at - BEFORE UPDATE - ON instrument - FOR EACH ROW + BEFORE UPDATE + ON instrument + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- diff --git a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql index a981ef0b..99d8a319 100644 --- a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql +++ b/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql @@ -50,9 +50,9 @@ CREATE TABLE tx_leg ( ); CREATE OR REPLACE TRIGGER update_tx_leg_updated_at - BEFORE UPDATE - ON tx_leg - FOR EACH ROW + BEFORE UPDATE + ON tx_leg + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- @@ -84,9 +84,9 @@ CREATE TABLE transaction ( ); CREATE OR REPLACE TRIGGER update_transaction_updated_at - BEFORE UPDATE - ON transaction - FOR EACH ROW + BEFORE UPDATE + ON transaction + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); ------------------------------------------------------------------------- diff --git a/migrations/0004_auth_key.sql b/migrations/0004_auth_key.sql index 40bfa569..9295d939 100644 --- a/migrations/0004_auth_key.sql +++ b/migrations/0004_auth_key.sql @@ -11,9 +11,9 @@ CREATE TABLE auth_strategy ( ); CREATE OR REPLACE TRIGGER update_auth_strategy_updated_at - BEFORE UPDATE - ON auth_strategy - FOR EACH ROW + BEFORE UPDATE + ON auth_strategy + FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); CREATE INDEX auth_strategy_status_idx ON auth_strategy(status); diff --git a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql b/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql deleted file mode 100644 index 5c51c85e..00000000 --- a/migrations/0005_platform_member_platform-member_role_member-role_invite_apikey.sql +++ /dev/null @@ -1,125 +0,0 @@ -------------------------------------------------------------------------- --- +goose Up - -------------------------------------------------------------------------- --- PLATFORM ---------------------------------------------------- -ALTER TABLE platform - DROP COLUMN IF EXISTS type, - DROP COLUMN IF EXISTS status, - DROP COLUMN IF EXISTS name, - DROP COLUMN IF EXISTS api_key, - DROP COLUMN IF EXISTS authentication, - ADD COLUMN activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users - ADD COLUMN name TEXT NOT NULL, - ADD COLUMN description TEXT NOT NULL, - ADD COLUMN domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) - ADD COLUMN ip_addresses TEXT[] DEFAULT NULL; -- define which API ips can make calls (API-to-API) - -------------------------------------------------------------------------- --- MEMBER ----------------------------------------------------- -CREATE TABLE member ( - id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - email TEXT NOT NULL, - password TEXT NOT NULL -- how do we maintain this? -); - -------------------------------------------------------------------------- --- PLATFORM_MEMBER ----------------------------------------------------- -CREATE TABLE platform_member ( - platform_id UUID REFERENCES platform (id), - member_id UUID REFERENCES member (id) -); - -CREATE UNIQUE INDEX platform_member_platform_id_member_id_idx ON platform_member(platform_id, member_id); - -------------------------------------------------------------------------- --- ROLE ----------------------------------------------------- -CREATE TABLE role ( - id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - name TEXT NOT NULL -); - -------------------------------------------------------------------------- --- MEMBER_ROLE ----------------------------------------------------- -CREATE TABLE member_role ( - member_id UUID REFERENCES member (id), - role_id UUID REFERENCES role (id) -); - -CREATE UNIQUE INDEX member_role_member_id_role_id_idx ON member_role(member_id, role_id); - -------------------------------------------------------------------------- --- INVITE ----------------------------------------------------- -CREATE TABLE invite ( - id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - expired_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - accepted_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - email TEXT NOT NULL, - invited_by UUID REFERENCES member (id), - platform_id UUID REFERENCES platform (id) -); - -------------------------------------------------------------------------- --- APIKEY ----------------------------------------------------- -CREATE TABLE apikey ( - id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), - created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, - deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, - type TEXT NOT NULL, -- [public,private] for now all public? - data TEXT NOT NULL, -- the key itself - description TEXT NOT NULL, - created_by UUID REFERENCES member (id), - platform_id UUID REFERENCES platform (id) -); - - -------------------------------------------------------------------------- --- +goose Down - -------------------------------------------------------------------------- --- PLATFORM ----------------------------------------------------- -ALTER TABLE platform - DROP COLUMN IF EXISTS activated_at, - DROP COLUMN IF EXISTS name, - DROP COLUMN IF EXISTS description, - DROP COLUMN IF EXISTS domains, - DROP COLUMN IF EXISTS ip_addresses - ADD COLUMN type TEXT NOT NULL, -- enum: to be defined at struct level in Go - ADD COLUMN status TEXT NOT NULL, -- enum: to be defined at struct level in Go - ADD COLUMN name TEXT DEFAULT '', - ADD COLUMN api_key TEXT DEFAULT '', - ADD COLUMN authentication TEXT DEFAULT ''; --enum [email, phone, wallet] - -------------------------------------------------------------------------- --- MEMBER ----------------------------------------------------- -DROP TABLE IF EXISTS member; - -------------------------------------------------------------------------- --- PLATFORM_MEMBER ----------------------------------------------------- -DROP TABLE IF EXISTS platform_member; - -------------------------------------------------------------------------- --- ROLE ----------------------------------------------------- -DROP TABLE IF EXISTS role; - -------------------------------------------------------------------------- --- MEMBER_ROLE ----------------------------------------------------- -DROP TABLE IF EXISTS member_role; - -------------------------------------------------------------------------- --- INVITE ----------------------------------------------------- -DROP TABLE IF EXISTS invite; - -------------------------------------------------------------------------- --- APIKEY ----------------------------------------------------- -DROP TABLE IF EXISTS apikey; \ No newline at end of file diff --git a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql new file mode 100644 index 00000000..f3626493 --- /dev/null +++ b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql @@ -0,0 +1,94 @@ +------------------------------------------------------------------------- +-- +goose Up + +------------------------------------------------------------------------- +-- USER_TO_PLATFORM ----------------------------------------------------- +ALTER TABLE user_platform + RENAME TO user_to_platform; + +DROP INDEX user_platform_user_id_platform_id_idx IF EXISTS; + +CREATE UNIQUE INDEX user_to_platform_user_id_platform_id_idx ON user_to_platform(user_id, platform_id); + + +------------------------------------------------------------------------- +-- CONTACT_TO_PLATFORM -------------------------------------------------- +ALTER TABLE contact_platform + RENAME TO contact_to_platform; + +DROP INDEX contact_platform_contact_id_platform_id_idx IF EXISTS; + +CREATE UNIQUE INDEX contact_to_platform_contact_id_platform_id_idx ON contact_to_platform(contact_id, platform_id); + + +------------------------------------------------------------------------- +-- DEVICE_TO_INSTRUMENT ------------------------------------------------- +ALTER TABLE device_instrument + RENAME TO device_to_instrument; + +DROP INDEX device_instrument_device_id_instrument_id_idx IF EXISTS; + +CREATE UNIQUE INDEX device_to_instrument_device_id_instrument_id_idx ON device_to_instrument(device_id, instrument_id); + + +------------------------------------------------------------------------- +-- PLATFORM ------------------------------------------------------------- +ALTER TABLE platform + DROP COLUMN IF EXISTS type, + DROP COLUMN IF EXISTS status, + DROP COLUMN IF EXISTS name, + DROP COLUMN IF EXISTS api_key, + DROP COLUMN IF EXISTS authentication, + ADD COLUMN activated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, -- for activating prod users + ADD COLUMN name TEXT NOT NULL, + ADD COLUMN description TEXT NOT NULL, + ADD COLUMN domains TEXT[] DEFAULT NULL, -- define which domains can make calls to API (web-to-API) + ADD COLUMN ip_addresses TEXT[] DEFAULT NULL; -- define which API ips can make calls (API-to-API) + + +------------------------------------------------------------------------- +-- +goose Down + +------------------------------------------------------------------------- +-- PLATFORM ------------------------------------------------------------- +ALTER TABLE platform + DROP COLUMN IF EXISTS activated_at, + DROP COLUMN IF EXISTS name, + DROP COLUMN IF EXISTS description, + DROP COLUMN IF EXISTS domains, + DROP COLUMN IF EXISTS ip_addresses + ADD COLUMN type TEXT NOT NULL, -- enum: to be defined at struct level in Go + ADD COLUMN status TEXT NOT NULL, -- enum: to be defined at struct level in Go + ADD COLUMN name TEXT DEFAULT '', + ADD COLUMN api_key TEXT DEFAULT '', + ADD COLUMN authentication TEXT DEFAULT ''; --enum [email, phone, wallet] + + +------------------------------------------------------------------------- +-- USER_PLATFORM ----------------------------------------------------- +ALTER TABLE user_to_platform + RENAME TO user_platform; + +DROP INDEX user_to_platform_user_id_platform_id_idx IF EXISTS; + +CREATE UNIQUE INDEX user_platform_user_id_platform_id_idx ON user_platform(user_id, platform_id); + + +------------------------------------------------------------------------- +-- CONTACT_PLATFORM -------------------------------------------------- +ALTER TABLE contact_to_platform + RENAME TO contact_platform; + +DROP INDEX contact_to_platform_contact_id_platform_id_idx IF EXISTS; + +CREATE UNIQUE INDEX contact_platform_contact_id_platform_id_idx ON contact_platform(contact_id, platform_id); + + +------------------------------------------------------------------------- +-- DEVICE_INSTRUMENT ------------------------------------------------- +ALTER TABLE device_to_instrument + RENAME TO device_instrument; + +DROP INDEX device_to_instrument_device_id_instrument_id_idx IF EXISTS; + +CREATE UNIQUE INDEX device_instrument_device_id_instrument_id_idx ON device_instrument(device_id, instrument_id); \ No newline at end of file diff --git a/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql b/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql new file mode 100644 index 00000000..ca8fc054 --- /dev/null +++ b/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql @@ -0,0 +1,97 @@ +------------------------------------------------------------------------- +-- +goose Up + +------------------------------------------------------------------------- +-- PLATFORM_MEMBER ------------------------------------------------------ +CREATE TABLE platform_member ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + email TEXT NOT NULL, + password TEXT NOT NULL -- how do we maintain this? +); + +------------------------------------------------------------------------- +-- PLATFORM_MEMBER ------------------------------------------------------ +CREATE TABLE member_to_platform ( + member_id UUID REFERENCES platform_member (id), + platform_id UUID REFERENCES platform (id) +); + +CREATE UNIQUE INDEX member_to_platform_platform_id_member_id_idx ON member_to_platform(platform_id, member_id); + +------------------------------------------------------------------------- +-- MEMBER_ROLE ---------------------------------------------------------- +CREATE TABLE member_role ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + name TEXT NOT NULL +); + +------------------------------------------------------------------------- +-- MEMBER_TO_ROLE ------------------------------------------------------- +CREATE TABLE member_to_role ( + member_id UUID REFERENCES platform_member (id), + role_id UUID REFERENCES role (id) +); + +CREATE UNIQUE INDEX member_to_role_member_id_role_id_idx ON member_role(member_id, role_id); + +------------------------------------------------------------------------- +-- MEMBER_INVITE -------------------------------------------------------- +CREATE TABLE member_invite ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + expired_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + accepted_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + email TEXT NOT NULL, + invited_by UUID REFERENCES platform_member (id), + platform_id UUID REFERENCES platform (id) +); + +------------------------------------------------------------------------- +-- APIKEY --------------------------------------------------------------- +CREATE TABLE apikey ( + id UUID PRIMARY KEY NOT NULL DEFAULT UUID_GENERATE_V4(), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, + deactivated_at TIMESTAMP WITH TIME ZONE DEFAULT NULL, + type TEXT NOT NULL, -- [public,private] for now all public? + data TEXT NOT NULL, -- the key itself + description TEXT NOT NULL, + created_by UUID REFERENCES platform_member (id), + platform_id UUID REFERENCES platform (id) +); + + +------------------------------------------------------------------------- +-- +goose Down + +------------------------------------------------------------------------- +-- PLATFORM_MEMBER ------------------------------------------------------ +DROP TABLE IF EXISTS platform_member; + +------------------------------------------------------------------------- +-- PLATFORM_TO_MEMBER --------------------------------------------------- +DROP TABLE IF EXISTS member_to_platform; + +------------------------------------------------------------------------- +-- MEMBER_ROLE ---------------------------------------------------------- +DROP TABLE IF EXISTS member_role; + +------------------------------------------------------------------------- +-- MEMBER_TO_ROLE ------------------------------------------------------- +DROP TABLE IF EXISTS member_to_role; + +------------------------------------------------------------------------- +-- MEMBER_INVITE -------------------------------------------------------- +DROP TABLE IF EXISTS member_invite; + +------------------------------------------------------------------------- +-- APIKEY --------------------------------------------------------------- +DROP TABLE IF EXISTS apikey; \ No newline at end of file From f63b69b7340877873b029b268ae9b05f0c1fe0c6 Mon Sep 17 00:00:00 2001 From: Ocasta Date: Thu, 26 Jan 2023 19:19:38 -0600 Subject: [PATCH 08/17] fix order, IF EXISTS, and missing commas --- ...platform_device-to-instrument_platform.sql | 14 ++++----- ...le_member-to-role_member-invite_apikey.sql | 29 ++++++++++--------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql index f3626493..0efdc4bc 100644 --- a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql +++ b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql @@ -6,7 +6,7 @@ ALTER TABLE user_platform RENAME TO user_to_platform; -DROP INDEX user_platform_user_id_platform_id_idx IF EXISTS; +DROP INDEX IF EXISTS user_platform_user_id_platform_id_idx; CREATE UNIQUE INDEX user_to_platform_user_id_platform_id_idx ON user_to_platform(user_id, platform_id); @@ -16,7 +16,7 @@ CREATE UNIQUE INDEX user_to_platform_user_id_platform_id_idx ON user_to_platform ALTER TABLE contact_platform RENAME TO contact_to_platform; -DROP INDEX contact_platform_contact_id_platform_id_idx IF EXISTS; +DROP INDEX IF EXISTS contact_platform_contact_id_platform_id_idx; CREATE UNIQUE INDEX contact_to_platform_contact_id_platform_id_idx ON contact_to_platform(contact_id, platform_id); @@ -26,7 +26,7 @@ CREATE UNIQUE INDEX contact_to_platform_contact_id_platform_id_idx ON contact_to ALTER TABLE device_instrument RENAME TO device_to_instrument; -DROP INDEX device_instrument_device_id_instrument_id_idx IF EXISTS; +DROP INDEX IF EXISTS device_instrument_device_id_instrument_id_idx; CREATE UNIQUE INDEX device_to_instrument_device_id_instrument_id_idx ON device_to_instrument(device_id, instrument_id); @@ -56,7 +56,7 @@ ALTER TABLE platform DROP COLUMN IF EXISTS name, DROP COLUMN IF EXISTS description, DROP COLUMN IF EXISTS domains, - DROP COLUMN IF EXISTS ip_addresses + DROP COLUMN IF EXISTS ip_addresses, ADD COLUMN type TEXT NOT NULL, -- enum: to be defined at struct level in Go ADD COLUMN status TEXT NOT NULL, -- enum: to be defined at struct level in Go ADD COLUMN name TEXT DEFAULT '', @@ -69,7 +69,7 @@ ALTER TABLE platform ALTER TABLE user_to_platform RENAME TO user_platform; -DROP INDEX user_to_platform_user_id_platform_id_idx IF EXISTS; +DROP INDEX IF EXISTS user_to_platform_user_id_platform_id_idx; CREATE UNIQUE INDEX user_platform_user_id_platform_id_idx ON user_platform(user_id, platform_id); @@ -79,7 +79,7 @@ CREATE UNIQUE INDEX user_platform_user_id_platform_id_idx ON user_platform(user_ ALTER TABLE contact_to_platform RENAME TO contact_platform; -DROP INDEX contact_to_platform_contact_id_platform_id_idx IF EXISTS; +DROP INDEX IF EXISTS contact_to_platform_contact_id_platform_id_idx; CREATE UNIQUE INDEX contact_platform_contact_id_platform_id_idx ON contact_platform(contact_id, platform_id); @@ -89,6 +89,6 @@ CREATE UNIQUE INDEX contact_platform_contact_id_platform_id_idx ON contact_platf ALTER TABLE device_to_instrument RENAME TO device_instrument; -DROP INDEX device_to_instrument_device_id_instrument_id_idx IF EXISTS; +DROP INDEX IF EXISTS device_to_instrument_device_id_instrument_id_idx; CREATE UNIQUE INDEX device_instrument_device_id_instrument_id_idx ON device_instrument(device_id, instrument_id); \ No newline at end of file diff --git a/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql b/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql index ca8fc054..43f665d9 100644 --- a/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql +++ b/migrations/0006_platform-member_member-to-platform_member-role_member-to-role_member-invite_apikey.sql @@ -35,10 +35,10 @@ CREATE TABLE member_role ( -- MEMBER_TO_ROLE ------------------------------------------------------- CREATE TABLE member_to_role ( member_id UUID REFERENCES platform_member (id), - role_id UUID REFERENCES role (id) + role_id UUID REFERENCES member_role (id) ); -CREATE UNIQUE INDEX member_to_role_member_id_role_id_idx ON member_role(member_id, role_id); +CREATE UNIQUE INDEX member_to_role_member_id_role_id_idx ON member_to_role(member_id, role_id); ------------------------------------------------------------------------- -- MEMBER_INVITE -------------------------------------------------------- @@ -73,25 +73,28 @@ CREATE TABLE apikey ( -- +goose Down ------------------------------------------------------------------------- --- PLATFORM_MEMBER ------------------------------------------------------ -DROP TABLE IF EXISTS platform_member; +-- APIKEY --------------------------------------------------------------- +DROP TABLE IF EXISTS apikey; ------------------------------------------------------------------------- --- PLATFORM_TO_MEMBER --------------------------------------------------- -DROP TABLE IF EXISTS member_to_platform; +-- MEMBER_INVITE -------------------------------------------------------- +DROP TABLE IF EXISTS member_invite; + +------------------------------------------------------------------------- +-- MEMBER_TO_ROLE ------------------------------------------------------- +DROP TABLE IF EXISTS member_to_role; ------------------------------------------------------------------------- -- MEMBER_ROLE ---------------------------------------------------------- DROP TABLE IF EXISTS member_role; ------------------------------------------------------------------------- --- MEMBER_TO_ROLE ------------------------------------------------------- -DROP TABLE IF EXISTS member_to_role; +-- PLATFORM_TO_MEMBER --------------------------------------------------- +DROP TABLE IF EXISTS member_to_platform; ------------------------------------------------------------------------- --- MEMBER_INVITE -------------------------------------------------------- -DROP TABLE IF EXISTS member_invite; +-- PLATFORM_MEMBER ------------------------------------------------------ +DROP TABLE IF EXISTS platform_member; + + -------------------------------------------------------------------------- --- APIKEY --------------------------------------------------------------- -DROP TABLE IF EXISTS apikey; \ No newline at end of file From 58e7788005bd6a04cb68a58df8fb405eca616fff Mon Sep 17 00:00:00 2001 From: Ocasta Date: Thu, 26 Jan 2023 19:33:38 -0600 Subject: [PATCH 09/17] fix race condition in docker --- docker-compose.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 49edbe1b..50239e4d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,8 +8,10 @@ services: ports: - 5555:5555 depends_on: - - db - - redis + redis: + condition: service_started + db: + condition: service_healthy volumes: - ./:/string_api db: @@ -22,6 +24,11 @@ services: - '5432:5432' volumes: - db:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 redis: image: redis:7.0-alpine restart: always From 0b114241622a9422ef1755ff61b822bc2105d9be Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 26 Jan 2023 19:05:23 -0700 Subject: [PATCH 10/17] fixed some things and broke some other things --- docker-compose.yml | 2 +- pkg/model/entity.go | 20 ++++++++++---------- pkg/repository/platform.go | 28 +++++++++++++--------------- pkg/service/platform.go | 15 ++++++++------- scripts/data_seeding.go | 5 +++-- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 50239e4d..7108b7bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,7 +25,7 @@ services: volumes: - db:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U postgres"] + test: ["CMD-SHELL", "pg_isready -U string_db"] interval: 5s timeout: 5s retries: 5 diff --git a/pkg/model/entity.go b/pkg/model/entity.go index 96382a7f..d8a8e54f 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -22,17 +22,17 @@ type User struct { LastName string `json:"lastName" db:"last_name"` } -// See PLATFORM in Migrations 0001 -- THIS IS DEPRECATED +// See PLATFORM in Migrations 0005 type Platform struct { - ID string `json:"id" db:"id"` - CreatedAt time.Time `json:"createdAt" db:"created_at"` - UpdatedAt time.Time `json:"updatedAt" db:"updated_at"` - DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` - Type string `json:"type" db:"type"` - Status string `json:"status" db:"status"` - Name string `json:"name" db:"name"` - ApiKey string `json:"apiKey" db:"api_key"` - Authentication AuthType `json:"authentication" db:"authentication"` + ID string `json:"id,omitempty" db:"id"` + CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"` + UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"` + DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"` + ActivatedAt *time.Time `json:"activatedAt,omitempty" db:"activated_at"` + Name string `json:"name" db:"name"` + Description string `json:"description" db:"description"` + Domains pq.StringArray `json:"domains" db:"domains"` + IPAddresses pq.StringArray `json:"ipAddresses" db:"ip_addresses"` } // See NETWORK in Migrations 0001 diff --git a/pkg/repository/platform.go b/pkg/repository/platform.go index 8313cbee..f932da80 100644 --- a/pkg/repository/platform.go +++ b/pkg/repository/platform.go @@ -1,8 +1,6 @@ package repository import ( - "database/sql" - "fmt" "time" "github.com/String-xyz/string-api/pkg/internal/common" @@ -24,7 +22,7 @@ type Platform interface { GetById(ID string) (model.Platform, error) List(limit int, offset int) ([]model.Platform, error) Update(ID string, updates any) error - GetByApiKey(key string) (model.Platform, error) + // GetByApiKey(key string) (model.Platform, error) } type platform[T any] struct { @@ -38,8 +36,8 @@ func NewPlatform(db *sqlx.DB) Platform { func (p platform[T]) Create(m model.Platform) (model.Platform, error) { plat := model.Platform{} rows, err := p.store.NamedQuery(` - INSERT INTO platform (type, authentication, api_key, status) - VALUES(:type, :authentication, :api_key, :status) RETURNING *`, m) + INSERT INTO platform (name, description) + VALUES(:name, :description) RETURNING *`, m) if err != nil { return plat, common.StringError(err) @@ -55,13 +53,13 @@ func (p platform[T]) Create(m model.Platform) (model.Platform, error) { return plat, nil } -func (p platform[T]) GetByApiKey(key string) (model.Platform, error) { - m := model.Platform{} - err := p.store.Get(&m, fmt.Sprintf("SELECT * FROM %s WHERE api_key = $1", p.table), key) - if err != nil && err == sql.ErrNoRows { - return m, common.StringError(ErrNotFound) - } else if err != nil { - return m, common.StringError(err) - } - return m, nil -} +// func (p platform[T]) GetByApiKey(key string) (model.Platform, error) { +// m := model.Platform{} +// err := p.store.Get(&m, fmt.Sprintf("SELECT * FROM %s WHERE api_key = $1", p.table), key) +// if err != nil && err == sql.ErrNoRows { +// return m, common.StringError(ErrNotFound) +// } else if err != nil { +// return m, common.StringError(err) +// } +// return m, nil +// } diff --git a/pkg/service/platform.go b/pkg/service/platform.go index 71999271..7e456f94 100644 --- a/pkg/service/platform.go +++ b/pkg/service/platform.go @@ -23,12 +23,13 @@ func NewPlatform(repos repository.Repositories) Platform { func (a platform) Create(c CreatePlatform) (model.Platform, error) { uuiKey := "str." + uuidWithoutHyphens() hashed := common.ToSha256(uuiKey) - m := model.Platform{ - Type: c.Type, - Authentication: c.Authentication, - ApiKey: hashed, - Status: "pending", - } + // m := model.Platform{ + // Type: c.Type, + // Authentication: c.Authentication, + // ApiKey: hashed, + // Status: "pending", + // } + m := model.Platform{} plat, err := a.repos.Platform.Create(m) if err != nil { @@ -37,7 +38,7 @@ func (a platform) Create(c CreatePlatform) (model.Platform, error) { _, err = a.repos.Auth.CreateAPIKey(plat.ID, c.Authentication, hashed, false) pt := &plat - pt.ApiKey = uuiKey + // pt.ApiKey = uuiKey if err != nil { return *pt, common.StringError(err) } diff --git a/scripts/data_seeding.go b/scripts/data_seeding.go index 805bfdf5..2dd9a52d 100644 --- a/scripts/data_seeding.go +++ b/scripts/data_seeding.go @@ -186,7 +186,8 @@ func DataSeeding() { // Platforms, placeholder /*platformDeveloper*/ - placeholderPlatform, err := repos.Platform.Create(model.Platform{Type: "Game", Status: "Verified", Name: "Nintendo", ApiKey: "Internal", Authentication: "Email"}) + placeholderPlatform, err := repos.Platform.Create(model.Platform{Name: "Nintendo", Description: "Fun"}) + if err != nil { panic(err) } @@ -377,7 +378,7 @@ func MockSeeding() { // Platforms, placeholder /*platformDeveloper*/ - placeholderPlatform, err := repos.Platform.Create(model.Platform{Type: "Game", Status: "Verified", Name: "Nintendo", ApiKey: "Internal", Authentication: "Email"}) + placeholderPlatform, err := repos.Platform.Create(model.Platform{Name: "Nintendo", Description: "Fun"}) if err != nil { panic(err) } From 4d8cef4e53121d9906e2271e212e6cd803f80dab Mon Sep 17 00:00:00 2001 From: Ocasta Date: Fri, 27 Jan 2023 12:36:26 -0600 Subject: [PATCH 11/17] remove mocks since we're not using it anymore --- entrypoint.sh | 3 --- migrations/mocks/0005_mocks.sql | 46 --------------------------------- 2 files changed, 49 deletions(-) delete mode 100644 migrations/mocks/0005_mocks.sql diff --git a/entrypoint.sh b/entrypoint.sh index 72b1a1fb..c630ff82 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -6,12 +6,9 @@ export $(grep -v '^#' .env | xargs) # run db migrations echo "----- Running migrations..." cd migrations -cd mocks DB_CONFIG="host=$DB_HOST user=$DB_USERNAME dbname=$DB_NAME sslmode=disable password=$DB_PASSWORD" goose postgres "$DB_CONFIG" reset -cd .. -goose postgres "$DB_CONFIG" reset goose postgres "$DB_CONFIG" up cd .. echo "----- ...Migrations done" diff --git a/migrations/mocks/0005_mocks.sql b/migrations/mocks/0005_mocks.sql deleted file mode 100644 index f8f199ca..00000000 --- a/migrations/mocks/0005_mocks.sql +++ /dev/null @@ -1,46 +0,0 @@ -------------------------------------------------------------------------- --- +goose Up -------------------------------------------------------------------------- --- STRING_USER ---------------------------------------------------------- -INSERT INTO string_user (id, created_at, updated_at, type, status, tags, first_name, last_name) -VALUES ('0e837b73-55cf-43ff-9b1e-0d8258eec978', '2022-10-19 00:17:01.837572+00', '2022-10-19 00:17:01.837572+00', 'Developer', 'Developing', '{}', 'Deve', 'Loper'); - -------------------------------------------------------------------------- --- DEVICE --------------------------------------------------------------- -INSERT INTO device (id, created_at, updated_at, last_used_at, validated_at, description, user_id) -VALUES ('073f5a88-9223-4554-a7ce-11d358123a21', '2022-10-19 00:23:10.405595+00', '2022-10-19 00:23:10.405595+00', '2022-10-19 00:17:01.837572+00', '2022-10-19 00:17:01.837572+00', 'Developer Laptop', '0e837b73-55cf-43ff-9b1e-0d8258eec978'); - -------------------------------------------------------------------------- --- INSTRUMENT ----------------------------------------------------------- -INSERT INTO instrument (id, created_at, updated_at, type, status, tags, network, public_key, last_4, user_id) -VALUES ('13438963-f5e7-47c4-a790-ebca3e3bf915', '2022-10-19 00:53:36.538289+00', '2022-10-19 00:53:36.538289+00', 'Credit Card', 'Ephemeral', '{}', 'Mastercard', '', '4242', '0e837b73-55cf-43ff-9b1e-0d8258eec978'), -('ab6a2d66-ad4c-43f4-adf9-c0cd3282492c', '2022-10-19 00:55:26.166175+00', '2022-10-19 00:55:26.166175+00', 'Crypto Wallet', 'Ephemeral', '{}', 'Ethereum', '0x44A4b9E2A69d86BA382a511f845CbF2E31286770', '', '0e837b73-55cf-43ff-9b1e-0d8258eec978'); - -------------------------------------------------------------------------- --- NETWORK -------------------------------------------------------------- -INSERT INTO network (id, created_at, updated_at, name, network_id, chain_id, gas_token_id, gas_oracle, rpc_url, explorer_url) -VALUES ('ea34e526-ec6e-4f2b-89b4-acc08db80d63', '2022-10-14 20:18:09.555645+00', '2022-10-14 20:18:09.555645+00', 'Fuji Testnet', '43113', '43113', '19611d0e-a42f-4cee-a35a-b34eb5c08a7f', 'avax', 'https://api.avax-test.network/ext/bc/C/rpc', 'https://testnet.snowtrace.io'), -('b21d6cd6-5d8a-49a6-bac6-e6323316dc01', '2022-10-14 20:41:39.962327+00', '2022-10-14 20:41:39.962327+00', 'Goerli Testnet', '5', '5', '3ef72571-c2e1-4ca3-991c-0df17cef7535', 'eth', 'https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161', 'https://goerli.etherscan.io'), -('6cea71b3-b287-4680-ad9d-e631d0bc84ba', '2022-10-14 20:41:39.962327+00', '2022-10-14 20:41:39.962327+00', 'Polygon Mainnet', '137', '137', 'c06986d8-cc2c-4cdc-9728-16a45698b3e7', 'poly', 'https://rpc-mainnet.matic.quiknode.pro', 'https://polygonscan.com'), -('cd42c066-554c-42ad-994b-48fed371931c', '2022-10-14 20:41:39.962327+00', '2022-10-14 20:41:39.962327+00', 'Avalanche Mainnet', '43114', '43114', '19611d0e-a42f-4cee-a35a-b34eb5c08a7f', 'avax', 'https://api.avax.network/ext/bc/C/rpc', 'https://snowtrace.io'), -('491d46e2-18e0-45ec-8209-faf0ec5d278c', '2022-10-14 20:41:39.962327+00', '2022-10-14 20:41:39.962327+00', 'Mumbai Testnet', '80001', '80001', 'c06986d8-cc2c-4cdc-9728-16a45698b3e7', 'poly', 'https://matic-mumbai.chainstacklabs.com', 'https://mumbai.polygonscan.com/'), -('60a02818-4e7d-4b84-b673-e2376fdbfbf9', '2022-10-14 20:41:39.962327+00', '2022-10-30 01:07:37.237054+00', 'Ethereum Mainnet', '1', '1', '3ef72571-c2e1-4ca3-991c-0df17cef7535', 'eth', 'https://rpc.ankr.com/eth', 'https://etherscan.io/'); - -------------------------------------------------------------------------- --- PLATFORM ------------------------------------------------------------- -INSERT INTO platform (id, created_at, updated_at, type, status, name, api_key, authentication) -VALUES ('54a7e062-4cec-44f3-9d89-99498d0eb6ef', '2022-10-19 00:37:16.965408+00', '2022-10-19 00:37:16.965408+00', 'Game', 'Verified', 'Nintendo', 'developer', 'email'); - -------------------------------------------------------------------------- --- ASSET ------------------------------------------------------------- -INSERT INTO asset (id, created_at, updated_at, name, description, decimals, is_crypto, network_id, value_oracle) -VALUES ('19611d0e-a42f-4cee-a35a-b34eb5c08a7f', '2022-10-14 20:17:06.460812+00', '2022-10-15 02:41:02.270712+00', 'AVAX', 'Avalanche', 18, TRUE, 'cd42c066-554c-42ad-994b-48fed371931c', 'avalanche-2'), -('c06986d8-cc2c-4cdc-9728-16a45698b3e7', '2022-10-14 20:17:06.460812+00', '2022-10-15 02:41:02.270712+00', 'MATIC', 'Matic', 18, TRUE, '6cea71b3-b287-4680-ad9d-e631d0bc84ba', 'matic-network'), -('3ef72571-c2e1-4ca3-991c-0df17cef7535', '2022-10-14 20:17:06.460812+00', '2022-10-15 02:41:02.270712+00', 'ETH', 'Ethereum', 18, TRUE, '60a02818-4e7d-4b84-b673-e2376fdbfbf9', 'ethereum'), -('bc376c3a-6481-49d0-83ef-34ba80937ba8', '2022-10-18 03:59:05.042924+00', '2022-10-18 03:59:05.042924+00', 'USD', 'United States Dollar', 6, FALSE, null, null); - - -------------------------------------------------------------------------- --- +goose Down - --- Can't delete rows due to foreign key constraint \ No newline at end of file From c0f9befda818adce9b235d98258e791fb1a84424 Mon Sep 17 00:00:00 2001 From: Sean Date: Fri, 27 Jan 2023 11:43:21 -0700 Subject: [PATCH 12/17] make goose happy --- ...form_contact-to-platform_device-to-instrument_platform.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql index 0efdc4bc..0568dda5 100644 --- a/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql +++ b/migrations/0005_user-to-platform_contact-to-platform_device-to-instrument_platform.sql @@ -57,8 +57,8 @@ ALTER TABLE platform DROP COLUMN IF EXISTS description, DROP COLUMN IF EXISTS domains, DROP COLUMN IF EXISTS ip_addresses, - ADD COLUMN type TEXT NOT NULL, -- enum: to be defined at struct level in Go - ADD COLUMN status TEXT NOT NULL, -- enum: to be defined at struct level in Go + ADD COLUMN type TEXT DEFAULT '', -- enum: to be defined at struct level in Go + ADD COLUMN status TEXT DEFAULT '', -- enum: to be defined at struct level in Go ADD COLUMN name TEXT DEFAULT '', ADD COLUMN api_key TEXT DEFAULT '', ADD COLUMN authentication TEXT DEFAULT ''; --enum [email, phone, wallet] From cb16928b0cd36dd1eeadbd2b2f3ab356850761cf Mon Sep 17 00:00:00 2001 From: Ocasta Date: Fri, 27 Jan 2023 12:46:24 -0600 Subject: [PATCH 13/17] rename to match many-to-many table names --- ... 0002_user-to-platform_device_contact_location_instrument.sql} | 0 ...ntact-to-platform_device-to-instrument_tx-leg_transaction.sql} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename migrations/{0002_user-platform_device_contact_location_instrument.sql => 0002_user-to-platform_device_contact_location_instrument.sql} (100%) rename migrations/{0003_contact-platform_device-instrument_tx-leg_transaction.sql => 0003_contact-to-platform_device-to-instrument_tx-leg_transaction.sql} (100%) diff --git a/migrations/0002_user-platform_device_contact_location_instrument.sql b/migrations/0002_user-to-platform_device_contact_location_instrument.sql similarity index 100% rename from migrations/0002_user-platform_device_contact_location_instrument.sql rename to migrations/0002_user-to-platform_device_contact_location_instrument.sql diff --git a/migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql b/migrations/0003_contact-to-platform_device-to-instrument_tx-leg_transaction.sql similarity index 100% rename from migrations/0003_contact-platform_device-instrument_tx-leg_transaction.sql rename to migrations/0003_contact-to-platform_device-to-instrument_tx-leg_transaction.sql From f6fbc96e13f797da1e1e89727add994f4a2852f8 Mon Sep 17 00:00:00 2001 From: Auroter <7332587+Auroter@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:25:59 -0700 Subject: [PATCH 14/17] Update pkg/repository/platform.go Co-authored-by: akfoster --- pkg/repository/platform.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/repository/platform.go b/pkg/repository/platform.go index f932da80..2bf6cc74 100644 --- a/pkg/repository/platform.go +++ b/pkg/repository/platform.go @@ -22,7 +22,6 @@ type Platform interface { GetById(ID string) (model.Platform, error) List(limit int, offset int) ([]model.Platform, error) Update(ID string, updates any) error - // GetByApiKey(key string) (model.Platform, error) } type platform[T any] struct { From 64571d16c7cabdc3862bf745bb01c8bd8ed16e69 Mon Sep 17 00:00:00 2001 From: Auroter <7332587+Auroter@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:26:14 -0700 Subject: [PATCH 15/17] Update pkg/repository/platform.go Co-authored-by: akfoster --- pkg/repository/platform.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pkg/repository/platform.go b/pkg/repository/platform.go index 2bf6cc74..8d21f93d 100644 --- a/pkg/repository/platform.go +++ b/pkg/repository/platform.go @@ -52,13 +52,3 @@ func (p platform[T]) Create(m model.Platform) (model.Platform, error) { return plat, nil } -// func (p platform[T]) GetByApiKey(key string) (model.Platform, error) { -// m := model.Platform{} -// err := p.store.Get(&m, fmt.Sprintf("SELECT * FROM %s WHERE api_key = $1", p.table), key) -// if err != nil && err == sql.ErrNoRows { -// return m, common.StringError(ErrNotFound) -// } else if err != nil { -// return m, common.StringError(err) -// } -// return m, nil -// } From 5b9896f72479c20fdd6ac31c31efc022170e6962 Mon Sep 17 00:00:00 2001 From: Auroter <7332587+Auroter@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:26:23 -0700 Subject: [PATCH 16/17] Update pkg/service/platform.go Co-authored-by: akfoster --- pkg/service/platform.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/pkg/service/platform.go b/pkg/service/platform.go index 7e456f94..255ae2c7 100644 --- a/pkg/service/platform.go +++ b/pkg/service/platform.go @@ -23,12 +23,6 @@ func NewPlatform(repos repository.Repositories) Platform { func (a platform) Create(c CreatePlatform) (model.Platform, error) { uuiKey := "str." + uuidWithoutHyphens() hashed := common.ToSha256(uuiKey) - // m := model.Platform{ - // Type: c.Type, - // Authentication: c.Authentication, - // ApiKey: hashed, - // Status: "pending", - // } m := model.Platform{} plat, err := a.repos.Platform.Create(m) From a113ec39a23ccbb92596489016da459ba2b1ab0a Mon Sep 17 00:00:00 2001 From: Auroter <7332587+Auroter@users.noreply.github.com> Date: Fri, 27 Jan 2023 12:26:31 -0700 Subject: [PATCH 17/17] Update pkg/service/platform.go Co-authored-by: akfoster --- pkg/service/platform.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/service/platform.go b/pkg/service/platform.go index 255ae2c7..aae5753f 100644 --- a/pkg/service/platform.go +++ b/pkg/service/platform.go @@ -32,7 +32,6 @@ func (a platform) Create(c CreatePlatform) (model.Platform, error) { _, err = a.repos.Auth.CreateAPIKey(plat.ID, c.Authentication, hashed, false) pt := &plat - // pt.ApiKey = uuiKey if err != nil { return *pt, common.StringError(err) }