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

chore(rethinkdb): TeamInvitation: Phase 3 #10327

Merged
merged 113 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
bbd3d12
chore: write to PG
mattkrick Aug 27, 2024
217606e
fix: refactor comment to SDL
mattkrick Aug 27, 2024
fd13993
add comment
mattkrick Aug 27, 2024
918b493
Merge branch 'master' into chore/Comment-phase1
mattkrick Aug 28, 2024
424a54b
migrate existing Comments
mattkrick Aug 29, 2024
c0278ae
switch reads to PG
mattkrick Aug 29, 2024
4cf9c8f
fix replies
mattkrick Aug 29, 2024
d61559a
Merge branch 'master' into chore/Comment-phase3
mattkrick Sep 6, 2024
da853e7
init migration
mattkrick Sep 6, 2024
fb941f6
add writes to PG
mattkrick Sep 9, 2024
0efe604
Merge branch 'master' into chore/ReflectPrompt-phase1
mattkrick Sep 9, 2024
814d9ef
refactor add/move reflect template prompt to sdl
mattkrick Sep 9, 2024
134b3b6
refactor 4 mutations to sdl
mattkrick Sep 9, 2024
2f8cf27
fix downmigration
mattkrick Sep 9, 2024
9f372a1
Merge branch 'master' into chore/ReflectPrompt-phase1
mattkrick Sep 9, 2024
171ded7
use explicit columns
mattkrick Sep 9, 2024
a38beb4
migrate existing rows
mattkrick Sep 9, 2024
8a64083
progress
mattkrick Sep 9, 2024
fcc66a9
use explicit props
mattkrick Sep 9, 2024
c44f72c
use explicit props nullable
mattkrick Sep 9, 2024
9c2b951
Merge branch 'chore/ReflectPrompt-phase1' into chore/ReflectPrompt-ph…
mattkrick Sep 9, 2024
e628e0b
remove writes to R
mattkrick Sep 10, 2024
21fc97c
fix tsc
mattkrick Sep 10, 2024
ec73789
fix bad old migrations referencing types
mattkrick Sep 10, 2024
d18a710
Merge branch 'chore/ReflectPrompt-phase1' into chore/ReflectPrompt-ph…
mattkrick Sep 10, 2024
551ce33
Merge branch 'chore/ReflectPrompt-phase2' into chore/ReflectPrompt-ph…
mattkrick Sep 10, 2024
726f632
chore: migrate PasswordResetRequest
mattkrick Sep 10, 2024
9c7839d
use 2 queries for resets
mattkrick Sep 10, 2024
89040df
clean up clientside sortOrder
mattkrick Sep 10, 2024
5843139
Merge branch 'master' into chore/ReflectPrompt-phase2
mattkrick Sep 11, 2024
cc6bcbc
Merge branch 'chore/ReflectPrompt-phase2' into chore/ReflectPrompt-ph…
mattkrick Sep 11, 2024
69fa463
Merge branch 'chore/ReflectPrompt-phase3' into chore/PasswordResetReq…
mattkrick Sep 11, 2024
8abce47
chore: migrate PushInvitation
mattkrick Sep 11, 2024
c30e68f
fix test
mattkrick Sep 11, 2024
845366f
Merge branch 'master' into chore/NewMeeting-phase1
mattkrick Sep 11, 2024
feb72b8
add types
mattkrick Sep 12, 2024
ad4b876
Merge branch 'master' into chore/NewMeeting-phase1
mattkrick Sep 12, 2024
7d84391
fix name conflict
mattkrick Sep 12, 2024
a33d00f
remove as much coercion as possible
mattkrick Sep 12, 2024
a25d978
Merge branch 'master' into chore/NewMeeting-phase1
mattkrick Sep 12, 2024
cdc0a02
fix migration name
mattkrick Sep 12, 2024
835dd65
Merge branch 'master' into chore/NewMeeting-phase1
mattkrick Sep 13, 2024
5a155ca
revert processRecurrence test
mattkrick Sep 13, 2024
3a0d530
progress
mattkrick Sep 15, 2024
30c1ab3
finish adding writes to PG
mattkrick Sep 17, 2024
e2f8b30
fix downmigration
mattkrick Sep 17, 2024
2eb4482
self review
mattkrick Sep 17, 2024
7f256a2
first pass
mattkrick Sep 23, 2024
36fe2f8
chore: add default value for meetinCount
mattkrick Sep 24, 2024
9e3c1bc
equality checker first pass
mattkrick Sep 24, 2024
7eebaba
on delete cascade
mattkrick Sep 24, 2024
7c374ed
Merge branch 'master' into chore/NewMeeting-phase1
mattkrick Sep 24, 2024
24624f1
merge master
mattkrick Sep 24, 2024
a2200ce
Merge branch 'chore/NewMeeting-phase1b' into chore/NewMeeting-phase2
mattkrick Sep 24, 2024
c2acd22
fixup equality checker
mattkrick Sep 24, 2024
57790ac
fix stopMeetingSeries
mattkrick Sep 24, 2024
6a23205
fix trigger
mattkrick Sep 24, 2024
feb3e4b
fix trigger
mattkrick Sep 24, 2024
b06ab38
Merge branch 'chore/NewMeeting-phase1b' into chore/NewMeeting-phase2
mattkrick Sep 24, 2024
dd6c1bf
init
mattkrick Sep 24, 2024
2a28f19
remove comma after execute()
mattkrick Sep 25, 2024
11eeec0
progress
mattkrick Sep 25, 2024
f2b7b79
fix equality check
mattkrick Sep 25, 2024
d208f73
refactor to PG
mattkrick Sep 26, 2024
703b109
fix endTime index
mattkrick Sep 27, 2024
046198b
Merge branch 'chore/NewMeeting-phase1' into chore/NewMeeting-phase1b
mattkrick Sep 27, 2024
8c12687
fix tsc
mattkrick Sep 27, 2024
4e708b5
Merge branch 'chore/NewMeeting-phase1b' into chore/NewMeeting-phase2
mattkrick Sep 27, 2024
24739d8
merge 2
mattkrick Sep 27, 2024
a2c582e
fix nullability
mattkrick Sep 27, 2024
d7dca32
Merge branch 'master' into chore/NewMeeting-phase2
mattkrick Sep 27, 2024
f2d5f15
disable check_meeting_overlap trigger for tests
mattkrick Sep 27, 2024
882cb0b
handle empty arrays
mattkrick Sep 27, 2024
baec1ce
fix typo
mattkrick Sep 27, 2024
e803ce7
fix processRecurrence.test
mattkrick Sep 28, 2024
6c38ce0
Merge branch 'chore/NewMeeting-phase2' into chore/NewMeeting-phase3
mattkrick Oct 1, 2024
5290837
Merge branch 'master' into chore/NewMeeting-phase3
mattkrick Oct 1, 2024
c1668ae
fix: bugs in self review
mattkrick Oct 2, 2024
2b7f490
chore: write to PG
mattkrick Oct 2, 2024
bc524d5
remove MeetingMember db type
mattkrick Oct 2, 2024
8ec1185
Merge branch 'master' into chore/NewMeeting-phase3
mattkrick Oct 3, 2024
8ab1ba5
Merge branch 'chore/NewMeeting-phase3' into chore/MeetingMember-phase1
mattkrick Oct 3, 2024
ca19288
fix: updateRetroMaxVotes
mattkrick Oct 3, 2024
a588b0d
fix: re-add MeetingMember
mattkrick Oct 3, 2024
011e646
chore: migrate existing rows
mattkrick Oct 3, 2024
7c844ce
first pass removing R
mattkrick Oct 4, 2024
120cf15
fix: voting transaction logic
mattkrick Oct 7, 2024
e3980ba
Merge branch 'master' into chore/NewMeeting-phase3
mattkrick Oct 8, 2024
a3644d7
Merge branch 'chore/NewMeeting-phase3' into chore/MeetingMember-phase1
mattkrick Oct 8, 2024
cc01e7e
Merge branch 'master' into chore/NewMeeting-phase3
mattkrick Oct 8, 2024
551afb6
Merge branch 'chore/NewMeeting-phase3' into chore/MeetingMember-phase1
mattkrick Oct 8, 2024
c599981
Merge branch 'chore/MeetingMember-phase1' into chore/MeetingMember-ph…
mattkrick Oct 8, 2024
d0decfd
Merge branch 'chore/MeetingMember-phase2' into chore/MeetingMember-ph…
mattkrick Oct 8, 2024
3d43dfc
chore: migrate MassInvitation
mattkrick Oct 8, 2024
4c4e791
chore: move NewFeature to PG
mattkrick Oct 8, 2024
d0aea83
Merge branch 'master' into chore/MeetingMember-phase2
mattkrick Oct 8, 2024
af15e12
Merge branch 'chore/MeetingMember-phase2' into chore/MeetingMember-ph…
mattkrick Oct 8, 2024
1c14d5d
fixup lint
mattkrick Oct 8, 2024
74607a8
chore: add writes to PG
mattkrick Oct 9, 2024
4f3145f
Merge branch 'chore/MeetingMember-phase3' into chore/MassInvitation-1…
mattkrick Oct 9, 2024
abaa434
Merge branch 'master' into chore/MeetingMember-phase3
mattkrick Oct 9, 2024
339459d
Merge branch 'chore/MeetingMember-phase3' into chore/MassInvitation-1…
mattkrick Oct 9, 2024
21a3347
Merge branch 'chore/MassInvitation-1shot' into chore/NewFeature
mattkrick Oct 9, 2024
2658800
Merge branch 'chore/NewFeature' into chore/TeamInvitation-phase1
mattkrick Oct 9, 2024
7407c2c
chore: migrate rows to PG
mattkrick Oct 9, 2024
b53fbd8
chore: move reads to PG
mattkrick Oct 9, 2024
466c175
remove unused references
mattkrick Oct 9, 2024
0b6539d
Merge branch 'master' into chore/NewFeature
mattkrick Oct 9, 2024
625b41a
Merge branch 'chore/NewFeature' into chore/TeamInvitation-phase1
mattkrick Oct 10, 2024
7e45348
Merge branch 'master' into chore/TeamInvitation-phase1
mattkrick Oct 10, 2024
a7f595d
Merge branch 'chore/TeamInvitation-phase1' into chore/TeamInvitation-…
mattkrick Oct 10, 2024
d1d10ff
Merge branch 'chore/TeamInvitation-phase2' into chore/TeamInvitation-…
mattkrick Oct 10, 2024
85867a6
Merge branch 'master' into chore/TeamInvitation-phase3
mattkrick Oct 10, 2024
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
11 changes: 1 addition & 10 deletions packages/server/database/rethinkDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {MasterPool, r} from 'rethinkdb-ts'
import {TeamInvitation} from '../postgres/types/index'
import getRethinkConfig from './getRethinkConfig'
import {R} from './stricterR'
import NotificationKickedOut from './types/NotificationKickedOut'
Expand All @@ -15,10 +14,6 @@ import NotificationTeamInvitation from './types/NotificationTeamInvitation'
import Task from './types/Task'

