Skip to content

Commit

Permalink
Remove deprecated timezone property
Browse files Browse the repository at this point in the history
  • Loading branch information
aaricdev committed Dec 16, 2023
1 parent bd2c989 commit 8c24ee0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 48 deletions.
6 changes: 3 additions & 3 deletions internal/database/_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ create table stream_schedule(
id text not null primary key,
broadcaster_id text not null,
starttime text not null,
endtime text not null,
timezone text not null,
is_vacation boolean not null default false,
endtime text not null,
timezone text not null,
is_vacation boolean not null default false,
is_recurring boolean not null default false,
is_canceled boolean not null default false,
title text,
Expand Down
8 changes: 6 additions & 2 deletions internal/database/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/jmoiron/sqlx"
)

const currentVersion = 6
const currentVersion = 7

type migrateMap struct {
SQL string
Expand Down Expand Up @@ -53,6 +53,10 @@ ALTER TABLE users ADD COLUMN content_labels text not null default '';`,
SQL: `DROP TABLE IF EXISTS stream_tags;`,
Message: `Removing deprecated stream_tags from database.`,
},
7: {
SQL: `ALTER TABLE stream_schedule DROP COLUMN timezone;`,
Message: `Removing deprecated stream_schedule.timezone from database`,
},
}

func checkAndUpdate(db sqlx.DB) error {
Expand Down Expand Up @@ -120,7 +124,7 @@ create table predictions ( id text not null primary key, broadcaster_id text not
create table prediction_outcomes ( id text not null primary key, title text not null, users int not null default 0, channel_points int not null default 0, color text not null, prediction_id text not null, foreign key (prediction_id) references predictions(id) );
create table prediction_predictions ( prediction_id text not null, user_id text not null, amount int not null, outcome_id text not null, primary key(prediction_id, user_id), foreign key(user_id) references users(id), foreign key(prediction_id) references predictions(id), foreign key(outcome_id) references prediction_outcomes(id) );
create table clips ( id text not null primary key, broadcaster_id text not null, creator_id text not null, video_id text not null, game_id text not null, title text not null, view_count int default 0, created_at text not null, duration real not null, vod_offset int default 0, foreign key (broadcaster_id) references users(id), foreign key (creator_id) references users(id) );
create table stream_schedule( id text not null primary key, broadcaster_id text not null, starttime text not null, endtime text not null, timezone text not null, is_vacation boolean not null default false, is_recurring boolean not null default false, is_canceled boolean not null default false, title text, category_id text, foreign key(broadcaster_id) references users(id), foreign key (category_id) references categories(id));
create table stream_schedule( id text not null primary key, broadcaster_id text not null, starttime text not null, endtime text not null, is_vacation boolean not null default false, is_recurring boolean not null default false, is_canceled boolean not null default false, title text, category_id text, foreign key(broadcaster_id) references users(id), foreign key (category_id) references categories(id));
create table chat_settings( broadcaster_id text not null primary key, slow_mode boolean not null default 0, slow_mode_wait_time int not null default 10, follower_mode boolean not null default 0, follower_mode_duration int not null default 60, subscriber_mode boolean not null default 0, emote_mode boolean not null default 0, unique_chat_mode boolean not null default 0, non_moderator_chat_delay boolean not null default 0, non_moderator_chat_delay_duration int not null default 10, shieldmode_is_active boolean not null default 0, shieldmode_moderator_id text not null default '', shieldmode_moderator_login text not null default '', shieldmode_moderator_name text not null default '', shieldmode_last_activated text not null default '' );
create table vips ( broadcaster_id text not null, user_id text not null, created_at text not null default '', primary key (broadcaster_id, user_id), foreign key (broadcaster_id) references users(id), foreign key (user_id) references users(id) );`

Expand Down
1 change: 0 additions & 1 deletion internal/database/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type ScheduleSegment struct {
IsVacation bool `db:"is_vacation" json:"-"`
Category *SegmentCategory `json:"category"`
UserID string `db:"broadcaster_id" json:"-"`
Timezone string `db:"timezone" json:"timezone,omitempty"`
CategoryID *string `db:"category_id" json:"-"`
CategoryName *string `db:"category_name" dbi:"false" json:"-"`
IsCanceled *bool `db:"is_canceled" json:"-"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func TestSegment(t *testing.T) {
// post tests
body := SegmentPatchAndPostBody{
Title: "hello",
Timezone: "America/Los_Angeles",
StartTime: time.Now().Format(time.RFC3339),
IsRecurring: &tr,
Duration: "60",
Expand Down Expand Up @@ -167,7 +166,6 @@ func TestSegment(t *testing.T) {
a.Equal(401, resp.StatusCode)

body.Title = "testing"
body.Timezone = ""
b, _ = json.Marshal(body)
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
q.Set("broadcaster_id", "1")
Expand All @@ -176,7 +174,6 @@ func TestSegment(t *testing.T) {
a.Nil(err)
a.Equal(400, resp.StatusCode)

body.Timezone = "test"
b, _ = json.Marshal(body)
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
q.Set("broadcaster_id", "1")
Expand All @@ -185,7 +182,6 @@ func TestSegment(t *testing.T) {
a.Nil(err)
a.Equal(400, resp.StatusCode)

body.Timezone = segment.Timezone
body.IsRecurring = nil
b, _ = json.Marshal(body)
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
Expand Down
37 changes: 0 additions & 37 deletions internal/mock_api/endpoints/schedule/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type ScheduleSegment struct{}

type SegmentPatchAndPostBody struct {
StartTime string `json:"start_time"`
Timezone string `json:"timezone"`
IsRecurring *bool `json:"is_recurring"`
Duration string `json:"duration"`
CategoryID *string `json:"category_id"`
Expand Down Expand Up @@ -96,15 +95,6 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
mock_errors.WriteBadRequest(w, "Invalid/malformed start_time provided")
return
}
if body.Timezone == "" {
mock_errors.WriteBadRequest(w, "Missing timezone")
return
}
_, err = time.LoadLocation(body.Timezone)
if err != nil {
mock_errors.WriteBadRequest(w, "Invalid timezone provided")
return
}

var isRecurring bool

Expand Down Expand Up @@ -139,7 +129,6 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
CategoryID: body.CategoryID,
Title: body.Title,
UserID: userCtx.UserID,
Timezone: "America/Los_Angeles",
IsCanceled: &f,
}
err = db.NewQuery(nil, 100).InsertSchedule(segment)
Expand All @@ -164,7 +153,6 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
CategoryID: body.CategoryID,
Title: body.Title,
UserID: userCtx.UserID,
Timezone: body.Timezone,
IsCanceled: &f,
}

Expand All @@ -182,11 +170,6 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
}
b := dbr.Data.(database.Schedule)

// Remove timezone from JSON given in response
for i := range b.Segments {
b.Segments[i].Timezone = ""
}

if b.Vacation.StartTime == "" && b.Vacation.EndTime == "" {
b.Vacation = nil
}
Expand Down Expand Up @@ -266,20 +249,6 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
}
}

// timezone
tz, err := time.LoadLocation(segment.Timezone)
if err != nil {
mock_errors.WriteServerError(w, err.Error())
return
}
if body.Timezone != "" {
tz, err = time.LoadLocation(body.Timezone)
if err != nil {
mock_errors.WriteBadRequest(w, "Error parsing timezone")
return
}
}

// is_canceled
isCanceled := false
if body.IsCanceled != nil {
Expand Down Expand Up @@ -317,7 +286,6 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
StartTime: st.UTC().Format(time.RFC3339),
EndTime: et.UTC().Format(time.RFC3339),
IsCanceled: &isCanceled,
Timezone: tz.String(),
Title: title,
}

Expand All @@ -334,11 +302,6 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
}
b = dbr.Data.(database.Schedule)

// Remove timezone from JSON given in response
for i := range b.Segments {
b.Segments[i].Timezone = ""
}

if b.Vacation.StartTime == "" && b.Vacation.EndTime == "" {
b.Vacation = nil
}
Expand Down
1 change: 0 additions & 1 deletion internal/mock_api/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ func generateUsers(ctx context.Context, count int) error {
CategoryID: &dropsGameID,
Title: "Test Title",
UserID: broadcaster.ID,
Timezone: "America/Los_Angeles",
IsCanceled: &f,
}

Expand Down

0 comments on commit 8c24ee0

Please sign in to comment.