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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
umi-java
March 30, 2025
Programming
78
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
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
130
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
440
R8 の設定見直しでアプリサイズ削減
andpad
0
140
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.5k
パーソナライズPodcastを作った話
repunit11
0
120
Heart of Swift Concurrency
koher
0
1.2k
Rでドレミ/Do-Re-Mi_with_R
florets1
0
120
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
310
Embedded Swiftで作る自作USBデバイス によるiOSデバイスの自動テスト / iOSDC Japan 2026 glassfiber
glassfiber
0
290
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
340
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
360
Simple Storage Service(S3) is not simple
iwatsukayura
0
190
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Paper Plane
katiecoart
PRO
4
53k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
760
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Raft: Consensus for Rubyists
vanstee
142
7.7k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.2k
Designing Experiences People Love
moore
143
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
4k
The Curse of the Amulet
leimatthew05
3
15k
The SEO identity crisis: Don't let AI make you average
varn
0
580
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
460
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のオブジェクト指向、便利✨