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

migration for constraints and defaults #246

Merged
merged 2 commits into from
Apr 13, 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
23 changes: 23 additions & 0 deletions trunk/trunk-registry/migrations/20230413123400_versions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- several records already exist with null values
UPDATE versions SET updated_at = (NOW() at time zone 'UTC') WHERE updated_at IS NULL;
UPDATE versions SET created_at = (NOW() at time zone 'UTC') WHERE created_at IS NULL;

UPDATE extensions SET updated_at = (NOW() at time zone 'UTC') WHERE updated_at IS NULL;
UPDATE extensions SET created_at = (NOW() at time zone 'UTC') WHERE created_at IS NULL;

-- put not null constraints on timestamp columns, at utc defaulting to current time
ALTER TABLE versions
ALTER COLUMN updated_at TYPE timestamp with time zone USING updated_at AT TIME ZONE 'UTC',
ALTER COLUMN updated_at SET DEFAULT (now() at time zone 'UTC'),
ALTER COLUMN updated_at SET NOT NULL,
ALTER COLUMN created_at TYPE timestamp with time zone USING created_at AT TIME ZONE 'UTC',
ALTER COLUMN created_at SET NOT NULL,
ALTER COLUMN created_at SET DEFAULT (now() at time zone 'UTC');

ALTER TABLE extensions
ALTER COLUMN updated_at TYPE timestamp with time zone USING updated_at AT TIME ZONE 'UTC',
ALTER COLUMN updated_at SET DEFAULT (now() at time zone 'UTC'),
ALTER COLUMN updated_at SET NOT NULL,
ALTER COLUMN created_at TYPE timestamp with time zone USING created_at AT TIME ZONE 'UTC',
ALTER COLUMN created_at SET NOT NULL,
ALTER COLUMN created_at SET DEFAULT (now() at time zone 'UTC');
24 changes: 12 additions & 12 deletions trunk/trunk-registry/sqlx-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
{
"name": "updated_at",
"ordinal": 2,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "created_at",
"ordinal": 3,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "downloads",
Expand Down Expand Up @@ -52,8 +52,8 @@
"nullable": [
false,
true,
true,
true,
false,
false,
true,
true,
true,
Expand Down Expand Up @@ -82,12 +82,12 @@
{
"name": "updated_at",
"ordinal": 2,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "created_at",
"ordinal": 3,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "downloads",
Expand Down Expand Up @@ -118,8 +118,8 @@
"nullable": [
false,
true,
true,
true,
false,
false,
true,
true,
true,
Expand Down Expand Up @@ -215,12 +215,12 @@
{
"name": "updated_at",
"ordinal": 3,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "created_at",
"ordinal": 4,
"type_info": "Timestamp"
"type_info": "Timestamptz"
},
{
"name": "downloads",
Expand Down Expand Up @@ -267,8 +267,8 @@
false,
true,
true,
true,
true,
false,
false,
true,
true,
true,
Expand Down
4 changes: 2 additions & 2 deletions trunk/trunk-registry/src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub async fn get_all_extensions(
{
"name": row.name.to_owned(),
"latestVersion": latest,
"createdAt": row.created_at.unwrap().to_string(),
"updatedAt": row.updated_at.unwrap().to_string(),
"createdAt": row.created_at.to_string(),
"updatedAt": row.updated_at.to_string(),
Comment on lines +31 to +32
Copy link
Member Author

Choose a reason for hiding this comment

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

these columns are now not null

"description": row.description.to_owned(),
"homepage": row.homepage.to_owned(),
"documentation": row.documentation.to_owned(),
Expand Down