mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
add scripts to migrate the data
This commit is contained in:
parent
b8d5907f36
commit
e5ad26c8e3
2 changed files with 34 additions and 0 deletions
24
scripts/init_payments_table.sh
Normal file
24
scripts/init_payments_table.sh
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/sh
|
||||
|
||||
DB_NAME="your_database_name"
|
||||
DB_USER="your_username"
|
||||
DB_HOST="your_host" # e.g., localhost or an IP address
|
||||
DB_PORT="your_port" # Default PostgreSQL port is 5432
|
||||
SQL_FILE="payment_migration.sql" # File containing the SQL script
|
||||
|
||||
# Check if the SQL file exists
|
||||
if [ ! -f "$SQL_FILE" ]; then
|
||||
echo "Error: SQL file '$SQL_FILE' not found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute the SQL script
|
||||
psql -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" -f "$SQL_FILE"
|
||||
|
||||
# Check the result of the execution
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "SQL script executed successfully."
|
||||
else
|
||||
echo "Error: Failed to execute SQL script."
|
||||
exit 1
|
||||
fi
|
||||
10
scripts/payment_migration.sql
Normal file
10
scripts/payment_migration.sql
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
INSERT INTO payments (created_at, updated_at, deleted_at, booking_id, amount, payment_method)
|
||||
SELECT MIN(i.created_at) AS created_at, -- Use the earliest created_at timestamp for this payment
|
||||
MAX(i.updated_at) AS updated_at, -- Use the latest updated_at timestamp for this payment
|
||||
i.deleted_at, -- Use the deleted_at timestamp from items
|
||||
i.booking_id, -- The associated booking_id
|
||||
SUM(i.price * i.quantity) AS amount, -- Calculate total amount from price * quantity
|
||||
i.payment_method -- The payment method
|
||||
FROM items i
|
||||
WHERE i.deleted_at IS NULL -- Exclude soft-deleted items
|
||||
GROUP BY i.booking_id, i.payment_method, i.deleted_at;
|
||||
Loading…
Reference in a new issue