-
Notifications
You must be signed in to change notification settings - Fork 10
Add instance config and instance state endpoint #159
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0729048
add instance config endpoint
ded56fa
add column, TODO: impl function for saving config
c4cf3b2
how to store and shape JSON
d0af56f
add endpoint
d9cbf6f
rmv logs
683f429
save
7a9b3a0
make chnages
4568004
change name, add TODO
cf090e7
upsert
91211bb
upsert
d23840f
start this
41c3be2
smthn aint righ
8a45d3d
getconfig done
483538c
state done but check to be sure
79efc94
add config to seed
2fce0dc
remv logs
ba4eeed
how to add state?
c28e563
Merge pull request #161 from pubpub/qdt/redis-lift-2
qweliant 8593c86
fix things
927c97b
rmv export
00c362c
rmv space
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from "./pub"; | ||
| export * from "./members"; | ||
| export * from "./errors"; | ||
| export * from "./errors"; | ||
| export * from "./integrations"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import prisma from "~/prisma/db"; | ||
|
|
||
| export async function setIntegrationInstanceConfig(instanceId: string, config: object) { | ||
| return await prisma.integrationInstance.update({ | ||
| where: { | ||
| id: instanceId, | ||
| }, | ||
| data: { | ||
| config, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| export const getIntegrationInstanceConfig = async (instanceId: string) => { | ||
| return await prisma.integrationInstance.findFirst({ | ||
| where: { | ||
| id: instanceId, | ||
| }, | ||
| select: { | ||
| config: true, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const setIntegrationInstanceState = async (instanceId: string, pubId: string, state) => { | ||
| return await prisma.integrationInstanceState.upsert({ | ||
| where: { | ||
| pub_instance: { | ||
| instanceId, | ||
| pubId, | ||
| }, | ||
| }, | ||
| update: { | ||
| state, | ||
| }, | ||
| create: { | ||
| instanceId, | ||
| pubId, | ||
| state, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| export const getIntegrationInstanceState = async (instanceId: string, pubId: string) => { | ||
| return await prisma.integrationInstanceState.findUnique({ | ||
| where: { | ||
| pub_instance: { | ||
| instanceId, | ||
| pubId, | ||
| }, | ||
| }, | ||
| select: { | ||
| state: true, | ||
| }, | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
core/prisma/migrations/20231030180206_add_config_column_to_schema/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "integration_instances" ADD COLUMN "config" JSONB; | ||
|
|
||
| -- AlterTable | ||
| ALTER TABLE "users" ALTER COLUMN "firstName" DROP DEFAULT, | ||
| ALTER COLUMN "lastName" DROP DEFAULT; |
15 changes: 15 additions & 0 deletions
15
core/prisma/migrations/20231031164256_add_integration_instance_state_table/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "IntegrationInstanceState" ( | ||
| "pub_id" TEXT NOT NULL, | ||
| "instance_id" TEXT NOT NULL, | ||
| "value" JSONB NOT NULL | ||
| ); | ||
|
|
||
| -- CreateIndex | ||
| CREATE UNIQUE INDEX "IntegrationInstanceState_pub_id_instance_id_key" ON "IntegrationInstanceState"("pub_id", "instance_id"); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "IntegrationInstanceState" ADD CONSTRAINT "IntegrationInstanceState_pub_id_fkey" FOREIGN KEY ("pub_id") REFERENCES "pubs"("id") ON DELETE RESTRICT ON UPDATE CASCADE; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "IntegrationInstanceState" ADD CONSTRAINT "IntegrationInstanceState_instance_id_fkey" FOREIGN KEY ("instance_id") REFERENCES "integration_instances"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
10 changes: 10 additions & 0 deletions
10
core/prisma/migrations/20231107143830_change_to_state/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /* | ||
| Warnings: | ||
|
|
||
| - You are about to drop the column `value` on the `IntegrationInstanceState` table. All the data in the column will be lost. | ||
| - Added the required column `state` to the `IntegrationInstanceState` table without a default value. This is not possible if the table is not empty. | ||
|
|
||
| */ | ||
| -- AlterTable | ||
| ALTER TABLE "IntegrationInstanceState" DROP COLUMN "value", | ||
| ADD COLUMN "state" JSONB NOT NULL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd make this an upsert too
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are
integrationInstancesalways going to be unconfigured before they are used? if not i think this should stay anupdate. it doesnt make sense to me why we would want to attach an unconfiguredinstanceto apuband expect users to vibe with that when its in an error state by default.selfishly, making this an
upsertalso means we need to query for anintegrationsomehow. i dont believe there exist a relationship between 'integrationInstances' andintegrationsin our schema unless an array of instances implies a one to many relationship.this means we'd now have to include the
integrationandcommunityid's in theinstanceurl redirect to manage a pub. if im wrong about this and querying for acommunityorintegrationis trivial via some prisma query im unawre of i care less about what i said in the first and second paragraph thoughThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im gonna keep this as update for now
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
none of this is true 🙃
integrationInstances do have a relation to integrations and communities, so it isn't hard to query for those. wedo it in the createPub endpoint for example.
i do see your point about how this is different from instance state at the moment. since we don't actually have any way for a user to create an integration instance, we've been seeding them with a config, so they do start configured. but in the future, users are going to be able to add/remove integrations from core and they won't have any config. after they fill out the form to set the config, we'll need an endpoint to create it, or to make this an upsert.so this will work fine for now, but i think you should add a todo about making this into an upsert and maybe change the name toupdateIntegrationInstanceConfig, since set implies upsert to me!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ you were never really here ✨