PHASE 1: Cleanup & Analyse - Feature-Konsolidierung: export_csv/json/zip → data_export (1 Feature) - Umbenennung: csv_import → data_import - Auto-Migration bei Container-Start (apply_v9c_migration.py) - Diagnose-Script (check_features.sql) Lessons Learned angewendet: - Ein Feature für Export, nicht drei - Migration ist idempotent (kann mehrfach laufen) - Zeigt BEFORE/AFTER State im Log Finaler Feature-Katalog (10 statt 13): - Data: weight, circumference, caliper, nutrition, activity, photos - AI: ai_calls, ai_pipeline - Export/Import: data_export, data_import Tier Limits: - FREE: 30 data entries, 0 AI/export/import - BASIC: unlimited data, 3 AI/month, 5 export/month, 3 import/month - PREMIUM/SELFHOSTED: unlimited Migration läuft automatisch auf dev UND prod beim Container-Start. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
142 lines
5.9 KiB
SQL
142 lines
5.9 KiB
SQL
-- ============================================================================
|
|
-- v9c Cleanup: Feature-Konsolidierung
|
|
-- ============================================================================
|
|
-- Created: 2026-03-20
|
|
-- Purpose: Konsolidiere Export-Features (export_csv/json/zip → data_export)
|
|
-- und Import-Features (csv_import → data_import)
|
|
--
|
|
-- Idempotent: Kann mehrfach ausgeführt werden
|
|
--
|
|
-- Lessons Learned:
|
|
-- "Ein Feature für Export, nicht drei (csv/json/zip)"
|
|
-- ============================================================================
|
|
|
|
-- ============================================================================
|
|
-- 1. Rename csv_import to data_import
|
|
-- ============================================================================
|
|
UPDATE features
|
|
SET
|
|
id = 'data_import',
|
|
name = 'Daten importieren',
|
|
description = 'CSV-Import (FDDB, Apple Health) + ZIP-Backup-Import'
|
|
WHERE id = 'csv_import';
|
|
|
|
-- Update tier_limits references
|
|
UPDATE tier_limits
|
|
SET feature_id = 'data_import'
|
|
WHERE feature_id = 'csv_import';
|
|
|
|
-- Update user_feature_restrictions references
|
|
UPDATE user_feature_restrictions
|
|
SET feature_id = 'data_import'
|
|
WHERE feature_id = 'csv_import';
|
|
|
|
-- Update user_feature_usage references
|
|
UPDATE user_feature_usage
|
|
SET feature_id = 'data_import'
|
|
WHERE feature_id = 'csv_import';
|
|
|
|
-- ============================================================================
|
|
-- 2. Remove old export_csv/json/zip features
|
|
-- ============================================================================
|
|
|
|
-- Remove tier_limits for old features
|
|
DELETE FROM tier_limits
|
|
WHERE feature_id IN ('export_csv', 'export_json', 'export_zip');
|
|
|
|
-- Remove user restrictions for old features
|
|
DELETE FROM user_feature_restrictions
|
|
WHERE feature_id IN ('export_csv', 'export_json', 'export_zip');
|
|
|
|
-- Remove usage tracking for old features
|
|
DELETE FROM user_feature_usage
|
|
WHERE feature_id IN ('export_csv', 'export_json', 'export_zip');
|
|
|
|
-- Remove old feature definitions
|
|
DELETE FROM features
|
|
WHERE id IN ('export_csv', 'export_json', 'export_zip');
|
|
|
|
-- ============================================================================
|
|
-- 3. Ensure data_export exists and is properly configured
|
|
-- ============================================================================
|
|
INSERT INTO features (id, name, description, category, limit_type, reset_period, default_limit, active)
|
|
VALUES ('data_export', 'Daten exportieren', 'CSV/JSON/ZIP Export', 'export', 'count', 'monthly', 0, true)
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
description = EXCLUDED.description,
|
|
category = EXCLUDED.category,
|
|
limit_type = EXCLUDED.limit_type,
|
|
reset_period = EXCLUDED.reset_period;
|
|
|
|
-- ============================================================================
|
|
-- 4. Ensure data_import exists and is properly configured
|
|
-- ============================================================================
|
|
INSERT INTO features (id, name, description, category, limit_type, reset_period, default_limit, active)
|
|
VALUES ('data_import', 'Daten importieren', 'CSV-Import (FDDB, Apple Health) + ZIP-Backup-Import', 'import', 'count', 'monthly', 0, true)
|
|
ON CONFLICT (id) DO UPDATE SET
|
|
name = EXCLUDED.name,
|
|
description = EXCLUDED.description,
|
|
category = EXCLUDED.category,
|
|
limit_type = EXCLUDED.limit_type,
|
|
reset_period = EXCLUDED.reset_period;
|
|
|
|
-- ============================================================================
|
|
-- 5. Update tier_limits for data_export (consolidate from old features)
|
|
-- ============================================================================
|
|
|
|
-- FREE tier: no export
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('free', 'data_export', 0)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- BASIC tier: 5 exports/month
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('basic', 'data_export', 5)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- PREMIUM tier: unlimited
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('premium', 'data_export', NULL)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- SELFHOSTED tier: unlimited
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('selfhosted', 'data_export', NULL)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- ============================================================================
|
|
-- 6. Update tier_limits for data_import
|
|
-- ============================================================================
|
|
|
|
-- FREE tier: no import
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('free', 'data_import', 0)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- BASIC tier: 3 imports/month
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('basic', 'data_import', 3)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- PREMIUM tier: unlimited
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('premium', 'data_import', NULL)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- SELFHOSTED tier: unlimited
|
|
INSERT INTO tier_limits (tier_id, feature_id, limit_value)
|
|
VALUES ('selfhosted', 'data_import', NULL)
|
|
ON CONFLICT (tier_id, feature_id) DO UPDATE SET limit_value = EXCLUDED.limit_value;
|
|
|
|
-- ============================================================================
|
|
-- Cleanup complete
|
|
-- ============================================================================
|
|
-- Final feature list:
|
|
-- Data: weight_entries, circumference_entries, caliper_entries,
|
|
-- nutrition_entries, activity_entries, photos
|
|
-- AI: ai_calls, ai_pipeline
|
|
-- Export/Import: data_export, data_import
|
|
--
|
|
-- Total: 10 features (down from 13)
|
|
-- ============================================================================
|