2021-12-03 17:34:24 +05:00
|
|
|
# Миграции
|
|
|
|
## создать миграцию
|
2021-09-13 09:39:11 +05:00
|
|
|
```
|
|
|
|
dotnet ef migrations add <MigrationName> --project AsbCloudDb
|
|
|
|
```
|
2021-12-03 17:34:24 +05:00
|
|
|
## откатить миграцию
|
2021-09-13 09:39:11 +05:00
|
|
|
```
|
|
|
|
dotnet ef migrations remvoe <MigrationName> --project AsbCloudDb
|
|
|
|
```
|
2021-12-03 17:34:24 +05:00
|
|
|
|
2021-09-13 09:39:11 +05:00
|
|
|
<MigrationName> - Name of migration class
|
2021-09-14 17:17:33 +05:00
|
|
|
После создания миграции обязательно прочитать сгенерированый код.
|
2021-09-13 09:39:11 +05:00
|
|
|
|
2021-12-03 17:34:24 +05:00
|
|
|
## Применить миграции
|
|
|
|
При старте проекта применяются автоматически
|
2021-09-10 11:28:57 +05:00
|
|
|
```
|
|
|
|
dotnet ef database update --project .\AsbCloudDb
|
2021-12-03 17:34:24 +05:00
|
|
|
```
|
2021-09-29 10:09:40 +05:00
|
|
|
|
2021-12-03 17:34:24 +05:00
|
|
|
# Backup
|
|
|
|
Terminal:
|
|
|
|
```
|
|
|
|
sudo -u postgres pg_dump -Fc -U postgres postgres -W > dump_2021-11-26.bak
|
|
|
|
```
|
2021-11-17 13:06:48 +05:00
|
|
|
|
2021-12-03 17:34:24 +05:00
|
|
|
# Restore backup
|
|
|
|
## Step 1. (Re)Create DB and schema IF needeed.
|
|
|
|
psql:
|
|
|
|
```
|
|
|
|
--drop schema public cascade;
|
|
|
|
CREATE DATABASE postgres;
|
|
|
|
\c postgres
|
|
|
|
create schema public;
|
|
|
|
```
|
|
|
|
|
|
|
|
## Step 2. Innit timescaledb and prepare DB to restore
|
|
|
|
```
|
|
|
|
CREATE EXTENSION IF NOT EXISTS timescaledb;
|
|
|
|
SELECT timescaledb_pre_restore();
|
|
|
|
```
|
|
|
|
## Step 3. Restore DB, then 'exit resore mode'. [Longest operation]
|
|
|
|
Terminal:
|
|
|
|
```
|
|
|
|
sudo -u postgres psql -p 5499 -U postgres postgres -W < dump_2021-11-26.bak
|
|
|
|
```
|
|
|
|
OR psql:
|
|
|
|
```
|
|
|
|
\! pg_restore -Fc -d postgres dump_2021-11-26.bak
|
|
|
|
```
|
|
|
|
Then psql:
|
|
|
|
```
|
|
|
|
SELECT timescaledb_post_restore();
|
|
|
|
```
|