iT邦幫忙

0

問問資料庫migration的概念

  • 分享至 

  • twitterImage

最近在使用migration來控制資料庫的版本,但現在有個問題是,migration是用手打進去的,如果像是使用者在網頁操作而Insert的資料,有要放進migration裡嗎(這裡問migration的主要概念,不考慮開發者的想法)?不太懂migration的主要概念是要控制schema版本還是data也要包含?
如果data也包含的話,這樣就是要在後端每一個insert動作完成後,自動寫它的sql到migration檔?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
通靈亡
iT邦高手 1 級 ‧ 2020-06-10 11:27:12
最佳解答

每個後端語言或框架的資料庫Migration的概念都差不多
都是用來管理「資料表的結構(schema)」的版本控制
跟開發者比較有關
https://en.wikipedia.org/wiki/Schema_migration

schema migration (also database migration, database change management)

A schema migration is performed on a database whenever it is necessary to update or revert that database's schema to some newer or older version.

Migrations are performed programmatically by using a schema migration tool. When invoked with a specified desired schema version, the tool automates the successive application or reversal of an appropriate sequence of schema changes until it is brought to the desired state.

使用者在網頁操作而Insert的資料(data) 是資料庫的資料備份跟還原的事情。

看更多先前的回應...收起先前的回應...
wrxue iT邦好手 1 級 ‧ 2020-06-11 09:57:15 檢舉

了解,感謝相關資料! 這樣migration 和 資料備份是不是就要同時做?

通靈亡 iT邦高手 1 級 ‧ 2020-06-11 09:59:53 檢舉

都要做沒錯

wrxue iT邦好手 1 級 ‧ 2020-06-11 10:03:32 檢舉

請問migrate在一個專案中通常是必要的嗎?

通靈亡 iT邦高手 1 級 ‧ 2020-06-11 10:10:44 檢舉

非必要但是會做的話建議做
migrate跟git的目的差不多
是為了用來記錄資料表結構的所有變更紀錄
當之後出問題,也可以從記錄得知是做了什麼變更造成的

wrxue iT邦好手 1 級 ‧ 2020-06-11 13:28:16 檢舉

大概有個概念,細節只能等到遇到再說了!感謝

0
Victor
iT邦新手 2 級 ‧ 2020-06-10 10:58:20

Laravel 嗎?

  • migration 用於建立資料表結構schema
  • Seed 寫預設資料
  • controller 使用者寫入資料的邏輯程式碼
wrxue iT邦好手 1 級 ‧ 2020-06-10 10:59:16 檢舉

我這裡是使用golang

我要發表回答

立即登入回答