-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance postgre sql setup script and documentation for various distros 7636 #7637
Changes from 2 commits
2f6e8f0
8ca06b1
c5294fa
e8d786b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ import { useCreateOneRelationMetadataItem } from '@/object-metadata/hooks/useCre | |
import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataItem'; | ||
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; | ||
import { useFindManyRecords } from '@/object-record/hooks/useFindManyRecords'; | ||
import { RecordFieldValueSelectorContextProvider } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext'; | ||
import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons'; | ||
|
@@ -30,6 +29,7 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; | |
import { H2Title } from 'twenty-ui'; | ||
import { z } from 'zod'; | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
import { defaultIconsByFieldType } from '~/pages/settings/data-model/constants/FieldTypeIcons'; | ||
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull'; | ||
|
||
type SettingsDataModelNewFieldFormValues = z.infer< | ||
|
@@ -48,7 +48,6 @@ export const SettingsObjectNewFieldConfigure = () => { | |
|
||
const { findActiveObjectMetadataItemBySlug } = | ||
useFilteredObjectMetadataItems(); | ||
|
||
const activeObjectMetadataItem = | ||
findActiveObjectMetadataItemBySlug(objectSlug); | ||
const { createMetadataField } = useFieldMetadataItem(); | ||
|
@@ -63,18 +62,15 @@ export const SettingsObjectNewFieldConfigure = () => { | |
), | ||
defaultValues: { | ||
type: fieldType, | ||
icon: 'IconUsers', | ||
icon: defaultIconsByFieldType[fieldType] || 'IconUsers', | ||
label: '', | ||
description: '', | ||
}, | ||
}); | ||
|
||
const fieldMetadataItem: Pick<FieldMetadataItem, 'icon' | 'label' | 'type'> = | ||
{ | ||
icon: formConfig.watch('icon'), | ||
label: formConfig.watch('label') || 'Employees', | ||
type: formConfig.watch('type'), | ||
}; | ||
useEffect(() => { | ||
formConfig.setValue('icon', defaultIconsByFieldType[fieldType] || 'IconUsers'); | ||
}, [fieldType, formConfig]); | ||
|
||
const [, setObjectViews] = useState<View[]>([]); | ||
const [, setRelationObjectViews] = useState<View[]>([]); | ||
|
@@ -209,7 +205,11 @@ export const SettingsObjectNewFieldConfigure = () => { | |
<H2Title title="Values" description="The values of this field" /> | ||
<SettingsDataModelFieldSettingsFormCard | ||
isCreatingField | ||
fieldMetadataItem={fieldMetadataItem} | ||
fieldMetadataItem={{ | ||
icon: formConfig.watch('icon'), | ||
label: formConfig.watch('label') || 'New Field', | ||
type: fieldType as FieldMetadataType, | ||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Ensure that fieldType is always a valid FieldMetadataType to avoid potential runtime errors |
||
objectMetadataItem={activeObjectMetadataItem} | ||
/> | ||
</Section> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { FieldMetadataType } from '~/generated-metadata/graphql'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dostavic what is this change about? |
||
|
||
export const defaultIconsByFieldType: Record<FieldMetadataType, string> = { | ||
[FieldMetadataType.Address]: 'IconLocation', | ||
[FieldMetadataType.Boolean]: 'IconCheckbox', | ||
[FieldMetadataType.Currency]: 'IconCurrency', | ||
[FieldMetadataType.Date]: 'IconCalendar', | ||
[FieldMetadataType.DateTime]: 'IconClock', | ||
[FieldMetadataType.FullName]: 'IconUser', | ||
[FieldMetadataType.MultiSelect]: 'IconList', | ||
[FieldMetadataType.Number]: 'IconNumber', | ||
[FieldMetadataType.Rating]: 'IconStar', | ||
[FieldMetadataType.RawJson]: 'IconCode', | ||
[FieldMetadataType.Relation]: 'IconRelationOneToMany', | ||
[FieldMetadataType.Select]: 'IconSelect', | ||
[FieldMetadataType.Text]: 'IconTypography', | ||
[FieldMetadataType.Uuid]: 'IconKey', | ||
[FieldMetadataType.Array]: 'IconCodeDots', | ||
[FieldMetadataType.Emails]: 'IconMail', | ||
[FieldMetadataType.Links]: 'IconLink', | ||
[FieldMetadataType.Phones]: 'IconPhone', | ||
[FieldMetadataType.Actor]: 'IconUsers', | ||
[FieldMetadataType.Numeric]: 'IconUsers', | ||
[FieldMetadataType.Position]: 'IconUsers', | ||
[FieldMetadataType.RichText]: 'IconUsers', | ||
[FieldMetadataType.TsVector]: 'IconUsers' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Consider using more specific icons for Numeric, Position, RichText, and TsVector field types instead of the generic IconUsers |
||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ handle_error () { | |
exit 1 | ||
} | ||
|
||
read -p "This script uses sudo to install postgresql, curl and change different settings, do you want to run this script? [y/N]" AGREEMENT | ||
read -p "This script uses sudo to install PostgreSQL, curl, and configure the system. Do you want to run this script? [y/N] " AGREEMENT | ||
|
||
if ! echo "$AGREEMENT" | grep -iq "^y"; then | ||
exit 1 | ||
|
@@ -55,28 +55,68 @@ echo_header $BLUE " DATABASE SETUP" | |
|
||
PG_MAIN_VERSION=15 | ||
PG_GRAPHQL_VERSION=1.5.6 | ||
TARGETARCH=$(dpkg --print-architecture) | ||
|
||
# Install PostgresSQL | ||
echo_header $GREEN "Step [1/4]: Installing PostgreSQL..." | ||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null | ||
sudo apt update -y || handle_error "Failed to update package list." | ||
sudo apt install -y postgresql-$PG_MAIN_VERSION postgresql-contrib-$PG_MAIN_VERSION || handle_error "Failed to install PostgreSQL." | ||
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..." | ||
curl -L https://github.com/supabase/pg_graphql/releases/download/v$PG_GRAPHQL_VERSION/pg_graphql-v$PG_GRAPHQL_VERSION-pg$PG_MAIN_VERSION-$TARGETARCH-linux-gnu.deb -o pg_graphql.deb || handle_error "Failed to download pg_graphql package." | ||
sudo dpkg --install pg_graphql.deb || handle_error "Failed to install pg_graphql package." | ||
rm pg_graphql.deb | ||
|
||
# Start postgresql service | ||
echo_header $GREEN "Step [3/4]: Starting PostgreSQL service..." | ||
if sudo service postgresql start; then | ||
echo "PostgreSQL service started successfully." | ||
|
||
if command -v dpkg &> /dev/null; then | ||
TARGETARCH=$(dpkg --print-architecture) | ||
else | ||
TARGETARCH=$(uname -m) | ||
fi | ||
|
||
# Detect package manager and set up PostgreSQL and curl | ||
if command -v dpkg &> /dev/null; then | ||
PACKAGE_MANAGER="dpkg" | ||
elif command -v pacman &> /dev/null; then | ||
PACKAGE_MANAGER="pacman" | ||
else | ||
handle_error "Failed to start PostgreSQL service." | ||
handle_error "Unsupported package manager. This script only supports dpkg and pacman." | ||
fi | ||
|
||
# Installation for Debian/Ubuntu | ||
if [ "$PACKAGE_MANAGER" = "dpkg" ]; then | ||
echo_header $GREEN "Step [1/4]: Installing PostgreSQL on Debian/Ubuntu..." | ||
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
wget -qO- https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo tee /etc/apt/trusted.gpg.d/pgdg.asc &>/dev/null | ||
sudo apt update -y || handle_error "Failed to update package list." | ||
sudo apt install -y postgresql-$PG_MAIN_VERSION postgresql-contrib-$PG_MAIN_VERSION curl || handle_error "Failed to install PostgreSQL or curl." | ||
|
||
echo_header $GREEN "Step [2/4]: Installing GraphQL for PostgreSQL on Debian/Ubuntu..." | ||
curl -L https://github.com/supabase/pg_graphql/releases/download/v$PG_GRAPHQL_VERSION/pg_graphql-v$PG_GRAPHQL_VERSION-pg$PG_MAIN_VERSION-$TARGETARCH-linux-gnu.deb -o pg_graphql.deb || handle_error "Failed to download pg_graphql package." | ||
sudo dpkg --install pg_graphql.deb || handle_error "Failed to install pg_graphql package." | ||
rm pg_graphql.deb | ||
|
||
echo_header $GREEN "Step [3/4]: Starting PostgreSQL service..." | ||
if sudo service postgresql start; then | ||
echo "PostgreSQL service started successfully." | ||
else | ||
handle_error "Failed to start PostgreSQL service." | ||
fi | ||
|
||
# Installation for Arch | ||
elif [ "$PACKAGE_MANAGER" = "pacman" ]; then | ||
echo_header $GREEN "Step [1/4]: Installing PostgreSQL on Arch..." | ||
sudo pacman -Syu --noconfirm || handle_error "Failed to update package list." | ||
sudo pacman -S postgresql postgresql-libs curl --noconfirm || handle_error "Failed to install PostgreSQL or curl." | ||
|
||
echo_header $GREEN "Step [2/4]: Installing GraphQL for PostgreSQL on Arch..." | ||
if ! yay -S --noconfirm pg_graphql; then | ||
handle_error "Failed to install pg_graphql package from AUR." | ||
fi | ||
Comment on lines
+101
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The script assumes 'yay' is installed for Arch Linux, but doesn't check for its presence or provide an alternative. This could cause issues for users without yay. |
||
|
||
echo_header $GREEN "Step [3/4]: Initializing and starting PostgreSQL service..." | ||
if sudo -u postgres sh -c 'test "$(ls -A /var/lib/postgres/data 2>/dev/null)"'; then | ||
echo "PostgreSQL data directory already contains data. Skipping initdb." | ||
else | ||
sudo -iu postgres initdb --locale en_US.UTF-8 -D /var/lib/postgres/data || handle_error "Failed to initialize PostgreSQL database." | ||
fi | ||
Comment on lines
+106
to
+110
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: The indentation for the 'else' block is incorrect, which could lead to readability issues. |
||
|
||
if [ "$(ps -p 1 -o comm=)" = "systemd" ]; then | ||
sudo systemctl enable postgresql | ||
sudo systemctl start postgresql || handle_error "Failed to start PostgreSQL service." | ||
else | ||
sudo mkdir -p /run/postgresql | ||
sudo chown postgres:postgres /run/postgresql | ||
sudo -iu postgres pg_ctl -D /var/lib/postgres/data -l /var/lib/postgres/logfile start || handle_error "Failed to start PostgreSQL service." | ||
fi | ||
fi | ||
|
||
# Run the init.sql to setup database | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding a dependency array to this useEffect to prevent unnecessary re-renders