Actualizar server.js
This commit is contained in:
120
server.js
120
server.js
@@ -321,6 +321,13 @@ async function autoUpdateDB() {
|
|||||||
urgencies_limit INT DEFAULT 0,
|
urgencies_limit INT DEFAULT 0,
|
||||||
bricos_limit INT DEFAULT 0,
|
bricos_limit INT DEFAULT 0,
|
||||||
coverages TEXT,
|
coverages TEXT,
|
||||||
|
|
||||||
|
billing_interval TEXT DEFAULT 'month',
|
||||||
|
billing_interval_count INT DEFAULT 1,
|
||||||
|
stripe_price_id TEXT,
|
||||||
|
is_active BOOLEAN DEFAULT TRUE,
|
||||||
|
updated_at TIMESTAMP DEFAULT NOW(),
|
||||||
|
|
||||||
created_at TIMESTAMP DEFAULT NOW()
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -359,11 +366,19 @@ async function autoUpdateDB() {
|
|||||||
created_at TIMESTAMP DEFAULT NOW()
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS protection_activity (
|
CREATE TABLE IF NOT EXISTS protection_payment_events (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
|
subscription_id INT REFERENCES protection_subscriptions(id) ON DELETE CASCADE,
|
||||||
company_id INT REFERENCES users(id) ON DELETE CASCADE,
|
company_id INT REFERENCES users(id) ON DELETE CASCADE,
|
||||||
type TEXT NOT NULL,
|
stripe_invoice_id TEXT,
|
||||||
description TEXT NOT NULL,
|
stripe_payment_intent_id TEXT,
|
||||||
|
stripe_checkout_session_id TEXT,
|
||||||
|
stripe_event_id TEXT,
|
||||||
|
amount DECIMAL(10,2) DEFAULT 0.00,
|
||||||
|
currency TEXT DEFAULT 'eur',
|
||||||
|
status TEXT NOT NULL,
|
||||||
|
event_type TEXT,
|
||||||
|
paid_at TIMESTAMP,
|
||||||
created_at TIMESTAMP DEFAULT NOW()
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -386,6 +401,105 @@ async function autoUpdateDB() {
|
|||||||
await client.query(`
|
await client.query(`
|
||||||
DO $$ BEGIN
|
DO $$ BEGIN
|
||||||
|
|
||||||
|
-- ==========================================
|
||||||
|
-- 🛡️ PARCHES MÓDULO PROTECCIÓN
|
||||||
|
-- ==========================================
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_plans' AND column_name='billing_interval') THEN
|
||||||
|
ALTER TABLE protection_plans ADD COLUMN billing_interval TEXT DEFAULT 'month';
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_plans' AND column_name='billing_interval_count') THEN
|
||||||
|
ALTER TABLE protection_plans ADD COLUMN billing_interval_count INT DEFAULT 1;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_plans' AND column_name='stripe_price_id') THEN
|
||||||
|
ALTER TABLE protection_plans ADD COLUMN stripe_price_id TEXT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_plans' AND column_name='is_active') THEN
|
||||||
|
ALTER TABLE protection_plans ADD COLUMN is_active BOOLEAN DEFAULT TRUE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_plans' AND column_name='updated_at') THEN
|
||||||
|
ALTER TABLE protection_plans ADD COLUMN updated_at TIMESTAMP DEFAULT NOW();
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='stripe_session_id') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN stripe_session_id TEXT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='stripe_subscription_id') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN stripe_subscription_id TEXT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='stripe_customer_id') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN stripe_customer_id TEXT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='stripe_price_id') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN stripe_price_id TEXT;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='started_at') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN started_at TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='current_period_start') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN current_period_start TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='current_period_end') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN current_period_end TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='last_payment_at') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN last_payment_at TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='cancel_at_period_end') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN cancel_at_period_end BOOLEAN DEFAULT FALSE;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='cancelled_at') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN cancelled_at TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='ended_at') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN ended_at TIMESTAMP;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='protection_subscriptions' AND column_name='updated_at') THEN
|
||||||
|
ALTER TABLE protection_subscriptions ADD COLUMN updated_at TIMESTAMP DEFAULT NOW();
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS protection_payment_events (
|
||||||
|
id SERIAL PRIMARY KEY,
|
||||||
|
subscription_id INT REFERENCES protection_subscriptions(id) ON DELETE CASCADE,
|
||||||
|
company_id INT REFERENCES users(id) ON DELETE CASCADE,
|
||||||
|
stripe_invoice_id TEXT,
|
||||||
|
stripe_payment_intent_id TEXT,
|
||||||
|
stripe_checkout_session_id TEXT,
|
||||||
|
stripe_event_id TEXT,
|
||||||
|
amount DECIMAL(10,2) DEFAULT 0.00,
|
||||||
|
currency TEXT DEFAULT 'eur',
|
||||||
|
status TEXT NOT NULL,
|
||||||
|
event_type TEXT,
|
||||||
|
paid_at TIMESTAMP,
|
||||||
|
created_at TIMESTAMP DEFAULT NOW()
|
||||||
|
);
|
||||||
|
|
||||||
|
UPDATE protection_subscriptions
|
||||||
|
SET payment_status = 'impagado'
|
||||||
|
WHERE payment_status IS NULL OR payment_status = '';
|
||||||
|
|
||||||
|
UPDATE protection_subscriptions
|
||||||
|
SET status = 'pendiente_pago'
|
||||||
|
WHERE status IS NULL OR status = '';
|
||||||
|
|
||||||
|
ALTER TABLE protection_subscriptions ALTER COLUMN payment_status SET DEFAULT 'impagado';
|
||||||
|
ALTER TABLE protection_subscriptions ALTER COLUMN status SET DEFAULT 'pendiente_pago';
|
||||||
|
|
||||||
-- 🟢 AÑADIDO: Fecha de última lectura del chat por el operario
|
-- 🟢 AÑADIDO: Fecha de última lectura del chat por el operario
|
||||||
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='scraped_services' AND column_name='last_chat_read_worker') THEN
|
IF NOT EXISTS (SELECT 1 FROM information_schema.columns WHERE table_name='scraped_services' AND column_name='last_chat_read_worker') THEN
|
||||||
ALTER TABLE scraped_services ADD COLUMN last_chat_read_worker TIMESTAMP DEFAULT '2000-01-01';
|
ALTER TABLE scraped_services ADD COLUMN last_chat_read_worker TIMESTAMP DEFAULT '2000-01-01';
|
||||||
|
|||||||
Reference in New Issue
Block a user