Initial commit.
This commit is contained in:
92
static/batch/sql_combine.bat
Normal file
92
static/batch/sql_combine.bat
Normal file
@@ -0,0 +1,92 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set dir_parent=C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\static\MySQL
|
||||
:: set dir_parent=C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\static\PostgreSQL
|
||||
set "f_list=file_list.txt"
|
||||
set dir_current=%cd%
|
||||
set "f_tmp=temp.txt"
|
||||
set "f_combine=0000_combine.sql"
|
||||
set verbose=0
|
||||
set "strs_delete_0=920_edit_permissions.sql"
|
||||
set "strs_delete_1=910_anal.sql"
|
||||
set "strs_delete_2=deprecated"
|
||||
set "strs_delete_3=%f_list%"
|
||||
set "strs_delete_4=%f_tmp%"
|
||||
set "strs_delete_5=701_p_shop_get_many_role_permission.sql"
|
||||
set "strs_delete_6=600_p_shop_save_product.sql"
|
||||
set "strs_delete_7=170_ish_tbl_ERP_Order.sql"
|
||||
set "strs_delete_7=dump.sql"
|
||||
set strs_n_max=8
|
||||
|
||||
set "str_list="
|
||||
|
||||
set max_length=8191
|
||||
set threshold=1000
|
||||
|
||||
echo temp = %f_tmp%
|
||||
echo dir_parent = !%dir_parent%!
|
||||
echo dir_current = !%dir_current%!
|
||||
echo file_list = %f_list%
|
||||
echo file = %f_combine%
|
||||
echo n strings = !strs_n_max!
|
||||
|
||||
cd %dir_parent%
|
||||
del %f_tmp%
|
||||
del %f_list%
|
||||
del %f_combine%
|
||||
|
||||
dir /b *.sql > %f_list%
|
||||
|
||||
|
||||
echo loopy
|
||||
|
||||
(for /f "delims=" %%a in (%f_list%) do (
|
||||
set "line=%%a"
|
||||
set include_line=1
|
||||
for /L %%i in (0, 1, %strs_n_max%) do (
|
||||
if !line! equ !strs_delete_%%i! (
|
||||
set include_line=0
|
||||
)
|
||||
set "line=!line!"
|
||||
)
|
||||
if !include_line! gtr 0 (
|
||||
echo !line!
|
||||
::set "str_list=!str_list! !line!"
|
||||
::set length=0
|
||||
::for %%i in (!str_list!) do (
|
||||
:: set /a length+=1
|
||||
::)
|
||||
::if !length! geq !threshold! (
|
||||
:: echo !str_list!
|
||||
:: echo !str_list! > %f_combine%
|
||||
:: set "str_list="
|
||||
::)
|
||||
type !line! >> %f_combine%
|
||||
)
|
||||
set "line=!line!"
|
||||
)) > %f_tmp%
|
||||
|
||||
|
||||
echo output list:
|
||||
type %f_tmp%
|
||||
|
||||
del %f_list%
|
||||
echo file_tmp: %f_tmp%
|
||||
echo file_list: %f_list%
|
||||
echo combining files
|
||||
echo !str_list!
|
||||
|
||||
echo cmd:
|
||||
::echo "type !str_list! > %f_combine%"
|
||||
::type !str_list! > %f_combine%
|
||||
::(for %%f in (!str_list!) do (
|
||||
:: echo %%f
|
||||
:: type "%%f" >> %f_combine%
|
||||
::))
|
||||
|
||||
cd %dir_current%
|
||||
|
||||
echo Current Time: %TIME%
|
||||
|
||||
endlocal
|
||||
44
static/batch/sql_combine.ps1
Normal file
44
static/batch/sql_combine.ps1
Normal file
@@ -0,0 +1,44 @@
|
||||
|
||||
# Combine-SqlFiles.ps1
|
||||
param(
|
||||
[string]$sourceFolder = "C:\Users\edwar\OneDrive\Documents\Programming\Visual Studio 2022\PARTS_Web\app\static\MySQL\",
|
||||
[string]$outputFileName = "0000_combined.sql",
|
||||
[string]$filePattern = "*.sql",
|
||||
[string[]]$excludeFiles = @("dump.sql") # Array of filenames to exclude
|
||||
)
|
||||
|
||||
$outputFile = Join-Path $sourceFolder $outputFileName
|
||||
$outputDir = Split-Path -Parent $outputFile
|
||||
|
||||
# Remove output file if it exists
|
||||
if (Test-Path $outputFile) {
|
||||
Remove-Item $outputFile -Force
|
||||
}
|
||||
|
||||
# Create directory if needed
|
||||
if (!(Test-Path -Path $outputDir)) {
|
||||
New-Item -ItemType Directory -Force -Path $outputDir
|
||||
}
|
||||
|
||||
# Create a StringBuilder for efficiency
|
||||
$output = New-Object System.Text.StringBuilder
|
||||
|
||||
# Process each file
|
||||
Get-ChildItem -Path $sourceFolder -Filter $filePattern -File |
|
||||
Where-Object { $_.Name -notin $excludeFiles -and $_.Name -ne $outputFileName } |
|
||||
ForEach-Object {
|
||||
Write-Host "Processing file: $($_.Name)"
|
||||
[void]$output.AppendLine("-- File: $($_.Name)")
|
||||
# Read file content and remove BOM if present
|
||||
$content = [System.IO.File]::ReadAllBytes($_.FullName)
|
||||
if ($content[0] -eq 0xEF -and $content[1] -eq 0xBB -and $content[2] -eq 0xBF) {
|
||||
$content = $content[3..($content.Length-1)]
|
||||
}
|
||||
[void]$output.AppendLine([System.Text.Encoding]::UTF8.GetString($content))
|
||||
[void]$output.AppendLine()
|
||||
}
|
||||
|
||||
# Write final output
|
||||
[System.IO.File]::WriteAllText($outputFile, $output.ToString(), [System.Text.UTF8Encoding]::new($false))
|
||||
|
||||
Write-Host "Files combined successfully into $outputFile"
|
||||
Reference in New Issue
Block a user