almeira-web/scripts/apply_coupons_columns.py

57 lines
2.0 KiB
Python

import paramiko
import json
HOST = '161.97.93.156'
USER = 'carlos'
PASSWORD = 'Innova1978+*?'
MARIADB = 'appwrite-mariadb-sss6crntvrcs54qbhvhy5728'
DB_PASS = 'sn9YkZqoLV06CQxAy2qsKi36S7POVShT'
DB_USER = 'sYoHWwl0DGvEyt3s'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=HOST, username=USER, password=PASSWORD, timeout=15)
sql_commands = """
ALTER TABLE _1_database_2_collection_12
ADD COLUMN IF NOT EXISTS `code` VARCHAR(50) NULL,
ADD COLUMN IF NOT EXISTS `description` VARCHAR(500) NULL,
ADD COLUMN IF NOT EXISTS `discountType` VARCHAR(20) NULL,
ADD COLUMN IF NOT EXISTS `discountValue` BIGINT(20) NULL,
ADD COLUMN IF NOT EXISTS `minSpend` BIGINT(20) DEFAULT 0,
ADD COLUMN IF NOT EXISTS `maxDiscount` BIGINT(20) DEFAULT 0,
ADD COLUMN IF NOT EXISTS `usageLimit` BIGINT(20) DEFAULT 0,
ADD COLUMN IF NOT EXISTS `usageCount` BIGINT(20) DEFAULT 0,
ADD COLUMN IF NOT EXISTS `expiresAt` VARCHAR(100) NULL,
ADD COLUMN IF NOT EXISTS `startDate` VARCHAR(100) NULL,
ADD COLUMN IF NOT EXISTS `isActive` TINYINT(1) DEFAULT 1,
ADD COLUMN IF NOT EXISTS `applicableCategories` VARCHAR(1000) NULL;
ALTER TABLE _1_database_2_collection_4
ADD COLUMN IF NOT EXISTS `couponCode` VARCHAR(50) NULL,
ADD COLUMN IF NOT EXISTS `discountAmount` BIGINT(20) DEFAULT 0;
UPDATE _1_attributes SET status = 'available' WHERE databaseInternalId = 2 AND collectionId IN ('coupons', 'orders');
"""
sftp = client.open_sftp()
with sftp.file('/tmp/alter_coupons.sql', 'w') as f:
f.write(sql_commands)
sftp.close()
cmd = f'docker exec -i {MARIADB} mysql -u {DB_USER} -p{DB_PASS} appwrite < /tmp/alter_coupons.sql'
stdin, stdout, stderr = client.exec_command(cmd)
print("MySQL Output:\n", stdout.read().decode())
print("MySQL Err:\n", stderr.read().decode())
# Sync attributes JSON in _1_database_2
sync_script = """
import json
import paramiko
# Read and sync
"""
client.exec_command('docker exec appwrite-redis-sss6crntvrcs54qbhvhy5728 redis-cli flushall')
print("Redis flushed successfully!")
client.close()