Skip to content

Commit

Permalink
chore(backend): remove latest version
Browse files Browse the repository at this point in the history
- remove `latest_version` column from postgres schema
- remove all references of latest version from code
  • Loading branch information
detj committed Dec 14, 2023
1 parent edf8e04 commit 0bf056d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 52 deletions.
48 changes: 15 additions & 33 deletions measure-backend/measure-go/measure/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ select
apps.unique_identifier,
apps.platform,
apps.first_version,
apps.latest_version,
apps.first_seen_at,
apps.onboarded,
apps.onboarded_at,
Expand All @@ -41,19 +40,18 @@ where apps.id = $1 and apps.team_id = $2;
`

type App struct {
ID *uuid.UUID `json:"id"`
TeamId uuid.UUID `json:"team_id"`
AppName string `json:"name" binding:"required"`
UniqueId string `json:"unique_identifier"`
Platform string `json:"platform"`
APIKey *APIKey `json:"api_key"`
firstVersion string `json:"first_version"`
latestVersion string `json:"latest_version"`
firstSeenAt time.Time `json:"first_seen_at"`
Onboarded bool `json:"onboarded"`
OnboardedAt time.Time `json:"onboarded_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ID *uuid.UUID `json:"id"`
TeamId uuid.UUID `json:"team_id"`
AppName string `json:"name" binding:"required"`
UniqueId string `json:"unique_identifier"`
Platform string `json:"platform"`
APIKey *APIKey `json:"api_key"`
firstVersion string `json:"first_version"`
firstSeenAt time.Time `json:"first_seen_at"`
Onboarded bool `json:"onboarded"`
OnboardedAt time.Time `json:"onboarded_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

func (a App) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -136,19 +134,17 @@ func (a *App) get() (*App, error) {
var uniqueId pgtype.Text
var platform pgtype.Text
var firstVersion pgtype.Text
var latestVersion pgtype.Text

stmt := sqlf.PostgreSQL.
Select("onboarded", nil).
Select("unique_identifier", nil).
Select("platform", nil).
Select("first_version", nil).
Select("latest_version", nil).
From("apps").
Where("id = ?", nil)
defer stmt.Close()

if err := server.Server.PgPool.QueryRow(context.Background(), stmt.String(), a.ID).Scan(&onboarded, &uniqueId, &platform, &firstVersion, &latestVersion); err != nil {
if err := server.Server.PgPool.QueryRow(context.Background(), stmt.String(), a.ID).Scan(&onboarded, &uniqueId, &platform, &firstVersion); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, nil
} else {
Expand All @@ -174,12 +170,6 @@ func (a *App) get() (*App, error) {
a.firstVersion = ""
}

if latestVersion.Valid {
a.latestVersion = latestVersion.String
} else {
a.latestVersion = ""
}

return a, nil
}

Expand All @@ -188,7 +178,6 @@ func (a *App) getWithTeam(id uuid.UUID) (*App, error) {
var uniqueId pgtype.Text
var platform pgtype.Text
var firstVersion pgtype.Text
var latestVersion pgtype.Text
var firstSeenAt pgtype.Timestamptz
var onboarded pgtype.Bool
var onboardedAt pgtype.Timestamptz
Expand All @@ -199,7 +188,7 @@ func (a *App) getWithTeam(id uuid.UUID) (*App, error) {

apiKey := new(APIKey)

if err := server.Server.PgPool.QueryRow(context.Background(), queryGetApp, id, a.TeamId).Scan(&appName, &uniqueId, &platform, &firstVersion, &latestVersion, &firstSeenAt, &onboarded, &onboardedAt, &apiKey.keyPrefix, &apiKey.keyValue, &apiKey.checksum, &apiKeyLastSeen, &apiKeyCreatedAt, &createdAt, &updatedAt); err != nil {
if err := server.Server.PgPool.QueryRow(context.Background(), queryGetApp, id, a.TeamId).Scan(&appName, &uniqueId, &platform, &firstVersion, &firstSeenAt, &onboarded, &onboardedAt, &apiKey.keyPrefix, &apiKey.keyValue, &apiKey.checksum, &apiKeyLastSeen, &apiKeyCreatedAt, &createdAt, &updatedAt); err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return nil, nil
} else {
Expand Down Expand Up @@ -233,12 +222,6 @@ func (a *App) getWithTeam(id uuid.UUID) (*App, error) {
a.Onboarded = onboarded.Bool
}

if latestVersion.Valid {
a.latestVersion = latestVersion.String
} else {
a.latestVersion = ""
}

if firstSeenAt.Valid {
a.firstSeenAt = firstSeenAt.Time
}
Expand Down Expand Up @@ -275,14 +258,13 @@ func (a *App) Onboard(tx pgx.Tx, uniqueIdentifier, platform, firstVersion string
Set("unique_identifier", nil).
Set("platform", nil).
Set("first_version", nil).
Set("latest_version", nil).
Set("first_seen_at", nil).
Set("updated_at", nil).
Where("id = ?", nil)

defer stmt.Close()

_, err := tx.Exec(context.Background(), stmt.String(), true, uniqueIdentifier, platform, firstVersion, firstVersion, now, now, a.ID)
_, err := tx.Exec(context.Background(), stmt.String(), true, uniqueIdentifier, platform, firstVersion, now, now, a.ID)
if err != nil {
return err
}
Expand Down
10 changes: 1 addition & 9 deletions measure-backend/measure-go/measure/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ select
apps.unique_identifier,
apps.platform,
apps.first_version,
apps.latest_version,
apps.first_seen_at,
apps.onboarded,
apps.onboarded_at,
Expand Down Expand Up @@ -88,15 +87,14 @@ func (t *Team) getApps() ([]App, error) {
var uniqueId pgtype.Text
var platform pgtype.Text
var firstVersion pgtype.Text
var latestVersion pgtype.Text
var firstSeenAt pgtype.Timestamptz
var onboardedAt pgtype.Timestamptz
var apiKeyLastSeen pgtype.Timestamptz
var apiKeyCreatedAt pgtype.Timestamptz

apiKey := new(APIKey)

if err := rows.Scan(&a.ID, &a.AppName, &a.TeamId, &uniqueId, &platform, &firstVersion, &latestVersion, &firstSeenAt, &a.Onboarded, &onboardedAt, &apiKey.keyPrefix, &apiKey.keyValue, &apiKey.checksum, &apiKeyLastSeen, &apiKeyCreatedAt, &a.CreatedAt, &a.UpdatedAt); err != nil {
if err := rows.Scan(&a.ID, &a.AppName, &a.TeamId, &uniqueId, &platform, &firstVersion, &firstSeenAt, &a.Onboarded, &onboardedAt, &apiKey.keyPrefix, &apiKey.keyValue, &apiKey.checksum, &apiKeyLastSeen, &apiKeyCreatedAt, &a.CreatedAt, &a.UpdatedAt); err != nil {
return nil, err
}

Expand All @@ -118,12 +116,6 @@ func (t *Team) getApps() ([]App, error) {
a.firstVersion = ""
}

if latestVersion.Valid {
a.latestVersion = latestVersion.String
} else {
a.latestVersion = ""
}

if firstSeenAt.Valid {
a.firstSeenAt = firstSeenAt.Time
}
Expand Down
2 changes: 0 additions & 2 deletions self-host/postgres/20231117010526_create-apps-relation.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ create table if not exists public.apps (
app_name varchar(512),
platform varchar(256) check (platform in ('ios', 'android', 'flutter', 'react-native', 'unity')),
first_version varchar(128),
latest_version varchar(128),
first_seen_at timestamptz,
onboarded boolean default false,
onboarded_at timestamptz,
Expand All @@ -20,7 +19,6 @@ comment on column public.apps.unique_identifier is 'unique id lingua franca to a
comment on column public.apps.app_name is 'name of app lingua franca to app creator';
comment on column public.apps.platform is 'platform of the app, like iOS, Android, Flutter';
comment on column public.apps.first_version is 'first version of the app as per ingested sessions from it';
comment on column public.apps.latest_version is 'latest version of the app as per ingested sessions from it';
comment on column public.apps.first_seen_at is 'utc timestamp as per the nascent ingested session';
comment on column public.apps.onboarded is 'app is considered onboarded once it receives the first session';
comment on column public.apps.onboarded_at is 'utc timestamp at the time of receiving first session';
Expand Down
8 changes: 0 additions & 8 deletions self-host/postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ CREATE TABLE public.apps (
app_name character varying(512),
platform character varying(256),
first_version character varying(128),
latest_version character varying(128),
first_seen_at timestamp with time zone,
onboarded boolean DEFAULT false,
onboarded_at timestamp with time zone,
Expand Down Expand Up @@ -225,13 +224,6 @@ COMMENT ON COLUMN public.apps.platform IS 'platform of the app, like iOS, Androi
COMMENT ON COLUMN public.apps.first_version IS 'first version of the app as per ingested sessions from it';


--
-- Name: COLUMN apps.latest_version; Type: COMMENT; Schema: public; Owner: -
--

COMMENT ON COLUMN public.apps.latest_version IS 'latest version of the app as per ingested sessions from it';


--
-- Name: COLUMN apps.first_seen_at; Type: COMMENT; Schema: public; Owner: -
--
Expand Down

0 comments on commit 0bf056d

Please sign in to comment.