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

複数LMSのサポート #192

Merged
merged 14 commits into from Feb 4, 2021
Merged

複数LMSのサポート #192

merged 14 commits into from Feb 4, 2021

Conversation

kou029w
Copy link

@kou029w kou029w commented Feb 3, 2021

close #180

!! NOTICE: 破壊的な変更が含まれます !!

  • feat: lti_consumer テーブルの追加
  • fix: 不要なmigrationsが行われる問題への対処 see also Migrate creates unnecessary migrations prisma/prisma#5244
  • feat: 複数のLMSのサポート - 環境変数からではなく lti_consumer テーブルから見つける
  • chore: bump prisma version
  • refactor: use include option in upsertTopic()
  • fix: seeding error:*.upsert()を同期的に実行すると誤って重複するので修正
  • refactor: Unknown→UnlinkedProblem,*NotFoundProblem - create Problem component
  • feat: global session atom
  • feat: NEXT_PUBLIC_LMS_URL をやめる - 代わりに LtiLaunchBody.launch_presentation_return_url を使う
  • chore: ビルドプロセスの整理
  • docs: LTI Tool Consumer 追加手順を記載

本番環境での移行方法

マイグレーション後、次のようなSQLを実行してください。 (@ties-makimura)

例:
OAuth Consumer key: {key}
OAuth Consumer secret: {secret}
の場合

-- Insert empty `lti_consumer`
INSERT INTO "lti_consumer" VALUES ('{key}', '{secret}');

-- Set `consumer_id` and `lti_consumer_id`
UPDATE "lti_context" SET consumer_id = '{key}';
UPDATE "lti_resource_link" SET consumer_id = '{key}';
UPDATE "users" SET lti_consumer_id = '{key}';

その他詳しい情報は README にも記載してます。
ご確認のほどよろしくお願いします。

確認したこと

ローカル環境でマイグレーションが機能することを確認。

git checkout feat-support-multiple-lms
docker-compose rm -sf db && docker-compose up -d db && sleep 5 && yarn --cwd server migrate

以前のバージョンをチェックアウトしマイグレーション・シーディングした後でも同様に機能することを確認。

git checkout master
docker-compose rm -sf db
docker-compose up -d db moodle
sleep 5
yarn --cwd server migrate
yarn --cwd server build:prisma
yarn --cwd server seed
git checkout feat-support-multiple-lms
yarn dev

いずれも問題無くパス。
LMSのリンク(とその更新)も機能している。

@vercel
Copy link

vercel bot commented Feb 3, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/ties-makimura/chibi-ch-i-lo/oyitxvuyn
✅ Preview: https://chibi-ch-i-lo-git-feat-support-multiple-lms.ties-makimura.vercel.app

@kou029w kou029w added this to 現在進行中 in CHiBi-CHiLO via automation Feb 4, 2021
@knokmki612
Copy link

「確認したこと」に記載のあるコマンドを実行して、私のローカル環境でも正常にLTIリンクからちびチロにアクセスできることを確認しました!

Comment on lines 23 to 45
await Promise.all(
ltiResourceLinks
.map((link) => ({ ...link, bookId: createdBooks[0].id }))
.map(upsertLtiResourceLink)
);
for (const link of ltiResourceLinks) {
await upsertLtiResourceLink({
...link,
consumerId: ltiConsumer.id,
bookId: createdBooks[0].id,
});
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Promise.allを使ったほうが効率がよさそうに思ったのですが、
ba3b76c のコミットメッセージをみると、一連のPromiseにたいして非同期にupsertすると、insertで?重複するので、個別にawaitすることで解決した、という意味なのかなと思いました

Copy link
Author

@kou029w kou029w Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

私の手元の環境だけかもしれませんが、

  await Promise.all(topics.map((topic) => upsertTopic(authorId, topic)));	

初回実行時にこの部分で重複するIDのトピック1つ必ず作られており修正しました。
Prismaの実装を詳しく追ったわけでないので正確なことは分かりませんがおそらくON CONFLICT句等でアトミックにINSERTしているわけではなくSELECTクエリとINSERTクエリそれぞれ発行されて1つ前のINSERTの実行以前にSELECTが実行されるなどの要因で誤ったINSERTやUPDATEが発行されているのではないかという仮説があり、とりあえずfor文で直列に実行されるように対処して初回実行時にupsertたちが失敗しないように修正しました。(今読み返すとupsertUserの部分も修正しておくべきですね。。。)

Copy link
Author

@kou029w kou029w Feb 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prisma/prisma#3242 これかな?

@@ -13,18 +13,16 @@ import { pagesPath } from "$utils/$path";
export type Query = BookEditQuery;

function Import({ bookId, context }: BookEditQuery) {
const { data: session } = useSession();
const { isTopicEditable } = useSessionAtom();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTopicEditableとisBookEditableをuseSessionInitで用意してから使いまわせるようにしたんですね、スッキリしましたね!

Copy link

@knokmki612 knokmki612 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良さそうに思いました!

@kou029w
Copy link
Author

kou029w commented Feb 4, 2021

マージします。
検証環境、本番相当環境へのマイグレーションのご対応のほどをお願いします。 > @ties-makimura
振る舞いについてそのほか問題等あれば別途起票ください

@kou029w kou029w merged commit 9a97ec1 into master Feb 4, 2021
CHiBi-CHiLO automation moved this from 現在進行中 to Done Feb 4, 2021
@kou029w kou029w deleted the feat-support-multiple-lms branch February 4, 2021 05:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
CHiBi-CHiLO
  
Done
Development

Successfully merging this pull request may close these issues.

複数LMSのサポート
2 participants