From 986082d7a7cc2a50d4bdf7020b608af2f3aca852 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Sat, 14 Oct 2023 22:40:05 +0200 Subject: [PATCH] Complete win script setup --- .../frontend/basics/folder-architecture.mdx | 2 ++ .../contributor/local-setup/yarn-setup.mdx | 4 ++-- infra/dev/postgres/init.sql | 24 +++++-------------- infra/dev/scripts/setup-database.sh | 9 +++---- server/scripts/setup-db.ts | 5 ++++ 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/docs/docs/contributor/frontend/basics/folder-architecture.mdx b/docs/docs/contributor/frontend/basics/folder-architecture.mdx index a8123edf8..f5e7bd7bc 100644 --- a/docs/docs/contributor/frontend/basics/folder-architecture.mdx +++ b/docs/docs/contributor/frontend/basics/folder-architecture.mdx @@ -6,6 +6,8 @@ sidebar_custom_props: icon: TbFolder --- +# Folder Architecture + In this guide, you will explore the details of the project directory structure and how it contributes to the organization and maintainability of Twenty. By following this folder architecture convention, it is easier to find the files related to specific features and ensure that the application is scalable and maintainable. diff --git a/docs/docs/contributor/local-setup/yarn-setup.mdx b/docs/docs/contributor/local-setup/yarn-setup.mdx index e9ee52c67..dd27a96b4 100644 --- a/docs/docs/contributor/local-setup/yarn-setup.mdx +++ b/docs/docs/contributor/local-setup/yarn-setup.mdx @@ -60,7 +60,7 @@ This database needs to be provisionned with the a `twenty` user (password: `twen ```bash cd twenty -sh ./infra/dev/scripts/setup-database.sh +./infra/dev/scripts/setup-database.sh ``` Option 2: Alternatively if you have docker installed: @@ -89,7 +89,7 @@ You can access them using `twenty` postgres user (password: `twenty`) We recommend to provision your database locally: ```bash cd twenty -sh ./infra/dev/scripts/setup-database.sh +./infra/dev/scripts/setup-database.sh ``` This will create a Docker container, exposing a PostgresSQL instance at [http://localhost:5432](http://localhost:5432). You can access them using `twenty` postgres user (password: `twenty`) diff --git a/infra/dev/postgres/init.sql b/infra/dev/postgres/init.sql index 6e5442864..0949eafc5 100644 --- a/infra/dev/postgres/init.sql +++ b/infra/dev/postgres/init.sql @@ -1,22 +1,10 @@ --- Create table "default" for local setup without docker SELECT 'CREATE DATABASE "default"' -WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'default')\gexec +WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'default'); + +SELECT 'CREATE DATABASE "test"' +WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = 'test'); --- Create user "twenty" for local setup without docker SELECT 'CREATE USER twenty PASSWORD ''twenty''' -WHERE NOT EXISTS (SELECT FROM pg_user WHERE usename = 'twenty')\gexec +WHERE NOT EXISTS (SELECT FROM pg_user WHERE usename = 'twenty'); --- Inflect names for pg_graphql -COMMENT ON SCHEMA "public" IS '@graphql({"inflect_names": true})'; - --- Connect to the "default" database -\c "default"; - --- Create extension uuid-ossp -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; - --- Create the tests database for e2e testing -CREATE DATABASE "test"; - --- Connect to the "test" database for e2e testing -\c "test"; +ALTER ROLE twenty superuser; diff --git a/infra/dev/scripts/setup-database.sh b/infra/dev/scripts/setup-database.sh index 69e98e0c8..279c08249 100644 --- a/infra/dev/scripts/setup-database.sh +++ b/infra/dev/scripts/setup-database.sh @@ -53,9 +53,9 @@ TARGETARCH=$(dpkg --print-architecture) # Install PostgresSQL echo_header $GREEN "Step [1/4]: Installing PostgreSQL..." -apt update -y || handle_error "Failed to update package list." -apt install -y postgresql-$PG_MAIN_VERSION postgresql-contrib || handle_error "Failed to install PostgreSQL." -apt install -y curl || handle_error "Failed to install curl." +sudo apt update -y || handle_error "Failed to update package list." +sudo apt install -y postgresql-$PG_MAIN_VERSION postgresql-contrib || handle_error "Failed to install PostgreSQL."su +sudo apt install -y curl || handle_error "Failed to install curl." # Install pg_graphql extensions echo_header $GREEN "Step [2/4]: Installing GraphQL for PostgreSQL..." @@ -73,4 +73,5 @@ fi # Run the init.sql to setup database echo_header $GREEN "Step [4/4]: Setting up database..." -sudo -u postgres psql -f ../postgres/init.sql || handle_error "Failed to execute init.sql script." +cp ./infra/dev/postgres/init.sql /tmp/init.sql +sudo -u postgres psql -f /tmp/init.sql || handle_error "Failed to execute init.sql script." diff --git a/server/scripts/setup-db.ts b/server/scripts/setup-db.ts index 283f6b6c0..11a4dec06 100644 --- a/server/scripts/setup-db.ts +++ b/server/scripts/setup-db.ts @@ -41,6 +41,11 @@ connectionSource 'create extension "uuid-ossp"', ); + await performQuery( + `COMMENT ON SCHEMA "public" IS '@graphql({"inflect_names": true})';`, + 'inflect names for graphql', + ); + await performQuery( ` DROP FUNCTION IF EXISTS graphql;