diff --git a/fix-db-permissions.sh b/fix-db-permissions.sh new file mode 100644 index 0000000..d54c69c --- /dev/null +++ b/fix-db-permissions.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +# Script to fix PostgreSQL permissions for schema creation +# This script reads DB_USER, DB_NAME, DB_HOST, and DB_PORT from .env and grants necessary permissions + +# Function to load .env file properly (handles comments and special characters) +load_env() { + if [ -f .env ]; then + # Read .env file line by line, skipping comments and empty lines + while IFS= read -r line || [ -n "$line" ]; do + # Skip comments and empty lines + [[ "$line" =~ ^[[:space:]]*# ]] && continue + [[ -z "${line// }" ]] && continue + + # Export variable if it contains = + if [[ "$line" =~ ^[[:space:]]*([^#=]+)=(.*)$ ]]; then + key="${BASH_REMATCH[1]%% *}" + value="${BASH_REMATCH[2]}" + # Remove leading/trailing whitespace and quotes + key=$(echo "$key" | xargs) + value=$(echo "$value" | sed -e 's/^["'\'']//' -e 's/["'\'']$//' | xargs) + export "$key=$value" + fi + done < .env + else + echo "Error: .env file not found" + exit 1 + fi +} + +# Load environment variables +load_env + +# Check if required variables are set +if [ -z "$DB_USER" ] || [ -z "$DB_NAME" ]; then + echo "Error: DB_USER or DB_NAME not set in .env file" + exit 1 +fi + +# Set defaults for host and port if not set +DB_HOST=${DB_HOST:-localhost} +DB_PORT=${DB_PORT:-5432} + +echo "Fixing PostgreSQL permissions for user: $DB_USER on database: $DB_NAME" +echo "Connecting to PostgreSQL at $DB_HOST:$DB_PORT" +echo "You will be prompted for the PostgreSQL superuser password (usually 'postgres')" +echo "" + +# Connect as postgres superuser and grant permissions +# Use -h for host and -p for port to force TCP/IP connection (password auth) +psql -h "$DB_HOST" -p "$DB_PORT" -U postgres -d postgres < Boolean) - @ApiPropertyOptional({ example: true }) - isActive?: boolean; } diff --git a/src/modules/icons/dto/create-icon.dto.ts b/src/modules/icons/dto/create-icon.dto.ts index 40ca410..5c06089 100644 --- a/src/modules/icons/dto/create-icon.dto.ts +++ b/src/modules/icons/dto/create-icon.dto.ts @@ -1,22 +1,11 @@ -import { IsString, IsOptional, IsBoolean } from 'class-validator'; -import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; +import { IsString } from 'class-validator'; +import { ApiProperty } from '@nestjs/swagger'; export class CreateIconDto { - @IsString() - @ApiProperty({ example: 'Facebook Icon' }) - name!: string; - @IsString() @ApiProperty({ example: 'https://example.com/icons/facebook.svg' }) url!: string; - @IsOptional() - @IsBoolean() - @Type(() => Boolean) - @ApiPropertyOptional({ example: true }) - isActive?: boolean; - @IsString() @ApiProperty({ example: 'group-id-here' }) groupId!: string; diff --git a/src/modules/icons/entities/group.entity.ts b/src/modules/icons/entities/group.entity.ts index 0cdcf3f..1208d0b 100644 --- a/src/modules/icons/entities/group.entity.ts +++ b/src/modules/icons/entities/group.entity.ts @@ -3,14 +3,10 @@ import { BaseEntity } from '../../../common/entities/base.entity'; import { Icon } from './icon.entity'; @Entity({ tableName: 'icon_groups' }) -@Index({ properties: ['isActive'] }) export class Group extends BaseEntity { @Property() name!: string; - @Property({ default: true }) - isActive: boolean = true; - @OneToMany(() => Icon, icon => icon.group) icons = new Collection(this); } diff --git a/src/modules/icons/entities/icon.entity.ts b/src/modules/icons/entities/icon.entity.ts index ea19569..f848d7a 100644 --- a/src/modules/icons/entities/icon.entity.ts +++ b/src/modules/icons/entities/icon.entity.ts @@ -3,18 +3,11 @@ import { BaseEntity } from '../../../common/entities/base.entity'; import { Group } from './group.entity'; @Entity({ tableName: 'icons' }) -@Index({ properties: ['isActive'] }) -@Index({ properties: ['group', 'isActive'] }) +@Index({ properties: ['group'] }) export class Icon extends BaseEntity { - @Property() - name!: string; - @Property() url!: string; - @Property({ default: true }) - isActive: boolean = true; - @ManyToOne(() => Group) group!: Group; } diff --git a/src/modules/icons/providers/group.service.ts b/src/modules/icons/providers/group.service.ts index b9983b6..173d0d9 100644 --- a/src/modules/icons/providers/group.service.ts +++ b/src/modules/icons/providers/group.service.ts @@ -17,7 +17,6 @@ export class GroupService { async create(dto: CreateGroupDto): Promise { const data: RequiredEntityData = { name: dto.name, - isActive: dto.isActive ?? true, }; const group = this.groupRepository.create(data); diff --git a/src/modules/icons/providers/icon.service.ts b/src/modules/icons/providers/icon.service.ts index a2c66d2..dd61046 100644 --- a/src/modules/icons/providers/icon.service.ts +++ b/src/modules/icons/providers/icon.service.ts @@ -22,9 +22,7 @@ export class IconService { } const data: RequiredEntityData = { - name: dto.name, url: dto.url, - isActive: dto.isActive ?? true, group: group, }; @@ -60,9 +58,7 @@ export class IconService { } this.em.assign(icon, { - name: dto.name, url: dto.url, - isActive: dto.isActive, }); await this.em.persistAndFlush(icon);