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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
umi-java
March 30, 2025
Programming
60
1
Share
データ移行で感じたオブジェクト指向
歴1年ちょいのエンジニアが、DBのデータ移行を行った手順とJavaのオブジェクト指向って便利だなと感じた話です。
umi-java
March 30, 2025
Other Decks in Programming
See All in Programming
野球解説AI Agentを開発してみた - 2026/02/27 LayerX社内LT会資料
shinyorke
PRO
0
390
モダンOBSプラグイン開発
umireon
0
200
Laravel Nightwatchの裏側 - Laravel公式Observabilityツールを支える設計と実装
avosalmon
1
310
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
160
RSAが破られる前に知っておきたい 耐量子計算機暗号(PQC)入門 / Intro to PQC: Preparing for the Post-RSA Era
mackey0225
3
120
VueエンジニアがReactを触って感じた_設計の違い
koukimiura
0
150
AIエージェントで業務改善してみた
taku271
0
420
レガシーPHP転生 〜父がドメインエキスパートだったのでDDD+Claude Codeでチート開発します〜
panda_program
0
230
Strategy for Finding a Problem for OSS: With Real Examples
kibitan
0
130
The free-lunch guide to idea circularity
hollycummins
0
410
夢の無限スパゲッティ製造機 -実装篇- #phpstudy
o0h
PRO
0
190
Nuxt Server Components
wattanx
0
240
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
225
10k
Chasing Engaging Ingredients in Design
codingconduct
0
160
Crafting Experiences
bethany
1
110
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
490
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
990
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
How to make the Groovebox
asonas
2
2.1k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
150
Balancing Empowerment & Direction
lara
5
1k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
2
1k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.8k
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のオブジェクト指向、便利✨