#!/bin/bash
# Extract specific tables from production backup for import into dev
# Source: database-backup-11-13-25-eod.sql
# Target tables: notifications, notificationtypes, printers, knowledgebase

BACKUP_FILE="/home/camp/projects/windows/database-backup-11-13-25-eod.sql"
OUTPUT_DIR="/home/camp/projects/windows/shopdb/sql"

echo "Extracting production data from $BACKUP_FILE..."

# Extract notifications table (structure + data)
echo "Extracting notifications..."
sed -n '/CREATE TABLE IF NOT EXISTS `notifications`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_notifications.sql"

# Extract notificationtypes table (structure + data)
echo "Extracting notificationtypes..."
sed -n '/CREATE TABLE IF NOT EXISTS `notificationtypes`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_notificationtypes.sql"

# Extract printers table (structure + data)
echo "Extracting printers..."
sed -n '/CREATE TABLE IF NOT EXISTS `printers`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_printers.sql"

# Extract knowledgebase table (structure + data)
echo "Extracting knowledgebase..."
sed -n '/CREATE TABLE IF NOT EXISTS `knowledgebase`/,/UNLOCK TABLES/p' "$BACKUP_FILE" > "$OUTPUT_DIR/prod_knowledgebase.sql"

echo "Extraction complete!"
echo ""
echo "Files created:"
ls -lh "$OUTPUT_DIR"/prod_*.sql

echo ""
echo "Next steps:"
echo "1. Review the extracted files"
echo "2. Run import_prod_data.sql to import into dev database"
