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
75
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
170k Jobs a Day on GKE: Scaling Mercari's CI Platform - and What's Next for AI-Native Development
junyaokabe
0
110
Google Apps Script で Ruby を動かす
kawahara
0
280
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
790
AI Readyの正体はデータマネジメントだ メダリオン2.0の最前線
freee
PRO
0
300
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
480
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
160
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
160
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
810
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
480
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
570
the container ship “Apple Silicon”@WWDC26 Recap -Japan-\(region).swift
shingangan
0
130
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
820
Featured
See All Featured
Navigating Weather and Climate Data
rabernat
0
480
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Side Projects
sachag
455
43k
Leo the Paperboy
mayatellez
8
2.2k
Unsuck your backbone
ammeep
672
58k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
260
Joys of Absence: A Defence of Solitary Play
codingconduct
1
440
Agile that works and the tools we love
rasmusluckow
331
22k
Ruling the World: When Life Gets Gamed
codingconduct
0
300
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
470
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
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のオブジェクト指向、便利✨