-
Notifications
You must be signed in to change notification settings - Fork 18
[UI] Support repo snapshots #462
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
1e3c096
1b63040
4ff91b0
880c04c
1dd7c37
2ece924
edb7d0f
bb35923
d291948
b3c03e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| -- CreateTable | ||
| CREATE TABLE "YDocSnapshot" ( | ||
| "id" TEXT NOT NULL, | ||
| "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "message" TEXT, | ||
| "yDocBlob" BYTEA, | ||
| "repoId" TEXT, | ||
|
|
||
| CONSTRAINT "YDocSnapshot_pkey" PRIMARY KEY ("id") | ||
| ); | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "YDocSnapshot" ADD CONSTRAINT "YDocSnapshot_repoId_fkey" FOREIGN KEY ("repoId") REFERENCES "Repo"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -515,10 +515,50 @@ async function copyRepo(_, { repoId }, { userId }) { | |
| return id; | ||
| } | ||
|
|
||
| /** | ||
| * create yDoc snapshot upon request. | ||
| */ | ||
| async function addRepoSnapshot(_, { repoId, message }) { | ||
| const repo = await prisma.repo.findFirst({ | ||
| where: { id: repoId }, | ||
| include: { | ||
| owner: true, | ||
| collaborators: true, | ||
| }, | ||
| }); | ||
| if (!repo) throw Error("Repo not exists."); | ||
| if (!repo.yDocBlob) throw Error(`yDocBlob on ${repoId} not found`); | ||
| const snapshot = await prisma.yDocSnapshot.create({ | ||
| data: { | ||
| id: await nanoid(), | ||
| yDocBlob: repo.yDocBlob, | ||
| message: message, | ||
| repoId: repoId, | ||
|
||
| }, | ||
| }); | ||
| return snapshot.id; | ||
| } | ||
|
|
||
| /** | ||
| * query yDoc snapshot for a repo. | ||
| */ | ||
| async function getRepoSnapshots(_, { repoId }) { | ||
| const snapshots = await prisma.yDocSnapshot.findMany({ | ||
| where: { repoId: repoId }, | ||
|
||
| }); | ||
| if (!snapshots) throw Error(`No snapshot exists for repo ${repoId}.`); | ||
|
|
||
| return snapshots.map((snapshot) => ({ | ||
| ...snapshot, | ||
| yDocBlob: JSON.stringify(snapshot.yDocBlob), | ||
| })); | ||
| } | ||
|
|
||
| export default { | ||
| Query: { | ||
| repo, | ||
| getDashboardRepos, | ||
| getRepoSnapshots, | ||
| }, | ||
| Mutation: { | ||
| createRepo, | ||
|
|
@@ -531,6 +571,7 @@ export default { | |
| addCollaborator, | ||
| updateVisibility, | ||
| deleteCollaborator, | ||
| addRepoSnapshot, | ||
| star, | ||
| unstar, | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,14 @@ export const typeDefs = gql` | |
| ttl: Int | ||
| } | ||
|
|
||
| type YDocSnapshot { | ||
| id: String | ||
| repoId: String | ||
| createdAt: String | ||
| message: String | ||
| yDocBlob: String | ||
|
||
| } | ||
|
|
||
| type Query { | ||
| hello: String | ||
| users: [User] | ||
|
|
@@ -102,6 +110,7 @@ export const typeDefs = gql` | |
| repo(id: String!): Repo | ||
| pod(id: ID!): Pod | ||
| getDashboardRepos: [Repo] | ||
| getRepoSnapshots(repoId: String!): [YDocSnapshot] | ||
| activeSessions: [String] | ||
| listAllRuntimes: [RuntimeInfo] | ||
| infoRuntime(sessionId: String!): RuntimeInfo | ||
|
|
@@ -137,6 +146,7 @@ export const typeDefs = gql` | |
|
|
||
| exportJSON(repoId: String!): String! | ||
| exportFile(repoId: String!): String! | ||
| addRepoSnapshot(repoId: String!, message: String!): String! | ||
| updateCodeiumAPIKey(apiKey: String!): Boolean | ||
| } | ||
| `; | ||
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.
Lower case “repo” field name.