The post has been translated automatically. Original language: Russian
Topic
To change the database schema on an empty project is one line. Changing it on a running service with live users is a separate task, where an error costs several minutes of unavailability or lost data.
What is dangerous on large tables
Adding a column with a default value. In older versions of the DBMS, this is a rewrite of the entire table under lock. New ones are often safe, but you need to check your version.
Creating an index in the usual way. The table is locked for writing until the end of the operation. Almost everywhere there is an option with parallel construction, and it is needed.
Changing the column type. As a rule, it means a complete rewrite of the data.
Deleting or renaming a column at the same time as the code is being deployed. At the time of the rollout, some instances are running on the old version and accessing what is no longer there.
The fourth point is the most underestimated. The problem is not the migration itself, but the fact that the code and schema are not changing at the same time.
A multi-step deployment scheme
To rename a column, the sequence looks like this.
Add a new column without deleting anything.
Embed code that writes to both places and reads from the old one.
Fill in a new column for existing rows in batches rather than a single query.
Switch the reading to a new column and make sure everything is working.
Stop writing to the old one and only then delete it, in a separate release.
Five steps instead of one, but at each stage you can roll back and at no point is there an incompatibility between the code and the schema.
Rules that save nerves
Fill in data with batch files with pauses. One UPDATE of ten million rows creates a long transaction, bloats the log and interferes with the rest of the requests.
Set the timeout to lock. Migrations that couldn't take the lock quickly should drop instead of queuing up and stopping all traffic.
Check migration against copies of real data. On a test database of thousands of lines, everything is always fast.
Keep migrations reversible where possible, and know the rollback plan in advance if not.
Do not combine schema changes and logic changes in one release. If there is a problem, it will be unclear what to roll back.
The main thing
Secure migration is not about tricky SQL, but about the fact that the schema and code are always compatible in both directions. Once this condition is met, the deployment ceases to be an event that the team prepares for in the evening after the traffic.
Do you do migrations during business hours or still at night?
Электронная подпись заменяет подпись на бумаге. Работает она не так, как кажется на первый взгляд: подпись не рисуется на документе, а вычисляется из его содержимого.
У человека есть два связанных ключа. Один закрытый, он хранится только у владельца. Второй открытый, его можно передавать кому угодно.
Подписание выглядит так. Программа считает по документу короткий отпечаток, а затем обрабатывает этот отпечаток закрытым ключом. Результат и есть подпись.
Проверка идёт в обратном порядке. Получатель берёт документ, считает отпечаток заново и с помощью открытого ключа проверяет, совпадает ли он с тем, что содержится в подписи.
Из этого следует главное свойство. Подпись связана с конкретным содержанием документа. Изменилась одна цифра в сумме, отпечаток стал другим, и проверка это покажет.
Второе свойство касается принадлежности. Открытый ключ сам по себе не говорит, кому он принадлежит. Поэтому существуют удостоверяющие центры, которые подтверждают связь ключа и человека.
И третье, о чём часто забывают. Подпись имеет дату. Документ, подписанный сегодня, и тот же документ, подписанный год назад, различаются, и это важно для договоров.
Простыми словами электронная подпись отвечает на два вопроса: кто подписал и не менялось ли содержимое после подписания.
А в вашей работе документы согласуются электронной подписью или всё ещё на бумаге?