update module icon
This commit is contained in:
@@ -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 <<EOF
|
||||||
|
-- Grant usage on the database
|
||||||
|
GRANT CONNECT ON DATABASE $DB_NAME TO $DB_USER;
|
||||||
|
|
||||||
|
-- Grant usage on the public schema
|
||||||
|
GRANT USAGE ON SCHEMA public TO $DB_USER;
|
||||||
|
|
||||||
|
-- Grant create privileges on the public schema
|
||||||
|
GRANT CREATE ON SCHEMA public TO $DB_USER;
|
||||||
|
|
||||||
|
-- Grant all privileges on all tables in public schema (current and future)
|
||||||
|
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO $DB_USER;
|
||||||
|
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO $DB_USER;
|
||||||
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $DB_USER;
|
||||||
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $DB_USER;
|
||||||
|
|
||||||
|
-- For PostgreSQL 15+
|
||||||
|
GRANT ALL ON DATABASE $DB_NAME TO $DB_USER;
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo ""
|
||||||
|
echo "✓ Permissions granted successfully!"
|
||||||
|
echo "You can now run: npm run db:create"
|
||||||
|
else
|
||||||
|
echo ""
|
||||||
|
echo "✗ Failed to grant permissions. Please check the error above."
|
||||||
|
echo ""
|
||||||
|
echo "Alternative: You can run the SQL commands manually:"
|
||||||
|
echo " psql -h $DB_HOST -p $DB_PORT -U postgres -d postgres"
|
||||||
|
echo " Then execute the GRANT commands from fix-db-permissions.sql"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
-- Fix PostgreSQL permissions for schema creation
|
||||||
|
-- Run this script as a PostgreSQL superuser (usually 'postgres')
|
||||||
|
--
|
||||||
|
-- Option 1: Run with psql (replace dmenuuser and dmenutest with your values):
|
||||||
|
-- psql -U postgres -d postgres -f fix-db-permissions.sql
|
||||||
|
--
|
||||||
|
-- Option 2: Run with sudo (no password needed):
|
||||||
|
-- sudo -u postgres psql -d postgres -f fix-db-permissions.sql
|
||||||
|
--
|
||||||
|
-- Option 3: Copy and paste these commands into psql after connecting
|
||||||
|
|
||||||
|
-- Replace 'dmenuuser' and 'dmenutest' with your actual DB_USER and DB_NAME from .env
|
||||||
|
-- Current values from your .env: DB_USER=dmenuuser, DB_NAME=dmenutest
|
||||||
|
--
|
||||||
|
-- IMPORTANT: For PostgreSQL 15+, we need to make the user the owner of the database and schema
|
||||||
|
|
||||||
|
-- Make the user the owner of the database (PostgreSQL 15+ requirement)
|
||||||
|
ALTER DATABASE dmenutest OWNER TO dmenuuser;
|
||||||
|
|
||||||
|
-- Connect to the target database (run this in psql, then continue with schema commands)
|
||||||
|
-- \c dmenutest
|
||||||
|
|
||||||
|
-- Make the user the owner of the public schema (PostgreSQL 15+ requirement)
|
||||||
|
ALTER SCHEMA public OWNER TO dmenuuser;
|
||||||
|
|
||||||
|
-- Grant all necessary permissions (redundant but safe)
|
||||||
|
GRANT CONNECT ON DATABASE dmenutest TO dmenuuser;
|
||||||
|
GRANT USAGE ON SCHEMA public TO dmenuuser;
|
||||||
|
GRANT CREATE ON SCHEMA public TO dmenuuser;
|
||||||
|
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO dmenuuser;
|
||||||
|
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO dmenuuser;
|
||||||
|
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO dmenuuser;
|
||||||
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO dmenuuser;
|
||||||
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO dmenuuser;
|
||||||
|
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO dmenuuser;
|
||||||
|
|
||||||
|
-- For PostgreSQL 15+ - ensure full database access
|
||||||
|
GRANT ALL ON DATABASE dmenutest TO dmenuuser;
|
||||||
|
|
||||||
@@ -1,16 +1,9 @@
|
|||||||
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
|
|
||||||
export class CreateGroupDto {
|
export class CreateGroupDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({ example: 'Social Media' })
|
@ApiProperty({ example: 'Social Media' })
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
@Type(() => Boolean)
|
|
||||||
@ApiPropertyOptional({ example: true })
|
|
||||||
isActive?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,11 @@
|
|||||||
import { IsString, IsOptional, IsBoolean } from 'class-validator';
|
import { IsString } from 'class-validator';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
|
||||||
|
|
||||||
export class CreateIconDto {
|
export class CreateIconDto {
|
||||||
@IsString()
|
|
||||||
@ApiProperty({ example: 'Facebook Icon' })
|
|
||||||
name!: string;
|
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({ example: 'https://example.com/icons/facebook.svg' })
|
@ApiProperty({ example: 'https://example.com/icons/facebook.svg' })
|
||||||
url!: string;
|
url!: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
@Type(() => Boolean)
|
|
||||||
@ApiPropertyOptional({ example: true })
|
|
||||||
isActive?: boolean;
|
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@ApiProperty({ example: 'group-id-here' })
|
@ApiProperty({ example: 'group-id-here' })
|
||||||
groupId!: string;
|
groupId!: string;
|
||||||
|
|||||||
@@ -3,14 +3,10 @@ import { BaseEntity } from '../../../common/entities/base.entity';
|
|||||||
import { Icon } from './icon.entity';
|
import { Icon } from './icon.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'icon_groups' })
|
@Entity({ tableName: 'icon_groups' })
|
||||||
@Index({ properties: ['isActive'] })
|
|
||||||
export class Group extends BaseEntity {
|
export class Group extends BaseEntity {
|
||||||
@Property()
|
@Property()
|
||||||
name!: string;
|
name!: string;
|
||||||
|
|
||||||
@Property({ default: true })
|
|
||||||
isActive: boolean = true;
|
|
||||||
|
|
||||||
@OneToMany(() => Icon, icon => icon.group)
|
@OneToMany(() => Icon, icon => icon.group)
|
||||||
icons = new Collection<Icon>(this);
|
icons = new Collection<Icon>(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,11 @@ import { BaseEntity } from '../../../common/entities/base.entity';
|
|||||||
import { Group } from './group.entity';
|
import { Group } from './group.entity';
|
||||||
|
|
||||||
@Entity({ tableName: 'icons' })
|
@Entity({ tableName: 'icons' })
|
||||||
@Index({ properties: ['isActive'] })
|
@Index({ properties: ['group'] })
|
||||||
@Index({ properties: ['group', 'isActive'] })
|
|
||||||
export class Icon extends BaseEntity {
|
export class Icon extends BaseEntity {
|
||||||
@Property()
|
|
||||||
name!: string;
|
|
||||||
|
|
||||||
@Property()
|
@Property()
|
||||||
url!: string;
|
url!: string;
|
||||||
|
|
||||||
@Property({ default: true })
|
|
||||||
isActive: boolean = true;
|
|
||||||
|
|
||||||
@ManyToOne(() => Group)
|
@ManyToOne(() => Group)
|
||||||
group!: Group;
|
group!: Group;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ export class GroupService {
|
|||||||
async create(dto: CreateGroupDto): Promise<Group> {
|
async create(dto: CreateGroupDto): Promise<Group> {
|
||||||
const data: RequiredEntityData<Group> = {
|
const data: RequiredEntityData<Group> = {
|
||||||
name: dto.name,
|
name: dto.name,
|
||||||
isActive: dto.isActive ?? true,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const group = this.groupRepository.create(data);
|
const group = this.groupRepository.create(data);
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ export class IconService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data: RequiredEntityData<Icon> = {
|
const data: RequiredEntityData<Icon> = {
|
||||||
name: dto.name,
|
|
||||||
url: dto.url,
|
url: dto.url,
|
||||||
isActive: dto.isActive ?? true,
|
|
||||||
group: group,
|
group: group,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,9 +58,7 @@ export class IconService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.em.assign(icon, {
|
this.em.assign(icon, {
|
||||||
name: dto.name,
|
|
||||||
url: dto.url,
|
url: dto.url,
|
||||||
isActive: dto.isActive,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.em.persistAndFlush(icon);
|
await this.em.persistAndFlush(icon);
|
||||||
|
|||||||
Reference in New Issue
Block a user