简体   繁体   中英

What is exactly Ecto Migration in Elixir?

Im from NodeJs/PHP background.

There you have a database ( i use MYSQL ) and a library to do sql queries in the database.

What is Ecto ? Is it like a Library wrapper for database in Elixr ?

And what are Migrations ? Why do i have to create Ecto Migrations when already i have created the database in MySQL ?

What is the recommended way to use mysql database from Elixr assuming i only have a mysql database created? (and configured the elixr phoenix and everything)

Eg. Databae example

Table thread

id | title

Table comment

id | text | thread_id

To keep it short, Ecto is a general data management library and a database wrapper.

The data management part (primarily realised through the Ecto.Changeset module) is independent of databases - it provides tools for dealing with data coming from external systems that need to be validated and converted to proper types.

The database wrapper part gives additional things over writing raw SQL - SQL injection protection, composition of queries and a richer type system.

The primary goal of migrations is to version the database - ie you have 3 developers and they all want to make a change to the database. Migrations allow automating this, they also make it easier to guarantee the production database and databases of each developer are the same - it's extremely hard and error prone when doing it all by hand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM