-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathPostgresDbBuilder.cs
44 lines (38 loc) · 1.34 KB
/
PostgresDbBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
public static class PostgresDbBuilder
{
public static async Task Create(NpgsqlConnection connection)
{
await using var command = connection.CreateCommand();
command.CommandText =
"""
-- begin-snippet: PostgresSchema
create table IF NOT EXISTS public."Companies"
(
"Id" uuid not null
constraint "PK_Companies"
primary key,
"Content" text
);
alter table public."Companies"
owner to postgres;
create table IF NOT EXISTS public."Employees"
(
"Id" uuid not null
constraint "PK_Employees"
primary key,
"CompanyId" uuid not null
constraint "FK_Employees_Companies_CompanyId"
references public."Companies"
on delete cascade,
"Content" text,
"Age" integer not null
);
alter table public."Employees"
owner to postgres;
create index IF NOT EXISTS "IX_Employees_CompanyId"
on public."Employees" ("CompanyId");
-- end-snippet
""";
await command.ExecuteNonQueryAsync();
}
}