48 lines
1.4 KiB
SQL
48 lines
1.4 KiB
SQL
-- +goose Up
|
|
|
|
ALTER TABLE payment_merchant_configs
|
|
ADD COLUMN owner_tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
|
|
ADD KEY idx_payment_merchant_configs_owner (owner_tenant_id, pay_way, status);
|
|
|
|
UPDATE payment_merchant_configs
|
|
SET owner_tenant_id = (SELECT id FROM tenants WHERE code = 'dachui' LIMIT 1)
|
|
WHERE owner_tenant_id = 0;
|
|
|
|
ALTER TABLE payment_orders
|
|
ADD COLUMN tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
|
|
ADD KEY idx_payment_orders_tenant_created (tenant_id, created_at);
|
|
|
|
UPDATE payment_orders p
|
|
JOIN rental_orders o ON o.id = p.order_id
|
|
SET p.tenant_id = o.payment_tenant_id
|
|
WHERE p.tenant_id = 0
|
|
AND o.payment_tenant_id > 0;
|
|
|
|
UPDATE payment_orders p
|
|
JOIN users u ON u.id = p.user_id
|
|
SET p.tenant_id = u.tenant_id
|
|
WHERE p.tenant_id = 0;
|
|
|
|
ALTER TABLE payment_config_usage_logs
|
|
ADD COLUMN tenant_id BIGINT UNSIGNED NOT NULL DEFAULT 0 AFTER id,
|
|
ADD KEY idx_payment_config_usage_logs_tenant (tenant_id, created_at);
|
|
|
|
UPDATE payment_config_usage_logs l
|
|
JOIN payment_orders p ON p.id = l.payment_order_id
|
|
SET l.tenant_id = p.tenant_id
|
|
WHERE l.tenant_id = 0;
|
|
|
|
-- +goose Down
|
|
|
|
ALTER TABLE payment_config_usage_logs
|
|
DROP KEY idx_payment_config_usage_logs_tenant,
|
|
DROP COLUMN tenant_id;
|
|
|
|
ALTER TABLE payment_orders
|
|
DROP KEY idx_payment_orders_tenant_created,
|
|
DROP COLUMN tenant_id;
|
|
|
|
ALTER TABLE payment_merchant_configs
|
|
DROP KEY idx_payment_merchant_configs_owner,
|
|
DROP COLUMN owner_tenant_id;
|