Skip to content

Commit

Permalink
fix: fix service start order when starting with docker compose
Browse files Browse the repository at this point in the history
  • Loading branch information
xmlking committed Apr 6, 2024
1 parent 301f260 commit 3fd2a7a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 26 deletions.
21 changes: 8 additions & 13 deletions apps/console/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,12 @@ nhost up --apply-seeds
| Dashboard | https://local.dashboard.nhost.run |
| Mailhog | https://local.mailhog.nhost.run |

#### Apply user schema
#### Apply seeds

> this step only needed first time when database got initialized
> got to `https://hasura.traefik.me/console/data/sql` and apply (un check: `This is a migration` )
Optionally apply all seed files

```sql
ALTER TABLE ONLY public.user_org_groups
ADD CONSTRAINT user_org_groups_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
```

TODO: After user record created for first-time (i.e., after user login), have admins assign `organization` and `groups` via Web UI:

```sql
INSERT INTO public.user_org_groups (id, user_id, groups, organization, created_at, created_by, updated_at, updated_by, deleted_at) VALUES ('271db270-6202-4c9a-82f8-7be326bf8be1', 'e9f249b0-5c86-446b-bb34-5cc24c1d398c', '{sig_admin,app_mgr}', 'chinthagunta', '2012-08-24 12:00:00+00', 'sumo@demo.com', '2024-03-13 06:47:14.718862+00','sumo@demo.com', NULL);
INSERT INTO public.user_org_groups (id, user_id, groups, organization, created_at, created_by, updated_at, updated_by, deleted_at) VALUES ('52b10e5f-77fb-4718-ac7e-a6960553dc50', 'e9f249b0-5c86-446b-bb34-5cc24c1d398c', '{aaa}', 'example', '2023-05-21 22:28:18.535229+00', 'sumo@demo.com', '2024-03-13 06:53:10.144137+00', 'sumo@demo.com', NULL);
```shell
hasura seed apply --database-name default --endpoint https://hasura.traefik.me --insecure-skip-tls-verify
```

### Frontend
Expand Down Expand Up @@ -174,3 +165,7 @@ You can preview the production build with `turbo preview`.
```shell
gcloud run deploy --allow-unauthenticated
```

## TODO

- After user record created for first-time (i.e., after user login), have admins assign `organization` and `groups` via Web UI:
4 changes: 4 additions & 0 deletions compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ services:
condition: service_healthy
graphql:
condition: service_healthy
auth:
condition: service_healthy
# storage:
# condition: service_healthy
extra_hosts:
- host.docker.internal:host-gateway
- auth${BASE_HOSTNAME}:host-gateway
Expand Down
4 changes: 2 additions & 2 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ services:
POSTGRES_DB: postgres
volumes:
- pg_data:/var/lib/postgresql/data
# - ./infra/base/postgres/initdb.d:/docker-entrypoint-initdb.d:ro
- ./infra/base/postgres/initdb.d:/docker-entrypoint-initdb.d:ro
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB -q']
interval: 60s
Expand Down Expand Up @@ -172,7 +172,7 @@ services:
# https://github.com/nhost/hasura-auth/blob/main/docs/environment-variables.md
###########################################################################
auth:
image: nhost/hasura-auth:0.28.0
image: nhost/hasura-auth:0.28.1
hostname: auth
container_name: auth
restart: unless-stopped
Expand Down
18 changes: 10 additions & 8 deletions docs/hasura.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ hasura version
hasura console

# Create a new seed by exporting data from tables already present in the database:
# use `--insecure-skip-tls-verify` if needed
hasura seed create devices --database-name default --from-table devices --endpoint https://hasura.traefik.me
hasura seed create pools --database-name default --from-table pools --endpoint https://hasura.traefik.me
hasura seed create rules --database-name default --from-table rules --endpoint https://hasura.traefik.me
hasura seed create policies --database-name default --from-table policies --endpoint https://hasura.traefik.me
hasura seed create users --database-name default --from-table auth.users --endpoint https://hasura.traefik.me --insecure-skip-tls-verify
hasura seed create user_roles --database-name default --from-table auth.user_roles --endpoint https://hasura.traefik.me --insecure-skip-tls-verify

# Export data from multiple tables:
# hasura seed create policies_organization --database-name default --from-table policies --from-table organization
# Apply only a particular file:
hasura seed apply --file 1_devices.sql --database-name default --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 2_rules.sql --database-name default --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 3_pools.sql --database-name default --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 4_policies.sql --database-name default --database-name default --endpoint https://hasura.traefik.me

# hasura seed apply --file 1684101975415_policies_organization.sql --database-name default

# Apply all seed file:
hasura seed apply --database-name default --endpoint https://hasura.traefik.me
# (Or) Apply only a particular files:
hasura seed apply --file 1_devices.sql --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 2_rules.sql --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 3_pools.sql --database-name default --endpoint https://hasura.traefik.me
hasura seed apply --file 4_policies.sql --database-name default --endpoint https://hasura.traefik.me

# To apply all the Migrations present in the `migrations/` directory and the Metadata present in the `metadata/` directory on a new, "fresh",
# instance of the Hasura Server at http://another-server-instance.hasura.app:
Expand Down
5 changes: 2 additions & 3 deletions nhost/migrations/default/1684206403640_init/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,5 @@ ALTER TABLE ONLY public.rules
ADD CONSTRAINT rules_protocol_fkey FOREIGN KEY (protocol) REFERENCES public.protocol(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public.user_org_groups
ADD CONSTRAINT user_org_groups_organization_fkey FOREIGN KEY (organization) REFERENCES public.organization(value) ON UPDATE RESTRICT ON DELETE RESTRICT;
-- run this manuvaly after all services started for the first time. because by the time `auth.users` may not be created yet.
-- ALTER TABLE ONLY public.user_org_groups
-- ADD CONSTRAINT user_org_groups_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
ALTER TABLE ONLY public.user_org_groups
ADD CONSTRAINT user_org_groups_user_id_fkey FOREIGN KEY (user_id) REFERENCES auth.users(id) ON UPDATE RESTRICT ON DELETE RESTRICT;
8 changes: 8 additions & 0 deletions nhost/seeds/default/0_users.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SET check_function_bodies = false;
INSERT INTO auth.users (id, created_at, updated_at, last_seen, disabled, display_name, avatar_url, locale, email, phone_number, password_hash, email_verified, phone_number_verified, new_email, otp_method_last_used, otp_hash, otp_hash_expires_at, default_role, is_anonymous, totp_secret, active_mfa_type, ticket, ticket_expires_at, metadata, webauthn_current_challenge) VALUES ('076a79f9-ed08-4e28-a4c3-8d4e0aa269a3', '2024-04-06 22:25:09.676552+00', '2024-04-06 22:48:21.002518+00', '2024-04-06 22:48:20.999+00', false, 'sumo demo', 'https://www.gravatar.com/avatar/74a8c22043d4dfc24342e8e30f39ab70?d=mp&r=g', 'en', 'sumo@demo.com', NULL, '$2a$10$5P/IQv/OmBK4cp9TPT6fPOFyAmqk6mH3jE4OoALvjf5n.T95ym2GC', false, false, NULL, NULL, NULL, '2024-04-06 22:25:09.676552+00', 'manager', false, NULL, NULL, NULL, '2024-04-06 22:25:09.675852+00', '{"org": "chinthagunta", "plan": "free"}', NULL);

INSERT INTO auth.user_roles (id, created_at, user_id, role) VALUES ('125a7851-d941-44f6-b5e2-35dfb8432123', '2024-04-06 22:25:09.676552+00', '076a79f9-ed08-4e28-a4c3-8d4e0aa269a3', 'me');
INSERT INTO auth.user_roles (id, created_at, user_id, role) VALUES ('7c66978f-2758-4049-8b5f-10d8c9b5365b', '2024-04-06 22:25:09.676552+00', '076a79f9-ed08-4e28-a4c3-8d4e0aa269a3', 'manager');

INSERT INTO public.user_org_groups (id, user_id, groups, organization, created_at, created_by, updated_at, updated_by, deleted_at) VALUES ('271db270-6202-4c9a-82f8-7be326bf8be1', '076a79f9-ed08-4e28-a4c3-8d4e0aa269a3', '{sig_admin,app_mgr}', 'chinthagunta', '2012-08-24 12:00:00+00', 'sumo@demo.com', '2024-03-13 06:47:14.718862+00','sumo@demo.com', NULL);
INSERT INTO public.user_org_groups (id, user_id, groups, organization, created_at, created_by, updated_at, updated_by, deleted_at) VALUES ('52b10e5f-77fb-4718-ac7e-a6960553dc50', '076a79f9-ed08-4e28-a4c3-8d4e0aa269a3', '{aaa}', 'example', '2023-05-21 22:28:18.535229+00', 'sumo@demo.com', '2024-03-13 06:53:10.144137+00', 'sumo@demo.com', NULL);

0 comments on commit 3fd2a7a

Please sign in to comment.