Skip to content

Commit

Permalink
Add inserted_at for packages
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Oct 16, 2024
1 parent ec0d115 commit 89d3cf8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ COPY packages /packages

RUN cd /build/backend && gleam export erlang-shipment

FROM --platform=x86_64 ghcr.io/gleam-lang/gleam:v1.4.0-erlang-alpine AS runner
FROM --platform=x86_64 ghcr.io/gleam-lang/gleam:v1.4.1-erlang-alpine AS runner
LABEL org.opencontainers.image.source=https://github.com/ghivert/gloogle

RUN apk add build-base ca-certificates inotify-tools
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- migrate:up
alter table package_release add column inserted_at timestamp;

-- migrate:down
alter table package_release drop column inserted_at;
6 changes: 4 additions & 2 deletions apps/backend/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ CREATE TABLE public.package_release (
updated_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
package_interface text,
gleam_toml text,
retirement jsonb
retirement jsonb,
inserted_at timestamp without time zone
);


Expand Down Expand Up @@ -611,4 +612,5 @@ INSERT INTO public.schema_migrations (version) VALUES
('20240801211520'),
('20240801220817'),
('20240902224247'),
('20240902225236');
('20240902225236'),
('20241016151324');
22 changes: 18 additions & 4 deletions apps/backend/src/backend/postgres/queries.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,33 @@ pub fn upsert_release(
let url = pgo.text(release.url)
let package_interface = pgo.nullable(pgo.text, package_interface)
let gleam_toml = pgo.nullable(pgo.text, gleam_toml)
let args = [package_id, version, url, package_interface, gleam_toml]
let inserted_at =
release.inserted_at
|> birl.to_erlang_universal_datetime
|> dynamic.from
|> dynamic.unsafe_coerce
let args = [
package_id,
version,
url,
package_interface,
gleam_toml,
inserted_at,
]
"INSERT INTO package_release (
package_id,
version,
url,
package_interface,
gleam_toml
) VALUES ($1, $2, $3, $4, $5)
gleam_toml,
inserted_at
) VALUES ($1, $2, $3, $4, $5, $6)
ON CONFLICT (package_id, version) DO UPDATE
SET
url = $3,
package_interface = $4,
gleam_toml = $5
gleam_toml = $5,
inserted_at = $6
RETURNING id, package_interface, gleam_toml"
|> pgo.execute(
db,
Expand Down

0 comments on commit 89d3cf8

Please sign in to comment.