Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
データ移行で感じたオブジェクト指向
Search
umi-java
March 30, 2025
Programming
80
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
データ移行で感じたオブジェクト指向
歴1年ちょいのエンジニアが、DBのデータ移行を行った手順とJavaのオブジェクト指向って便利だなと感じた話です。
umi-java
March 30, 2025
Transcript
12 slides
データ移⾏で感じた オブジェクト指向 ココカラ勉強会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のオブジェクト指向、便利✨
Other Decks in Programming
See All in Programming
AI駆動開発4年目の現在地(『あなたはFDEになるべきか?』イベント資料)
kumaiu
0
680
React Native에 현대적인 빌드 도구 더하기: Rollipop 구현기
leegeunhyeok
0
190
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
610
疎結合とは何か?ソフトウェア設計における結合バランスについて考える #phpcon_niigata
kajitack
2
400
Web3Dライブラリを作ってVue Custom Rendererの仕組みを理解しよう / lets learn vue custom renderer by making 3d library
drumath2237
1
140
Proxmox x Talos Linux x Terraform で実現するなんかいい感じの Kubernetes クラスタ / A Sleek Kubernetes Cluster Powered by Proxmox, Talos Linux, and Terraform
nnaka2992
0
290
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
270
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
Growing PicoRuby's Ecosystem on ESP32
yuuu
2
150
Agentic AI with the Power of Jakarta EE
ivargrimstad
0
120
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
350
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
190
Featured
See All Featured
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
580
Joys of Absence: A Defence of Solitary Play
codingconduct
1
580
The Pragmatic Product Professional
lauravandoore
37
7.5k
Producing Creativity
orderedlist
PRO
348
41k
Color Theory Basics | Prateek | Gurzu
gurzu
1
530
Are puppies a ranking factor?
jonoalderson
2
4.2k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
A better future with KSS
kneath
240
18k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
530
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
68
60k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k