Parcourir la source

cosmetic fixes

root il y a 3 mois
Parent
commit
420baf876a

+ 8 - 0
docs/databases/checkDBschema.pl

@@ -92,6 +92,7 @@ sub get_schema {
         for my $col (keys %cols) {
         for my $col (keys %cols) {
             my $info = $cols{$col};
             my $info = $cols{$col};
             $schema{$table}{$col} = {
             $schema{$table}{$col} = {
+                name     => $info->{name} // '',
                 type     => $info->{type}     // '',
                 type     => $info->{type}     // '',
                 nullable => $info->{nullable} // 1,
                 nullable => $info->{nullable} // 1,
                 default  => normalize_default($info->{default}, $db_type),
                 default  => normalize_default($info->{default}, $db_type),
@@ -126,6 +127,13 @@ for my $table (keys %clear_schema) {
             $has_critical_error = 1;
             $has_critical_error = 1;
             next;
             next;
         }
         }
+        my $clean_name = $clear_schema{$table}{$col}{name} // '';
+        my $work_name  = $work_schema{$table}{$col}{name} // '';
+        if ($clean_name ne $work_name) {
+            print "❗ ERROR: Column '$col' in table '$table' has different name case:\n";
+            print "      Clean: '$clean_name', Working: '$work_name'\n";
+            $has_critical_error = 1;
+        }
 
 
         # === Сравнение типов ===
         # === Сравнение типов ===
         my $clean_type = $clear_schema{$table}{$col}{type} // '';
         my $clean_type = $clear_schema{$table}{$col}{type} // '';

+ 22 - 3
docs/databases/checkDBschema.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
-# Eye Migration Script for ALT Linux/Debian/Ubuntu with PostgreSQL support
-# Version: 2.1
+# Eye Script validating current DB schema for ALT Linux/Debian/Ubuntu with PostgreSQL support
+# Version: 1.0
 
 
 # set -e
 # set -e
 
 
@@ -175,12 +175,21 @@ setup_mysql() {
         fi
         fi
     fi
     fi
 
 
-    print_info "Importing database structure..."
+    # === Проверка: существует ли база данных? ===
+    if mysql $MYSQL_OPT -sN -e "SHOW DATABASES;" | grep -q "^${DB_TEST}$"; then
+        print_error "Database '$DB_TEST' already exists. The script has been stopped."
+        exit 120
+        fi
+
+    print_info "Creating database..."
 
 
     # Import main SQL file
     # Import main SQL file
     mysql $MYSQL_OPT <<EOF
     mysql $MYSQL_OPT <<EOF
 CREATE DATABASE IF NOT EXISTS ${DB_TEST} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 CREATE DATABASE IF NOT EXISTS ${DB_TEST} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 EOF
 EOF
+
+    print_info "Importing database structure..."
+
     mysql $MYSQL_OPT ${DB_TEST} < ${SQL_CREATE_FILE}
     mysql $MYSQL_OPT ${DB_TEST} < ${SQL_CREATE_FILE}
 
 
     if [[ $? -ne 0 ]]; then
     if [[ $? -ne 0 ]]; then
@@ -227,6 +236,12 @@ setup_postgresql() {
         LC_TYPE="en_US.UTF-8"
         LC_TYPE="en_US.UTF-8"
     fi
     fi
 
 
+    # === Проверка: существует ли БД? ===
+    if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw "^\s*${DB_TEST}\s*$"; then
+        print_error "Database '$DB_TEST' already exists. The script has been stopped."
+        exit 120
+        fi
+
     print_info "Creating database '$DB_TEST' with locale '$LC_TYPE'..."
     print_info "Creating database '$DB_TEST' with locale '$LC_TYPE'..."
 
 
     sudo -u postgres createdb \
     sudo -u postgres createdb \
@@ -352,6 +367,10 @@ install_clear_db() {
 # Function to display help
 # Function to display help
 show_help() {
 show_help() {
     echo "Usage: $0"
     echo "Usage: $0"
+    echo "\tThe script checks the correctness of the working database structure."
+    echo "\tTo do this, it creates a new empty database with a reference structure,"
+    echo "\tand then compares the two databases. "
+    echo "\tThe name of the test database is formed from the name of the working database with _test appended to it."
     echo ""
     echo ""
     echo "Options:"
     echo "Options:"
     echo "  --help, -h     Show this help"
     echo "  --help, -h     Show this help"

+ 7 - 1
docs/databases/migrate2psql.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 # Eye Migration Script for ALT Linux/Debian/Ubuntu with PostgreSQL support
 # Eye Migration Script for ALT Linux/Debian/Ubuntu with PostgreSQL support
-# Version: 2.1
+# Version: 1.0
 
 
 # set -e
 # set -e
 
 
@@ -271,6 +271,12 @@ local   all             postgres                                peer\
         LC_TYPE="en_US.UTF-8"
         LC_TYPE="en_US.UTF-8"
     fi
     fi
 
 
+    # === Проверка: существует ли БД? ===
+    if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw "^\s*${DB_NAME}\s*$"; then
+        print_error "Database '$DB_NAME' already exists. The script has been stopped."
+        exit 120
+        fi
+
     print_info "Creating database '$DB_NAME' with locale '$LC_TYPE'..."
     print_info "Creating database '$DB_NAME' with locale '$LC_TYPE'..."
 
 
     # Set password for stat user
     # Set password for stat user

+ 1 - 1
html/inc/common.php

@@ -2205,7 +2205,7 @@ function print_device_port_select($db, $field_name, $device_id, $target_id)
     $target_id = (int)$target_id;
     $target_id = (int)$target_id;
     
     
     $dpSQL = "
     $dpSQL = "
-    SELECT d.device_name,dp.port,dp.device_id,dp.id,dp.ifName
+    SELECT d.device_name,dp.port,dp.device_id,dp.id,dp.ifname
     FROM devices d
     FROM devices d
     JOIN device_ports dp
     JOIN device_ports dp
         ON dp.device_id = d.id
         ON dp.device_id = d.id

+ 35 - 11
install-eye.sh

@@ -1,6 +1,6 @@
 #!/bin/bash
 #!/bin/bash
 # Eye Installation Script for ALT Linux/Debian/Ubuntu with PostgreSQL support
 # Eye Installation Script for ALT Linux/Debian/Ubuntu with PostgreSQL support
-# Version: 2.1
+# Version: 1.0
 
 
 # set -e
 # set -e
 
 
@@ -767,12 +767,28 @@ setup_mysql() {
     # Generate password for db user
     # Generate password for db user
     DB_PASS=$(pwgen 16 1)
     DB_PASS=$(pwgen 16 1)
 
 
-    print_info "Importing database structure..."
+    # === Проверка: существует ли база данных? ===
+    if mysql $MYSQL_OPT -sN -e "SHOW DATABASES;" | grep -q "^${DB_NAME}$"; then
+        print_error "Database '$DB_NAME' already exists. The script has been stopped."
+        exit 120
+        fi
+
+    print_info "Create database..."
 
 
     # Import main SQL file
     # Import main SQL file
     mysql $MYSQL_OPT <<EOF
     mysql $MYSQL_OPT <<EOF
 CREATE DATABASE IF NOT EXISTS ${DB_NAME} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 CREATE DATABASE IF NOT EXISTS ${DB_NAME} DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
 EOF
 EOF
+    if [[ $? -ne 0 ]]; then
+        print_error "Error creating database ${DB_NAME}"
+        if [[ -f "$MYSQL_CNF_FILE" ]]; then
+            rm -f "$MYSQL_CNF_FILE"
+        fi
+        exit 121
+    fi
+
+    print_info "Importing database structure..."
+
     mysql $MYSQL_OPT ${DB_NAME} < ${SQL_CREATE_FILE}
     mysql $MYSQL_OPT ${DB_NAME} < ${SQL_CREATE_FILE}
 
 
     if [[ $? -ne 0 ]]; then
     if [[ $? -ne 0 ]]; then
@@ -780,7 +796,7 @@ EOF
         if [[ -f "$MYSQL_CNF_FILE" ]]; then
         if [[ -f "$MYSQL_CNF_FILE" ]]; then
             rm -f "$MYSQL_CNF_FILE"
             rm -f "$MYSQL_CNF_FILE"
         fi
         fi
-        return 1
+        exit 122
     fi
     fi
 
 
     print_info "Database structure imported"
     print_info "Database structure imported"
@@ -790,7 +806,8 @@ EOF
     mysql $MYSQL_OPT ${DB_NAME} < ${SQL_DATA_FILE}
     mysql $MYSQL_OPT ${DB_NAME} < ${SQL_DATA_FILE}
 
 
     if [[ $? -ne 0 ]]; then
     if [[ $? -ne 0 ]]; then
-        print_warn "Error importing data.sql (data may already exist)"
+        print_error "Error importing data.sql !!!"
+        exit 123
     else
     else
         print_info "Initial data imported"
         print_info "Initial data imported"
     fi
     fi
@@ -808,7 +825,7 @@ EOF
         if [[ -f "$MYSQL_CNF_FILE" ]]; then
         if [[ -f "$MYSQL_CNF_FILE" ]]; then
             rm -f "$MYSQL_CNF_FILE"
             rm -f "$MYSQL_CNF_FILE"
         fi
         fi
-        return 1
+        exit 124
     fi
     fi
 
 
     print_info "User $DB_USER successfully created"
     print_info "User $DB_USER successfully created"
@@ -871,9 +888,15 @@ local   all             postgres                                peer\
     # Check PostgreSQL access
     # Check PostgreSQL access
     if ! command -v psql &> /dev/null; then
     if ! command -v psql &> /dev/null; then
         print_error "PostgreSQL client not installed"
         print_error "PostgreSQL client not installed"
-        return 1
+        exit 110
     fi
     fi
 
 
+    # === Проверка: существует ли БД? ===
+    if sudo -u postgres psql -lqt | cut -d \| -f 1 | grep -qw "^\s*${DB_NAME}\s*$"; then
+        print_error "Database '$DB_NAME' already exists. The script has been stopped."
+        exit 120
+        fi
+
     # Спросить, создавать ли БД
     # Спросить, создавать ли БД
     read -p "Create database and user for Eye? (y/n): " -n 1 -r
     read -p "Create database and user for Eye? (y/n): " -n 1 -r
     echo
     echo
@@ -914,7 +937,7 @@ local   all             postgres                                peer\
 
 
     if [[ $? -ne 0 ]]; then
     if [[ $? -ne 0 ]]; then
         print_error "Failed to create database"
         print_error "Failed to create database"
-        return 1
+        exit 121
     fi
     fi
 
 
     print_info "Database created successfully with owner '$DB_USER'"
     print_info "Database created successfully with owner '$DB_USER'"
@@ -932,7 +955,7 @@ EOF
 
 
     if [[ $? -ne 0 ]]; then
     if [[ $? -ne 0 ]]; then
         print_error "Error importing create_db.sql"
         print_error "Error importing create_db.sql"
-        return 1
+        exit 122
     fi
     fi
 
 
     print_info "Database structure imported successfully"
     print_info "Database structure imported successfully"
@@ -946,7 +969,8 @@ SET ROLE "$DB_USER";
 EOF
 EOF
 
 
         if [[ $? -ne 0 ]]; then
         if [[ $? -ne 0 ]]; then
-            print_warn "Warning: failed to import data (may already exist or non-critical)"
+            print_error "Warning: failed to import data (may already exist or non-critical)"
+            exit 123
         else
         else
             print_info "Database data imported successfully"
             print_info "Database data imported successfully"
         fi
         fi
@@ -1035,13 +1059,13 @@ setup_database() {
         fi
         fi
     else
     else
         print_error "Unsupported database type: $DB_TYPE"
         print_error "Unsupported database type: $DB_TYPE"
-        return 1
+        exit 130
     fi
     fi
 
 
     # Проверка существования файлов
     # Проверка существования файлов
     if [[ ! -f "$SQL_CREATE_FILE" || ! -f "$SQL_DATA_FILE" ]]; then
     if [[ ! -f "$SQL_CREATE_FILE" || ! -f "$SQL_DATA_FILE" ]]; then
         print_error "SQL files not found for DB_TYPE=$DB_TYPE and EYE_LANG=$EYE_LANG"
         print_error "SQL files not found for DB_TYPE=$DB_TYPE and EYE_LANG=$EYE_LANG"
-        return 1
+        exit 131
     fi
     fi
 
 
     print_info "Using SQL files for $EYE_LANG language"
     print_info "Using SQL files for $EYE_LANG language"