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

refactor: project_path to project_slug DB column renames #1639

Merged
merged 4 commits into from
Aug 2, 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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class ZombieEventDetectionSpec

private def insertProjectToDB(project: data.Project, eventDate: EventDate): Int = EventLog.execute { session =>
val query: Command[GitLabId *: Slug *: EventDate *: EmptyTuple] =
sql"""INSERT INTO project (project_id, project_path, latest_event_date)
sql"""INSERT INTO project (project_id, project_slug, latest_event_date)
VALUES ($projectIdEncoder, $projectSlugEncoder, $eventDateEncoder)
ON CONFLICT (project_id)
DO UPDATE SET latest_event_date = excluded.latest_event_date WHERE excluded.latest_event_date > project.latest_event_date
Expand Down
4 changes: 2 additions & 2 deletions event-log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ Event-log uses relational database as an internal storage. The DB has the follow
| project |
|-------------------------------------------|
| project_id INT4 PK NOT NULL |
| project_path VARCHAR NOT NULL |
| project_slug VARCHAR NOT NULL |
| latest_event_date TIMESTAMPTZ NOT NULL |

| event_payload |
Expand Down Expand Up @@ -945,7 +945,7 @@ Event-log uses relational database as an internal storage. The DB has the follow
| id SERIAL PK NOT NULL |
| date TIMESTAMPTZ NOT NULL |
| project_id INT4 NOT NULL |
| project_path VARCHAR NOT NULL |
| project_slug VARCHAR NOT NULL |

| ts_migration |
|---------------------------------------------|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,10 @@ object EventPayloadFinder {
.build(_.option)

def selectPayload: Query[EventId *: ProjectSlug *: EmptyTuple, PayloadData] =
sql"""
SELECT ep.payload
sql"""SELECT ep.payload
FROM event_payload ep
INNER JOIN project p USING (project_id)
WHERE ep.event_id = $eventIdEncoder AND p.project_path = $projectSlugEncoder
WHERE ep.event_id = $eventIdEncoder AND p.project_slug = $projectSlugEncoder
"""
.query(byteVectorDecoder)
.map(PayloadData)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q
}

private val selectEventInfo: Fragment[Void] = sql"""
SELECT evt.event_id, prj.project_id, prj.project_path, evt.status, evt.event_date, evt.execution_date, evt.message, COUNT(times.status)
SELECT evt.event_id, prj.project_id, prj.project_slug, evt.status, evt.event_date, evt.execution_date, evt.message, COUNT(times.status)
FROM event evt
"""

Expand All @@ -75,7 +75,7 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q

private val filterByProject: projects.Identifier => AppliedFragment = {
case slug: projects.Slug =>
val fragment: Fragment[projects.Slug] = sql"""AND prj.project_path = $projectSlugEncoder"""
val fragment: Fragment[projects.Slug] = sql"""AND prj.project_slug = $projectSlugEncoder"""
fragment(slug)
case id: projects.GitLabId =>
val fragment: Fragment[projects.GitLabId] = sql"""AND prj.project_id = $projectIdEncoder"""
Expand Down Expand Up @@ -131,7 +131,7 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q
"""

private val groupBy: Fragment[Void] = sql"""
GROUP BY evt.event_id, evt.status, evt.event_date, evt.execution_date, evt.message, prj.project_id, prj.project_path
GROUP BY evt.event_id, evt.status, evt.event_date, evt.execution_date, evt.message, prj.project_id, prj.project_slug
"""

private val orderBy: Sorting[Criteria.Sort.type] => Fragment[Void] = sorting => {
Expand Down Expand Up @@ -230,7 +230,9 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q
sql"""SELECT times.status, times.processing_time
FROM status_processing_time times
WHERE times.event_id = $eventIdEncoder AND times.project_id = (
SELECT project_id FROM project WHERE project_path = $projectSlugEncoder
SELECT project_id
FROM project
WHERE project_slug = $projectSlugEncoder
ORDER BY project_id DESC
LIMIT 1
)
Expand All @@ -245,7 +247,7 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q
val query: Fragment[projects.Slug] = sql"""
SELECT COUNT(DISTINCT evt.event_id)
FROM event evt
JOIN project prj ON evt.project_id = prj.project_id AND prj.project_path = $projectSlugEncoder
JOIN project prj ON evt.project_id = prj.project_id AND prj.project_slug = $projectSlugEncoder
"""
query(projectSlug) |+| whereEventDate(maybeDates)
case Criteria(Criteria.Filters.ProjectEvents(projectId: projects.GitLabId, None, maybeDates), _, _) =>
Expand All @@ -259,7 +261,7 @@ private class EventsFinderImpl[F[_]: Async: NonEmptyParallel: SessionResource: Q
val query: Fragment[projects.Slug *: EventStatus *: EmptyTuple] = sql"""
SELECT COUNT(DISTINCT evt.event_id)
FROM event evt
JOIN project prj ON evt.project_id = prj.project_id AND prj.project_path = $projectSlugEncoder
JOIN project prj ON evt.project_id = prj.project_id AND prj.project_slug = $projectSlugEncoder
WHERE evt.status = $eventStatusEncoder
"""
query(projectSlug *: status *: EmptyTuple) |+| andEventDate(maybeDates)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private class CleanUpEventsQueueImpl[F[_]: Async: SessionResource: QueriesExecut
measureExecutionTime {
SqlStatement[F](name = "clean_up_events_queue - offer")
.command[OffsetDateTime *: projects.GitLabId *: projects.Slug *: EmptyTuple](
sql"""INSERT INTO clean_up_events_queue (date, project_id, project_path)
sql"""INSERT INTO clean_up_events_queue (date, project_id, project_slug)
VALUES ($timestamptz, $projectIdEncoder, $projectSlugEncoder)
ON CONFLICT DO NOTHING
""".command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private class ProjectIdFinderImpl[F[_]: MonadCancelThrow: SessionResource: Queri
.select[projects.Slug, projects.GitLabId](sql"""
SELECT project_id
FROM project
WHERE project_path = $projectSlugEncoder
WHERE project_slug = $projectSlugEncoder
""".query(projectIdDecoder))
.arguments(projectSlug)
.build(_.option)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ private class CommitSyncForcerImpl[F[_]: MonadCancelThrow: SessionResource: Quer
SqlStatement
.named(s"${categoryName.value.toLowerCase} - insert project")
.command[projects.GitLabId *: projects.Slug *: EventDate *: EmptyTuple](sql"""
INSERT INTO project (project_id, project_path, latest_event_date)
INSERT INTO project (project_id, project_slug, latest_event_date)
VALUES ($projectIdEncoder, $projectSlugEncoder, $eventDateEncoder)
ON CONFLICT (project_id)
DO NOTHING
ON CONFLICT (project_id) DO NOTHING
""".command)
.arguments(projectId *: projectSlug *: EventDate(Instant.EPOCH) *: EmptyTuple)
.build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ private class EventPersisterImpl[F[_]: MonadCancelThrow: SessionResource: Querie
SqlStatement(name = "new - upsert project")
.command[projects.GitLabId *: projects.Slug *: EventDate *: EmptyTuple](
sql"""
INSERT INTO project (project_id, project_path, latest_event_date)
INSERT INTO project (project_id, project_slug, latest_event_date)
VALUES ($projectIdEncoder, $projectSlugEncoder, $eventDateEncoder)
ON CONFLICT (project_id)
DO
UPDATE SET latest_event_date = EXCLUDED.latest_event_date, project_path = EXCLUDED.project_path
UPDATE SET latest_event_date = EXCLUDED.latest_event_date, project_slug = EXCLUDED.project_slug
WHERE EXCLUDED.latest_event_date > project.latest_event_date
""".command
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ private class GlobalCommitSyncForcerImpl[F[_]: MonadCancelThrow: SessionResource
SqlStatement
.named(s"${categoryName.value.toLowerCase} - insert project")
.command[projects.GitLabId *: projects.Slug *: EventDate *: EmptyTuple](sql"""
INSERT INTO project (project_id, project_path, latest_event_date)
INSERT INTO project (project_id, project_slug, latest_event_date)
VALUES ($projectIdEncoder, $projectSlugEncoder, $eventDateEncoder)
ON CONFLICT (project_id)
DO NOTHING
ON CONFLICT (project_id) DO NOTHING
""".command)
.arguments(projectId *: projectSlug *: EventDate(Instant.EPOCH) *: EmptyTuple)
.build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private[statuschange] class DbUpdater[F[_]: Async: QueriesExecutionTimes](
SqlStatement
.named("all_to_new - find projects")
.select[Void, ProjectEventsToNew](
sql"""SELECT proj.project_id, proj.project_path
sql"""SELECT proj.project_id, proj.project_slug
FROM project proj
ORDER BY proj.latest_event_date ASC"""
.query(projectIdDecoder ~ projectSlugDecoder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ object DequeuedEventHandler {
FROM event e
JOIN project p ON e.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
WHERE #${`status IN`(EventStatus.all diff Set(Skipped, GeneratingTriples, AwaitingDeletion, Deleting))}
FOR UPDATE
) old_evt
Expand All @@ -125,7 +125,7 @@ object DequeuedEventHandler {
FROM status_processing_time t
JOIN project p ON t.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
)""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
.build
Expand All @@ -141,7 +141,7 @@ object DequeuedEventHandler {
FROM event_payload ep
JOIN project p ON ep.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
)""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
.build
Expand All @@ -158,7 +158,7 @@ object DequeuedEventHandler {
FROM event e
JOIN project p ON e.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
)
""".command)
.arguments(status *: project.id *: project.slug *: EmptyTuple)
Expand All @@ -179,7 +179,7 @@ object DequeuedEventHandler {
FROM event e
JOIN project p ON e.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
WHERE e.status = '#${GeneratingTriples.value}'
)""".command)
.arguments(project.id *: project.id *: project.slug *: EmptyTuple)
Expand All @@ -197,7 +197,7 @@ object DequeuedEventHandler {
FROM subscription_category_sync_time st
JOIN project p ON st.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
)
""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
Expand All @@ -212,7 +212,7 @@ object DequeuedEventHandler {
FROM event e
JOIN project p ON e.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
ORDER BY event_date DESC
LIMIT 1""".query(eventDateDecoder))
.arguments(project.id *: project.slug *: EmptyTuple)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private[statuschange] class ProjectCleanerImpl[F[_]: Async: Logger: QueriesExecu
SqlStatement(name = "project_to_new - clean_up_events_queue removal")
.command[projects.GitLabId *: projects.Slug *: EmptyTuple](sql"""
DELETE FROM clean_up_events_queue
WHERE project_id = $projectIdEncoder AND project_path = $projectSlugEncoder""".command)
WHERE project_id = $projectIdEncoder AND project_slug = $projectSlugEncoder""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
.build
.void
Expand All @@ -102,7 +102,7 @@ private[statuschange] class ProjectCleanerImpl[F[_]: Async: Logger: QueriesExecu
FROM subscription_category_sync_time st
JOIN project p ON st.project_id = p.project_id
AND p.project_id = $projectIdEncoder
AND p.project_path = $projectSlugEncoder
AND p.project_slug = $projectSlugEncoder
)""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
.build
Expand All @@ -113,7 +113,7 @@ private[statuschange] class ProjectCleanerImpl[F[_]: Async: Logger: QueriesExecu
SqlStatement(name = "project_to_new - remove project")
.command[projects.GitLabId *: projects.Slug *: EmptyTuple](sql"""
DELETE FROM project
WHERE project_id = $projectIdEncoder AND project_path = $projectSlugEncoder""".command)
WHERE project_id = $projectIdEncoder AND project_slug = $projectSlugEncoder""".command)
.arguments(project.id *: project.slug *: EmptyTuple)
.build
.mapResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private class DequeuedEventHandlerImpl[F[_]: Async: QueriesExecutionTimes](
FROM (
SELECT e.event_id, e.project_id
FROM event e
JOIN project p ON e.project_id = p.project_id AND p.project_path = $projectSlugEncoder
JOIN project p ON e.project_id = p.project_id AND p.project_slug = $projectSlugEncoder
WHERE e.status = '#${TriplesStore.value}'
ORDER BY event_date DESC
LIMIT 1
Expand Down Expand Up @@ -119,7 +119,7 @@ private class DequeuedEventHandlerImpl[F[_]: Async: QueriesExecutionTimes](
AND project_id = (
SELECT project_id
FROM project
WHERE project_path = $projectSlugEncoder
WHERE project_slug = $projectSlugEncoder
)
""".command
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private class EventFinderImpl[F[_]: Async: Parallel: SessionResource: QueriesExe
.named(s"${SubscriptionCategory.categoryName.value.toLowerCase} - find projects")
.select[ExecutionDate *: ExecutionDate *: Int *: EmptyTuple, ProjectInfo](
sql"""
SELECT p.project_id, p.project_path, p.latest_event_date,
SELECT p.project_id, p.project_slug, p.latest_event_date,
(SELECT count(event_id) FROM event evt_int WHERE evt_int.project_id = p.project_id AND evt_int.status = '#${GeneratingTriples.value}') AS current_occupancy
FROM (
SELECT DISTINCT project_id, MAX(event_date) AS max_event_date
Expand Down Expand Up @@ -140,7 +140,7 @@ private class EventFinderImpl[F[_]: Async: Parallel: SessionResource: QueriesExe
.select[projects.Slug *: projects.GitLabId *: ExecutionDate *: ExecutionDate *: EmptyTuple,
AwaitingGenerationEvent
](sql"""
SELECT evt.event_id, evt.project_id, $projectSlugEncoder AS project_path, evt.event_body
SELECT evt.event_id, evt.project_id, $projectSlugEncoder AS project_slug, evt.event_body
FROM (
SELECT project_id, max(event_date) AS max_event_date
FROM event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private class EventFinderImpl[F[_]: Async: Parallel: SessionResource: Logger: Qu
SqlStatement
.named(s"${categoryName.show.toLowerCase} - find event in queue")
.select[Void, Project](sql"""
SELECT queue.project_id, queue.project_path
SELECT queue.project_id, queue.project_slug
FROM clean_up_events_queue queue
ORDER BY queue.date ASC
LIMIT 1
Expand All @@ -85,7 +85,7 @@ private class EventFinderImpl[F[_]: Async: Parallel: SessionResource: Logger: Qu
SqlStatement
.named(s"${categoryName.show.toLowerCase} - find event")
.select[ExecutionDate, Project](sql"""
SELECT evt.project_id, prj.project_path
SELECT evt.project_id, prj.project_slug
FROM event evt
JOIN project prj ON prj.project_id = evt.project_id
WHERE evt.status = '#${AwaitingDeletion.value}'
Expand All @@ -104,7 +104,7 @@ private class EventFinderImpl[F[_]: Async: Parallel: SessionResource: Logger: Qu
.named(s"${categoryName.show.toLowerCase} - delete clean-up event")
.command[projects.Slug](sql"""
DELETE FROM clean_up_events_queue
WHERE project_path = $projectSlugEncoder
WHERE project_slug = $projectSlugEncoder
""".command)
.arguments(projectSlug)
.build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private class EventFinderImpl[F[_]: MonadCancelThrow: SessionResource: QueriesEx
LIMIT 1
) event_status,
proj.project_id,
proj.project_path,
proj.project_slug,
sync_time.last_synced,
proj.latest_event_date
FROM project proj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private class EventFinderImpl[F[_]: Async: SessionResource: QueriesExecutionTime
.select[CategoryName *: LastSyncedDate *: EmptyTuple, (Project, Option[LastSyncedDate])](
sql"""SELECT
proj.project_id,
proj.project_path,
proj.project_slug,
sync_time.last_synced
FROM project proj
LEFT JOIN subscription_category_sync_time sync_time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private class EventFinderImpl[F[_]: MonadCancelThrow: SessionResource: QueriesEx
CategoryName *: EventDate *: LastSyncedDate *: EventDate *: LastSyncedDate *: EventDate *: LastSyncedDate *: EmptyTuple,
(projects.GitLabId, Option[LastSyncedDate], MemberSyncEvent)
](
sql"""SELECT proj.project_id, sync_time.last_synced, proj.project_path
sql"""SELECT proj.project_id, sync_time.last_synced, proj.project_slug
FROM project proj
LEFT JOIN subscription_category_sync_time sync_time
ON sync_time.project_id = proj.project_id AND sync_time.category_name = $categoryNameEncoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private class EventFinderImpl[F[_]: MonadCancelThrow: SessionResource: QueriesEx
SqlStatement
.named(s"${categoryName.show.toLowerCase} - find event")
.select[Void, MinProjectInfoEvent](
sql"""SELECT p.project_id, p.project_path
sql"""SELECT p.project_id, p.project_slug
FROM project p
WHERE NOT EXISTS (
SELECT project_id
Expand Down
Loading