Skip to content

Task/sean/str 385 #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
11 changes: 9 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ services:
ports:
- 5555:5555
depends_on:
- db
- redis
redis:
condition: service_started
db:
condition: service_healthy
volumes:
- ./:/string_api
db:
Expand All @@ -22,6 +24,11 @@ services:
- '5432:5432'
volumes:
- db:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U string_db"]
interval: 5s
timeout: 5s
retries: 5
redis:
image: redis:7.0-alpine
restart: always
Expand Down
3 changes: 0 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 16 additions & 16 deletions migrations/0001_string-user_platform_asset_network.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

-------------------------------------------------------------------------
Expand All @@ -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();

-------------------------------------------------------------------------
Expand All @@ -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();

-------------------------------------------------------------------------
Expand All @@ -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);
Expand All @@ -121,7 +121,7 @@ DROP TABLE IF EXISTS network;

-------------------------------------------------------------------------
-- PLATFORM -------------------------------------------------------------
DROP TRIGGER IF EXISTS update_platform_updated_at ON platfom;
DROP TRIGGER IF EXISTS update_platform_updated_at ON platform;
DROP TABLE IF EXISTS platform;

-------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

-------------------------------------------------------------------------
Expand All @@ -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();

-------------------------------------------------------------------------
Expand All @@ -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();

-------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

-------------------------------------------------------------------------
Expand Down Expand Up @@ -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();

-------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions migrations/0004_auth_key.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
-------------------------------------------------------------------------
-- +goose Up

-------------------------------------------------------------------------
-- USER_TO_PLATFORM -----------------------------------------------------
ALTER TABLE user_platform
RENAME TO user_to_platform;

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);


-------------------------------------------------------------------------
-- CONTACT_TO_PLATFORM --------------------------------------------------
ALTER TABLE contact_platform
RENAME TO contact_to_platform;

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);


-------------------------------------------------------------------------
-- DEVICE_TO_INSTRUMENT -------------------------------------------------
ALTER TABLE device_instrument
RENAME TO device_to_instrument;

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);


-------------------------------------------------------------------------
-- 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 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]


-------------------------------------------------------------------------
-- USER_PLATFORM -----------------------------------------------------
ALTER TABLE user_to_platform
RENAME TO user_platform;

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);


-------------------------------------------------------------------------
-- CONTACT_PLATFORM --------------------------------------------------
ALTER TABLE contact_to_platform
RENAME TO contact_platform;

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);


-------------------------------------------------------------------------
-- DEVICE_INSTRUMENT -------------------------------------------------
ALTER TABLE device_to_instrument
RENAME TO device_instrument;

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);
Loading