Skip to content
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

migrate all timestamp columns to timestamptz (timezone aware) #54

Merged
merged 2 commits into from
Jun 25, 2024
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
2 changes: 2 additions & 0 deletions server/data/helper_party_api_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export async function validateApiKey(
key: string,
): Promise<boolean> {
const supabase = await createSupabaseServiceClient();
// toISOString() always and only returns UTC timestamps
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
const currentTimestamp = new Date().toISOString();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may want to refactor this later to be able to unit test the expiration

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also add an already expired key to seed.sql for that test. it's a good test to add

const { data, error } = await supabase
.from("helper_party_api_keys")
Expand Down
17 changes: 17 additions & 0 deletions server/supabase/migrations/20240621172426_timestamptz.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
alter table queries alter created_at type timestamptz using created_at at time zone 'utc';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to make sure - do we generate the timestamp on DB side for all of these columns during insert/update?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep!

alter table queries alter started_at type timestamptz using started_at at time zone 'utc';
alter table queries alter ended_at type timestamptz using ended_at at time zone 'utc';

alter table helper_parties alter created_at type timestamptz using created_at at time zone 'utc';
alter table helper_parties alter modified_at type timestamptz using modified_at at time zone 'utc';

alter table helper_party_networks alter created_at type timestamptz using created_at at time zone 'utc';
alter table helper_party_networks alter modified_at type timestamptz using modified_at at time zone 'utc';

alter table helper_party_network_members alter created_at type timestamptz using created_at at time zone 'utc';

alter table helper_party_query_status_updates alter started_at type timestamptz using started_at at time zone 'utc';

alter table helper_party_api_keys alter created_at type timestamptz using created_at at time zone 'utc';
alter table helper_party_api_keys alter expires_at type timestamptz using expires_at at time zone 'utc';
alter table helper_party_api_keys alter modified_at type timestamptz using modified_at at time zone 'utc';
Loading