export type RethinkSchema = {
NewFeature: {
type: any
index: ''
}
Notification: {
type:
| NotificationTaskInvolves
Expand All @@ -44,14 +39,10 @@ export type RethinkSchema = {
| 'userId'
| 'integrationHash'
}
TeamInvitation: {
type: TeamInvitation
index: 'email' | 'teamId' | 'token'
}
}

export type DBType = {
[P in keyof RethinkSchema]: RethinkSchema[P]['type']
[P in keyof RethinkSchema]: any
}

export type ParabolR = R<RethinkSchema>
Expand Down
42 changes: 0 additions & 42 deletions packages/server/database/types/TeamInvitation.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/server/dataloader/RethinkDBCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class RethinkDBCache {
.table(table)
.get(id)
// "always" will return the document whether it has changed or not
.update(updater, {returnChanges: 'always'})('changes')(0)('new_val')
.update(updater as any, {returnChanges: 'always'})('changes')(0)('new_val')
.default(null)
)
})
Expand Down
4 changes: 2 additions & 2 deletions packages/server/dataloader/foreignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ export const massInvitationsByTeamMemberId = foreignKeyLoaderMaker(
}
)

export const _pgteamInvitationsByTeamId = foreignKeyLoaderMaker(
'_pgteamInvitations',
export const teamInvitationsByTeamId = foreignKeyLoaderMaker(
'teamInvitations',
'teamId',
async (teamIds) => {
return selectTeamInvitations()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/dataloader/primaryKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,6 @@ export const newFeatures = primaryKeyLoaderMaker((ids: readonly number[]) => {
return selectNewFeatures().where('id', 'in', ids).execute()
})

export const _pgteamInvitations = primaryKeyLoaderMaker((ids: readonly string[]) => {
export const teamInvitations = primaryKeyLoaderMaker((ids: readonly string[]) => {
return selectTeamInvitations().where('id', 'in', ids).execute()
})
15 changes: 0 additions & 15 deletions packages/server/dataloader/rethinkForeignKeyLoaderMakers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,3 @@ export const tasksByTeamId = new RethinkForeignKeyLoaderMaker(
.run()
}
)

export const teamInvitationsByTeamId = new RethinkForeignKeyLoaderMaker(
'teamInvitations',
'teamId',
async (teamIds) => {
const r = await getRethink()
const now = new Date()
return r
.table('TeamInvitation')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter({acceptedAt: null})
.filter((row: RDatum) => row('expiresAt').ge(now))
.run()
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ import RethinkPrimaryKeyLoaderMaker from './RethinkPrimaryKeyLoaderMaker'
*/
export const notifications = new RethinkPrimaryKeyLoaderMaker('Notification')
export const tasks = new RethinkPrimaryKeyLoaderMaker('Task')
export const teamInvitations = new RethinkPrimaryKeyLoaderMaker('TeamInvitation')
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {InvitationTokenError} from 'parabol-client/types/constEnums'
import getRethink from '../../../database/rethinkDriver'
import generateUID from '../../../generateUID'
import getKysely from '../../../postgres/getKysely'
import {verifyMassInviteToken} from '../../../utils/massInviteToken'
Expand All @@ -13,7 +12,6 @@ const handleMassInviteToken = async (
) => {
const validToken = await verifyMassInviteToken(invitationToken, dataLoader)
if ('error' in validToken) return {error: validToken.error}
const r = await getRethink()
const {teamId, userId: invitedBy, exp: expiresAt, meetingId} = validToken
if (tms?.includes(teamId)) {
return {error: InvitationTokenError.ALREADY_ACCEPTED, teamId, meetingId}
Expand All @@ -26,14 +24,9 @@ const handleMassInviteToken = async (
teamId,
expiresAt,
email,
isMassInvite: true,
acceptedAt: null
isMassInvite: true
}
await getKysely().insertInto('TeamInvitation').values(invitation).execute()
await r
.table('TeamInvitation')
.insert({...invitation, createdAt: new Date()})
.run()
return {invitation}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {InvitationTokenError} from 'parabol-client/types/constEnums'
import getRethink from '../../../database/rethinkDriver'
import {TeamInvitation} from '../../../postgres/types'
import getKysely from '../../../postgres/getKysely'

const handleTeamInviteToken = async (
invitationToken: string,
Expand All @@ -9,12 +9,13 @@ const handleTeamInviteToken = async (
notificationId?: string
) => {
const r = await getRethink()
const invitation = (await r
.table('TeamInvitation')
.getAll(invitationToken, {index: 'token'})
.nth(0)
.default(null)
.run()) as TeamInvitation
const pg = getKysely()
const invitation = await pg
.selectFrom('TeamInvitation')
.selectAll()
.where('token', '=', invitationToken)
.limit(1)
.executeTakeFirst()
if (!invitation) return {error: InvitationTokenError.NOT_FOUND}
const {expiresAt} = invitation
if (expiresAt.getTime() < Date.now()) {
Expand Down
23 changes: 14 additions & 9 deletions packages/server/graphql/mutations/helpers/inviteToTeamHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,21 @@ const inviteToTeamHelper = async (
const operationId = dataLoader.share()
const subOptions = {mutatorId, operationId}

const [total, pending] = await Promise.all([
r.table('TeamInvitation').getAll(teamId, {index: 'teamId'}).count().run(),
r
.table('TeamInvitation')
.getAll(teamId, {index: 'teamId'})
.filter({acceptedAt: null})
.count()
.run()
const [totalRes, pendingRes] = await Promise.all([
pg
.selectFrom('TeamInvitation')
.select(({fn}) => fn.count<bigint>('id').as('count'))
.where('teamId', '=', teamId)
.executeTakeFirstOrThrow(),
pg
.selectFrom('TeamInvitation')
.select(({fn}) => fn.count<bigint>('id').as('count'))
.where('teamId', '=', teamId)
.where('acceptedAt', 'is', null)
.executeTakeFirstOrThrow()
])
const total = Number(totalRes.count)
const pending = Number(pendingRes.count)
const accepted = total - pending
// if no one has accepted one of their 100+ invites, don't trust them
if (accepted === 0 && total + invitees.length >= 100) {
Expand Down Expand Up @@ -126,7 +132,6 @@ const inviteToTeamHelper = async (
createdAt: new Date(),
acceptedAt: null
}))
await r.table('TeamInvitation').insert(teamInvitationsToInsert).run()
await pg.insertInto('TeamInvitation').values(teamInvitationsToInsert).execute()
// remove suggested action, if any
let removedSuggestedActionId
Expand Down
12 changes: 1 addition & 11 deletions packages/server/graphql/private/mutations/hardDeleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,7 @@ const hardDeleteUser: MutationResolvers['hardDeleteUser'] = async (
.table('Task')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter((row: RValue) => row('createdBy').eq(userIdToDelete))
.delete(),
invitedByTeamInvitation: r
.table('TeamInvitation')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter((row: RValue) => row('invitedBy').eq(userIdToDelete))
.delete(),
createdByTeamInvitations: r
.table('TeamInvitation')
.getAll(r.args(teamIds), {index: 'teamId'})
.filter((row: RValue) => row('acceptedBy').eq(userIdToDelete))
.update({acceptedBy: ''})
.delete()
}).run()

// now postgres, after FKs are added then triggers should take care of children
Expand Down
17 changes: 9 additions & 8 deletions packages/server/graphql/queries/verifiedInvitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {GraphQLID, GraphQLNonNull} from 'graphql'
import {InvitationTokenError} from 'parabol-client/types/constEnums'
import util from 'util'
import {AuthIdentityTypeEnum} from '../../../client/types/constEnums'
import getRethink from '../../database/rethinkDriver'
import getKysely from '../../postgres/getKysely'
import {getUserByEmail} from '../../postgres/queries/getUsersByEmails'
import IUser from '../../postgres/types/IUser'
import getBestInvitationMeeting from '../../utils/getBestInvitationMeeting'
Expand Down Expand Up @@ -41,14 +41,15 @@ export default {
},
resolve: rateLimit({perMinute: 60, perHour: 1800})(
async (_source: unknown, {token}, {dataLoader}: GQLContext) => {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const teamInvitation = await r
.table('TeamInvitation')
.getAll(token, {index: 'token'})
.nth(0)
.default(null)
.run()
const teamInvitation = await pg
.selectFrom('TeamInvitation')
.selectAll()
.where('token', '=', token)
.limit(1)
.executeTakeFirst()

if (!teamInvitation) return {errorType: InvitationTokenError.NOT_FOUND}
const {
email,
Expand Down
12 changes: 1 addition & 11 deletions packages/server/safeMutations/acceptTeamInvitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ const handleFirstAcceptedInvitation = async (
const acceptTeamInvitation = async (team: Team, userId: string, dataLoader: DataLoaderWorker) => {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const {id: teamId, orgId} = team
const [user, organizationUser] = await Promise.all([
dataLoader.get('users').loadNonNull(userId),
Expand Down Expand Up @@ -112,16 +111,7 @@ const acceptTeamInvitation = async (team: Team, userId: string, dataLoader: Data
openDrawer: 'manageTeam'
})
.onConflict((oc) => oc.column('id').doUpdateSet({isNotRemoved: true, isLead: false}))
.execute(),
r
.table('TeamInvitation')
.getAll(teamId, {index: 'teamId'})
.filter({email})
.update({
acceptedAt: now,
acceptedBy: userId
})
.run()
.execute()
])
dataLoader.clearAll(['teamMembers', 'users'])
if (!organizationUser) {
Expand Down
15 changes: 1 addition & 14 deletions packages/server/safeMutations/safeArchiveTeam.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
import {sql} from 'kysely'
import getRethink from '../database/rethinkDriver'
import {RDatum} from '../database/stricterR'
import {DataLoaderWorker} from '../graphql/graphql'
import getKysely from '../postgres/getKysely'

const safeArchiveTeam = async (teamId: string, dataLoader: DataLoaderWorker) => {
const r = await getRethink()
const pg = getKysely()
const now = new Date()
const teamMembers = await dataLoader.get('teamMembersByTeamId').load(teamId)
const userIds = teamMembers.map((tm) => tm.userId)
const [rethinkResult, removedSuggestedActions, team] = await Promise.all([
r({
invitations: r
.table('TeamInvitation')
.getAll(teamId, {index: 'teamId'})
.filter({acceptedAt: null})
.update((invitation: RDatum) => ({
expiresAt: r.min([invitation('expiresAt'), now])
})) as unknown as null
}).run(),
const [removedSuggestedActions, team] = await Promise.all([
pg
.updateTable('SuggestedAction')
.set({removedAt: now})
Expand Down Expand Up @@ -48,7 +36,6 @@ const safeArchiveTeam = async (teamId: string, dataLoader: DataLoaderWorker) =>
dataLoader.clearAll(['teamMembers', 'users', 'teams'])
const users = await Promise.all(userIds.map((userId) => dataLoader.get('users').load(userId)))
return {
invitations: rethinkResult.invitations,
removedSuggestedActionIds: removedSuggestedActions.map(({id}) => id),
team: team ?? null,
users
Expand Down
Loading