Is every DDL SQL command reversible? [database version control]

I want to configure a database schema change tracking mechanism, such as described in this answer :

For every change you make to the database, you write a new migration. Migrations usually have two methods: the up method, in which the changes are applied, and the down method, in which the changes are canceled. One command brings the database up to date, and can also be used for the database for a specific version of the schema.

My question is this: is all the DDL command in the up method reversible? In other words, can we always provide a down method? Can you imagine any DDL command that cannot be omitted?

Please do not take into account the typical problem of data migration when we lose data during the up method: for example, changing the field type from datetime( DateOfBirth) to int( YearOfBirth), we lose data that cannot be restored.

+3
source share
3 answers

in sql server, every DDL command that I know of is an up / down pair.

+4
source

Besides data loss, every migration I have ever done is reversible. However, Rails offers a way to mark migration as "destructive":

, . ActiveRecord:: down.

API .

+2

, , , , DROP COLUMN .

: SEQUENCE, . "" , 1. . , , , 1 , , , reset , , .

Any other DDL that depends on the state of the data in the database has similar problems. This is probably not a very good circuit design in the first place, I'm just trying to think of any cases that fit your question.

+2
source

Source: https://habr.com/ru/post/1697467/


All Articles