shortlinks fix

This commit is contained in:
Sergey Chubaryan 2025-02-23 16:34:24 +03:00
parent 00b8636b5a
commit f490d45300
3 changed files with 5 additions and 20 deletions

View File

@ -35,8 +35,8 @@ func (u *shortlinkRepo) AddShortlink(ctx context.Context, dto ShortlinkDTO) erro
_, span := u.tracer.Start(ctx, "postgres::AddShortlink")
defer span.End()
query := `insert into shortlinks (url, expires_at) values ($1, $2);`
_, err := u.db.ExecContext(ctx, query, dto.Url, dto.ExpiresAt)
query := `insert into shortlinks (id, url, expires_at) values ($1, $2, $3);`
_, err := u.db.ExecContext(ctx, query, dto.Id, dto.Url, dto.ExpiresAt)
return err
}
@ -72,7 +72,7 @@ func (u *shortlinkRepo) DeleteExpiredShortlinks(ctx context.Context, limit int)
where id in (
select id
from shortlinks
where current_date > expiration
where current_date > expires_at
limit $1
)
returning *

View File

@ -9,8 +9,6 @@ create table if not exists users (
updated_at timestamp
);
alter table users alter column active set default true;
create index if not exists idx_users_email on users(email);
create or replace trigger trg_user_created

View File

@ -1,18 +1,5 @@
create table if not exists shortlinks (
id int generated always as identity,
id text primary key,
url text not null,
expires_at timestamp not null,
created_at timestamp,
updated_at timestamp
expires_at timestamp not null
);
create or replace trigger trg_shortlink_created
before insert on shortlinks
for each row
execute function trg_proc_row_created();
create or replace trigger trg_shortlink_updated
before update on shortlinks
for each row
when (new is distinct from old)
execute function trg_proc_row_updated();