Skip to content
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
20 changes: 20 additions & 0 deletions db/migrations/9_timestamp.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ALTER TABLE IF EXISTS ONLY "workspaces" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "workspaces" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "sources" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "sources" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "plugins" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "plugins" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "events" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "events" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "endpoints" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "endpoints" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "attempts" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "attempts" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';

ALTER TABLE IF EXISTS ONLY "attempt_details" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
ALTER TABLE IF EXISTS ONLY "attempt_details" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3) AT TIME ZONE 'UTC';
20 changes: 20 additions & 0 deletions db/migrations/9_timestamp.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ALTER TABLE IF EXISTS ONLY "workspaces" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "workspaces" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "sources" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "sources" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "plugins" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "plugins" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "events" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "events" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "endpoints" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "endpoints" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "attempts" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "attempts" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);

ALTER TABLE IF EXISTS ONLY "attempt_details" ALTER COLUMN "created_at" SET DEFAULT CURRENT_TIMESTAMP(3);
ALTER TABLE IF EXISTS ONLY "attempt_details" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP(3);
6 changes: 6 additions & 0 deletions test/admin/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/webhookx-io/webhookx/db/entities"
"github.com/webhookx-io/webhookx/test/helper"
"github.com/webhookx-io/webhookx/utils"
"time"
)

var _ = Describe("/endpoints", Ordered, func() {
Expand Down Expand Up @@ -39,6 +40,7 @@ var _ = Describe("/endpoints", Ordered, func() {

Context("POST", func() {
It("creates an endpoint", func() {
now := time.Now()
resp, err := adminClient.R().
SetBody(map[string]interface{}{
"request": map[string]interface{}{
Expand Down Expand Up @@ -66,6 +68,10 @@ var _ = Describe("/endpoints", Ordered, func() {
e, err := db.Endpoints.Get(context.TODO(), result.ID)
assert.Nil(GinkgoT(), err)
assert.NotNil(GinkgoT(), e)

assert.True(GinkgoT(), now.UnixMilli() <= e.UpdatedAt.UnixMilli())
assert.True(GinkgoT(), now.UnixMilli() <= e.UpdatedAt.UnixMilli())
assert.Equal(GinkgoT(), e.CreatedAt, e.UpdatedAt)
})

Context("errors", func() {
Expand Down