Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
データ移行で感じたオブジェクト指向
Search
umi-java
March 30, 2025
Programming
73
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
データ移行で感じたオブジェクト指向
歴1年ちょいのエンジニアが、DBのデータ移行を行った手順とJavaのオブジェクト指向って便利だなと感じた話です。
umi-java
March 30, 2025
Other Decks in Programming
See All in Programming
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
160
yield再入門 #phpcon
o0h
PRO
0
820
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
290
AIが無かった頃の素敵な出会いの話
codmoninc
1
280
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.4k
AI時代に設計が 最大の生産性レバーになる 意図駆動開発とデータを消さない設計|Don't Delete Your Data or Your Intent — Design as the Deepest Lever in the AI Era
tomohisa
0
120
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
160
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
200
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
340
Built Our Own Background Agent at LayerX #aidevex_findy
layerx
PRO
9
3.8k
React本体のコードリーディング
high_g_engineer
0
110
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
1.8k
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
Claude Code のすすめ
schroneko
67
230k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.5k
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
190
Leo the Paperboy
mayatellez
8
1.9k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
GitHub's CSS Performance
jonrohan
1033
470k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
4 Signs Your Business is Dying
shpigford
187
22k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
400
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
270
Transcript
データ移⾏で感じた オブジェクト指向 ココカラ勉強会LT 2025.03.29 うみ
about Me X : @umi_java バックエンド:Java / Spring boot フロントエンド:React
/ Next.js うみ ⾷品栄養系の研究職(企業勤務4年間+⼤学勤務3年間) 2023年夏〜 Javaを勉強 2024年1⽉〜 エンジニア転職 オンラインスクール運営会社にて社内システムの開発
background 使用環境 Java 21 Spring boot v3.4.0 受講生管理システム(現行:A) 移行元DB:MySQL 移行先DB:postgreSQL
新・受講生管理システム(B) 作成中
事前準備‧環境構築 (先輩にやってもらったこと) • データ移行用リポジトリ作成 ⬇ • 移行元 (mySQL) DB、移行先 (postgreSQL)
DBとの繋ぎこみ • 移行元データ から移行先テーブルへのマッピング ◦ 元のデータを抜け漏れなく移行するため
移⾏先テーブル単位でのマッピング • 移行先テーブル基準で、どのカラムにどのデータが入るか整理 (各カラムのNOT NULL制約が満たせるかなど確認) • 変換処理が必要なデータの洗い出し データ移行について考えてる人 ▶ by
DALL-E
データ構造(抜粋) 移行前(A) 移行先(B) int型 ( 1, 2, 3, … )
String型 ( ULID )
データ構造(抜粋) 移⾏前(A) 移⾏先(B) idの対応を取るため 移⾏先の各テーブルに ʻlegacy_student_id’ カラム追加? int型 ( 1,
2, 3, … ) String型 ( ULID )
移⾏元データオブジェクトの作成 テーブルごとのオブジェクト(DTO)を用意 (A: mySQL DB)
StudentEntityのフィールドに、student_courseやchat_userのオブジェクトも内包 移⾏先データオブジェクトの作成(B) (B: postgreSQL DB)
データ移⾏① studentEntity⽣成メソッド studentId から studentや studentCourse を全件取得し各オ ブジェクト(A)に格納 student 情報を移行先のオブジェク
ト(studentEntity)に set 取得した studentCourseなど、他の テーブル情報もそれぞれの Entityに set ↓ studentEntity に各Entity を全て set
A(mySQL DB) から Student 全件取得 ↓ Student 1件ずつ以下を繰り返し実⾏ - StudentEntity⽣成(①のメソッド)
- StudentEntityにsetしたデータをB(postgreSQL DB)の各テーブルに インサート ↓ 完 データ移⾏② AからBへデータ移⾏
まとめ DBのデータをオブジェクト化してひとまとめに扱うことで、 - 各テーブルに移行用の特別なカラムを設置したり、 - 複雑なSQL文を書いたり することなく、シンプルにデータの移行ができた。 今回使ったSQL文は SELECTと INSERTのみ
データの加工・変換処理もJava文法で書けるので分かりやすい →Javaのオブジェクト指向、便利✨