tomatophp / filament-locations

Database Seeds for Locations for FilamentPHP
https://tomatophp.com/en/open-source/filament-locations
MIT License
11 stars 4 forks source link

Don't working with Postgres #2

Open streeboga opened 2 weeks ago

streeboga commented 2 weeks ago

INFO Running migrations.

2021_04_14_182305_fill_all_vars ...................................................................................................... 5.57ms FAIL

PDOException

SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "" LINE 2: INSERT INTOcountries(id,name,code,phone,cre...

linear[bot] commented 2 weeks ago

TOT-140 Don't working with Postgres

3x1io commented 1 day ago

hi @streeboga we still do not support Postgres DB

streeboga commented 1 day ago
   public function replace($input, $onlyEnd = false)
    {
        $output = str_replace('`', '', $input);
        $output = str_replace('\\"', '"', $output);
        // Заменяем ENGINE = InnoDB если есть
        $output = preg_replace('/ENGINE = InnoDB.*?;/i', ';', $output);

// Заменяем тип AUTO_INCREMENT на SERIAL
        $output = str_replace('INT AUTO_INCREMENT', 'SERIAL', $output);

// Заменяем TINYINT(1) на BOOLEAN
        $output = str_replace('TINYINT(1)', 'BOOLEAN', $output);

// Заменяем TEXT для JSON полей на JSONB
        $output = preg_replace('/(translations|timezones)\s+TEXT/i', '$1 JSONB', $output);

// Преобразуем JSON строки для PostgreSQL
        $output = preg_replace_callback('/\'({.*?})\'/s', function($matches) {
            // Экранируем одинарные кавычки внутри JSON
            $json = str_replace("'", "''", $matches[1]);
            return "'" . $json . "'";
        }, $output);

// Преобразуем значения для булевых полей
        $output = str_replace(', 1)', ', true)', $output);
        $output = str_replace(', 0)', ', false)', $output);
        if ($onlyEnd) {
            $output = str_replace(', 1,', ', true,', $output);
            $output = str_replace(', 0,', ', false,', $output);
        }

// Преобразуем INSERT INTO синтаксис если нужно
        $output = preg_replace('/INSERT INTO `(.*?)`/i', 'INSERT INTO $1', $output);

        return $output;
    }
DB::connection()->getPdo()->exec($this->replace($countires, true));

for support Postgres DB