Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/andr-ll/pgsql_templates

A collection of sql scripts for PostgreSQL database. Includes migration script which populates db with fake data.
https://github.com/andr-ll/pgsql_templates

Last synced: 22 days ago
JSON representation

A collection of sql scripts for PostgreSQL database. Includes migration script which populates db with fake data.

Awesome Lists containing this project

README

        

# pgsql_templates

[![License][license-pic]][license-url]

A collection of `sql` scripts for `PostgreSQL` database.

Includes migration script which populates db with fake data: 10000 user entities and 100 posts per user.

There is fake person data used only.

During user creation random names are taken from [main.random_name()](./create/function/random_name.sql) function
and user `last_name` is a random string (mixed upper and lower cases) generated by [main.random_chars()](./create/function/random_chars.sql).

All values can be customized by adjusting `sql` scripts.

## Fake db usage

> **Note**
>
> For running migrations [docker-compose](https://docs.docker.com/compose/install/) is required to be installed.

1. Open terminal and run `docker-compose up` to see all outputs or `docker-compose up -d` with daemon mode.
2. Wait for a wile until migration is completed (you can check logs by running `docker logs -f pg_migration`).
3. Connect to `PostgreSQL` ([using default credentials](./docker-compose.yml)) with any client ([cli](https://wiki.postgresql.org/wiki/PostgreSQL_Clients#CLI_Clients), [gui](https://wiki.postgresql.org/wiki/PostgreSQL_Clients#Cross-platform_GUI_Clients), [web](https://wiki.postgresql.org/wiki/PostgreSQL_Clients#Web_Clients)) and try to query for `user` or `post`:

```sql
SELECT u.name, u.last_name FROM main.user AS u LIMIT 10;

SELECT p.user_id, p.title FROM main.post AS p LIMIT 10;

SELECT
u.id,
u.name,
to_jsonb(array_agg(p.title))
FROM
main.user AS u
JOIN main.post AS p
ON p.user_id = u.id
GROUP BY
u.id
LIMIT
10;
```

[license-pic]: https://img.shields.io/github/license/andr-ii/nuti?color=blue&label=%C2%A9%20license
[license-url]: https://github.com/andr-ii/nuti/blob/master/LICENSE