no more cur versions table
parent
a2d1d17e23
commit
61349beb85
|
|
@ -52,13 +52,6 @@ func initDB(ctx context.Context) error {
|
|||
`ALTER TABLE "feed.versions" ADD COLUMN url TEXT NOT NULL`,
|
||||
`ALTER TABLE "feed.versions" ADD COLUMN cron TEXT NOT NULL DEFAULT '0 0 * * *'`,
|
||||
|
||||
`CREATE TABLE "feed.current_versions" (
|
||||
entries_id TEXT NOT NULL,
|
||||
versions_created_at TIMESTAMP NOT NULL,
|
||||
updated_at TIMESTAMP NOT NULL,
|
||||
FOREIGN KEY (entries_id, versions_created_at) REFERENCES "feed.versions" (entries_id, created_at)
|
||||
)`,
|
||||
|
||||
`CREATE TABLE "feed.executions" (
|
||||
entries_id TEXT,
|
||||
versions_created_at TIMESTAMP NOT NULL,
|
||||
|
|
@ -107,6 +100,43 @@ type (
|
|||
)
|
||||
|
||||
func (f *Feeds) Get(ctx context.Context, id string) (Feed, error) {
|
||||
return db.QueryOne[Feed](ctx, `
|
||||
WITH entry AS (
|
||||
SELECT
|
||||
id AS ID,
|
||||
created_at AS Created,
|
||||
updated_at AS Updated,
|
||||
deleted_at AS Deleted
|
||||
FROM "feed.entries"
|
||||
WHERE id = ?
|
||||
), WITH version AS (
|
||||
SELECT
|
||||
TODO
|
||||
FROM "feed.versions"
|
||||
), WITH execution AS (
|
||||
SELECT
|
||||
TODO
|
||||
FROM "feed.executions"
|
||||
WHERE entries_id = ?
|
||||
ORDER BY executed DESC
|
||||
LIMIT 1
|
||||
)
|
||||
SELECT
|
||||
entry.ID AS "Entry.ID",
|
||||
entry.Created AS "Entry.Created",
|
||||
entry.Updated AS "Entry.Updated",
|
||||
entry.Deleted AS "Entry.Deleted",
|
||||
version.Created AS "Version.Created",
|
||||
version.URL AS "Version.URL",
|
||||
version.Cron AS "Version.Cron",
|
||||
execution.Executed AS "",
|
||||
FROM entry
|
||||
FROM version
|
||||
FROM execution
|
||||
`)
|
||||
}
|
||||
|
||||
func (f *Feeds) oldGet(ctx context.Context, id string) (Feed, error) {
|
||||
entry, err := f.getEntry(ctx, id)
|
||||
if err != nil {
|
||||
return Feed{}, err
|
||||
|
|
|
|||
Loading…
Reference in New Issue