-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
rust/postgres/postgres/firststep
.
create dev environment.
- Loading branch information
1 parent
b9f93bc
commit 0e3c509
Showing
9 changed files
with
890 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# rust postgres firststep | ||
|
||
## Development | ||
|
||
### Start dev environment | ||
|
||
```sh | ||
docker compose up -d | ||
``` | ||
|
||
### Attach application container | ||
|
||
```sh | ||
docker compose exec app bash | ||
``` | ||
|
||
|
||
### Setup project | ||
|
||
```sh | ||
cargo init | ||
cargo add postgres --features="with-uuid-1" | ||
cargo add uuid | ||
``` | ||
|
||
### Run | ||
|
||
```sh | ||
cargo run | ||
``` | ||
|
||
## References | ||
|
||
- [postgres - crates.io: Rust Package Registry](https://crates.io/crates/postgres) | ||
- [postgres - Rust](https://docs.rs/postgres/latest/postgres/) | ||
- [Config in postgres::config - Rust](https://docs.rs/postgres/latest/postgres/config/struct.Config.html) | ||
|
3 changes: 3 additions & 0 deletions
3
rust/sql/postgres/postgres/firststep/conf/postgres/init.d/000_droptables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
DROP TABLE IF EXISTS "device"; | ||
DROP TABLE IF EXISTS "user"; | ||
|
10 changes: 10 additions & 0 deletions
10
rust/sql/postgres/postgres/firststep/conf/postgres/init.d/001_create_tables.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE "user" ( | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid() | ||
, name text NOT NULL | ||
); | ||
|
||
CREATE TABLE "device" ( | ||
id UUID PRIMARY KEY DEFAULT gen_random_uuid() | ||
, name text NOT NULL | ||
, user_id UUID REFERENCES "user"(id) | ||
); |
22 changes: 22 additions & 0 deletions
22
rust/sql/postgres/postgres/firststep/conf/postgres/init.d/101_create_test_data.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
INSERT INTO "user" (id, name) | ||
values | ||
('{d35696e8-5aa0-4b35-88cf-ded521b3dede}', 'user1') | ||
, ('{d35696e8-5aa0-4b35-88cf-ded521b3dedd}', 'user2') | ||
, ('{d35696e8-5aa0-4b35-88cf-ded521b3dedc}', 'user3') | ||
, ('{d35696e8-5aa0-4b35-88cf-ded521b3dedb}', 'user4') | ||
, ('{d35696e8-5aa0-4b35-88cf-ded521b3deda}', 'user5') | ||
; | ||
|
||
INSERT INTO "device" (id, name, user_id) | ||
values | ||
('{d35696e8-5aa0-4b35-98cf-ded521b3dede}', 'device11', '{d35696e8-5aa0-4b35-88cf-ded521b3dede}') | ||
, ('{d35696e8-5aa0-4b35-98cf-ded521b3dedd}', 'device12', '{d35696e8-5aa0-4b35-88cf-ded521b3dede}') | ||
, ('{d35696e8-5aa0-4b35-98cf-ded521b3dedc}', 'device13', '{d35696e8-5aa0-4b35-88cf-ded521b3dede}') | ||
, ('{d35696e8-5aa0-4b35-98cf-ded521b3dedb}', 'device14', '{d35696e8-5aa0-4b35-88cf-ded521b3dede}') | ||
, ('{d35696e8-5aa0-4b35-98cf-ded521b3deda}', 'device15', '{d35696e8-5aa0-4b35-88cf-ded521b3dede}') | ||
, ('{d35696e8-5aa0-4b35-a8cf-ded521b3dede}', 'device21', '{d35696e8-5aa0-4b35-88cf-ded521b3dedd}') | ||
, ('{d35696e8-5aa0-4b35-a8cf-ded521b3dedd}', 'device22', '{d35696e8-5aa0-4b35-88cf-ded521b3dedd}') | ||
, ('{d35696e8-5aa0-4b35-a8cf-ded521b3dedc}', 'device23', '{d35696e8-5aa0-4b35-88cf-ded521b3dedd}') | ||
, ('{d35696e8-5aa0-4b35-a8cf-ded521b3dedb}', 'device24', '{d35696e8-5aa0-4b35-88cf-ded521b3dedd}') | ||
, ('{d35696e8-5aa0-4b35-a8cf-ded521b3deda}', 'device25', '{d35696e8-5aa0-4b35-88cf-ded521b3dedd}') | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3' | ||
|
||
services: | ||
app: | ||
image: rust | ||
init: true | ||
environment: | ||
POSTGRES_HOST: "postgres:5432" | ||
POSTGRES_DB: "postgres" | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_PASSWORD: "password" | ||
command: | ||
- sleep | ||
- infinity | ||
volumes: | ||
- "./project:/project" | ||
working_dir: /project | ||
postgres: | ||
image: postgres:15 | ||
init: true | ||
restart: always | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data | ||
- ./conf/postgres/init.d/:/docker-entrypoint-initdb.d | ||
environment: | ||
POSTGRES_DB: "postgres" | ||
POSTGRES_USER: "postgres" | ||
POSTGRES_PASSWORD: "password" | ||
ports: | ||
- "0.0.0.0:5432:5432" | ||
|
||
volumes: | ||
postgres_data: | ||
driver: local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Oops, something went wrong.