feat: add cleanup plan for obsolete files and migration script for project status constraint
This commit is contained in:
166
CLEANUP_PLAN.md
Normal file
166
CLEANUP_PLAN.md
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
# Project Cleanup - Files Marked for Deletion
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
This document identifies files that can be safely deleted to clean up the project repository. Files are categorized by type and include reasoning for deletion.
|
||||||
|
|
||||||
|
## Categories of Files to Delete
|
||||||
|
|
||||||
|
### 1. Debug Files
|
||||||
|
These are standalone debug/test files that were used during development but are no longer needed in production.
|
||||||
|
|
||||||
|
**Files to delete:**
|
||||||
|
- `debug-dropdown.js` - Simple dropdown testing script
|
||||||
|
- `debug-task-insert.mjs` - Database task insertion debugging
|
||||||
|
- `debug-disabled/` - Entire folder containing disabled debug components:
|
||||||
|
- `debug-disabled/comprehensive-polish-map/page.js`
|
||||||
|
- `debug-disabled/debug-polish-orthophoto/` (entire folder)
|
||||||
|
- `debug-disabled/test-improved-wmts/` (entire folder)
|
||||||
|
- `debug-disabled/test-polish-map/` (entire folder)
|
||||||
|
- `debug-disabled/test-polish-orthophoto/` (entire folder)
|
||||||
|
|
||||||
|
### 2. Standalone Test Files
|
||||||
|
These are one-off test scripts that were used for verification but are not part of the official test suite.
|
||||||
|
|
||||||
|
**Files to delete:**
|
||||||
|
- `test-audit-logging.mjs` - Audit logging functionality test
|
||||||
|
- `test-auth-api.mjs` - Authentication API testing
|
||||||
|
- `test-auth-detailed.mjs` - Detailed auth flow testing
|
||||||
|
- `test-auth-pages.mjs` - Auth pages testing
|
||||||
|
- `test-auth-session.mjs` - Session testing
|
||||||
|
- `test-auth.mjs` - General auth testing
|
||||||
|
- `test-complete-auth.mjs` - Complete auth flow testing
|
||||||
|
- `test-create-function.mjs` - Function creation testing
|
||||||
|
- `test-current-audit-logs.mjs` - Current audit logs testing
|
||||||
|
- `test-date-formatting.js` - Date formatting utility testing
|
||||||
|
- `test-dropdown-comprehensive.html` - Comprehensive dropdown HTML test
|
||||||
|
- `test-dropdown.html` - Basic dropdown HTML test
|
||||||
|
- `test-edge-compatibility.mjs` - Edge runtime compatibility testing
|
||||||
|
- `test-logged-in-flow.mjs` - Logged-in user flow testing
|
||||||
|
- `test-logging.mjs` - General logging testing
|
||||||
|
- `test-mobile.html` - Mobile interface testing
|
||||||
|
- `test-nextauth.mjs` - NextAuth testing
|
||||||
|
- `test-project-api.mjs` - Project API testing
|
||||||
|
- `test-project-creation.mjs` - Project creation testing
|
||||||
|
- `test-safe-audit-logging.mjs` - Safe audit logging testing
|
||||||
|
- `test-task-api.mjs` - Task API testing
|
||||||
|
- `test-user-tracking.mjs` - User tracking testing
|
||||||
|
|
||||||
|
### 3. Database Migration and Check Scripts
|
||||||
|
These are one-time migration and verification scripts that are no longer needed after successful execution.
|
||||||
|
|
||||||
|
**Files to delete:**
|
||||||
|
- `check-audit-db.mjs` - Audit database verification
|
||||||
|
- `check-columns.mjs` - Database column verification
|
||||||
|
- `check-projects-table.mjs` - Projects table verification
|
||||||
|
- `check-projects.mjs` - Projects data verification
|
||||||
|
- `check-schema.mjs` - Schema verification
|
||||||
|
- `check-task-schema.mjs` - Task schema verification
|
||||||
|
- `fix-notes-columns.mjs` - Notes columns fix (completed)
|
||||||
|
- `fix-task-columns.mjs` - Task columns fix (completed)
|
||||||
|
- `init-db-temp.mjs` - Temporary database initialization
|
||||||
|
- `migrate-project-status.mjs` - Project status migration (completed)
|
||||||
|
- `migrate-to-username.js` - Username migration (completed)
|
||||||
|
- `update-admin-username.js` - Admin username update (completed)
|
||||||
|
- `update-queries.ps1` - PowerShell query update script (completed)
|
||||||
|
- `verify-audit-fix.mjs` - Audit fix verification (completed)
|
||||||
|
- `verify-project.mjs` - Project verification (completed)
|
||||||
|
|
||||||
|
### 4. Old Database Backups
|
||||||
|
These are backup files that can be archived or deleted if no longer needed.
|
||||||
|
|
||||||
|
**Files to delete (with caution):**
|
||||||
|
- `data/database_old.sqlite` - Old database backup
|
||||||
|
- `data/database_old2.sqlite` - Older database backup
|
||||||
|
|
||||||
|
**Recommendation:** Archive these to external storage before deletion, or keep one as emergency backup.
|
||||||
|
|
||||||
|
### 5. Implementation Documentation
|
||||||
|
These are detailed implementation notes that document completed work and are no longer needed for ongoing development.
|
||||||
|
|
||||||
|
**Files to delete:**
|
||||||
|
- `AUDIT_LOGGING_IMPLEMENTATION.md` - Audit logging implementation details
|
||||||
|
- `AUTHORIZATION_IMPLEMENTATION.md` - Authorization implementation details
|
||||||
|
- `DROPDOWN_COMPLETION_STATUS.md` - Dropdown completion status
|
||||||
|
- `DROPDOWN_IMPLEMENTATION_SUMMARY.md` - Dropdown implementation summary
|
||||||
|
- `EDGE_RUNTIME_FIX_FINAL.md` - Edge runtime fix documentation
|
||||||
|
- `EDGE_RUNTIME_FIX.md` - Edge runtime fix details
|
||||||
|
- `INTEGRATION_COMPLETE.md` - Integration completion documentation
|
||||||
|
- `INTEGRATION_SUMMARY.md` - Integration summary
|
||||||
|
- `MERGE_COMPLETE.md` - Merge completion documentation
|
||||||
|
- `MERGE_PREPARATION_SUMMARY.md` - Merge preparation summary
|
||||||
|
- `POLISH_LAYERS_IMPLEMENTATION.md` - Polish layers implementation
|
||||||
|
|
||||||
|
## Files to Keep (Official Documentation)
|
||||||
|
These documentation files should be retained as they provide ongoing value:
|
||||||
|
|
||||||
|
- `README.md` - Project overview and setup instructions
|
||||||
|
- `ROADMAP.md` - Future development roadmap
|
||||||
|
- `TESTING.md` - Testing documentation and procedures
|
||||||
|
- `docs/MAP_LAYERS.md` - Map layers configuration guide
|
||||||
|
|
||||||
|
## Deletion Strategy
|
||||||
|
|
||||||
|
### Phase 1: Safe Deletions (Immediate)
|
||||||
|
Delete these files immediately as they have no production value:
|
||||||
|
- All debug files
|
||||||
|
- All standalone test files
|
||||||
|
- All migration/check scripts
|
||||||
|
- Implementation documentation files
|
||||||
|
|
||||||
|
### Phase 2: Database Backups (With Caution)
|
||||||
|
- Archive old database files to external storage
|
||||||
|
- Keep one backup as emergency rollback option
|
||||||
|
- Delete after confirming current database is stable
|
||||||
|
|
||||||
|
### Phase 3: Verification
|
||||||
|
After deletion:
|
||||||
|
1. Run `npm run build` to ensure no broken references
|
||||||
|
2. Run `npm test` to ensure test suite still passes
|
||||||
|
3. Check for any import errors or missing dependencies
|
||||||
|
|
||||||
|
## Impact Assessment
|
||||||
|
|
||||||
|
### Positive Impacts:
|
||||||
|
- **Reduced repository size** - Remove ~50+ unnecessary files
|
||||||
|
- **Cleaner codebase** - Eliminate confusion from old debug/test files
|
||||||
|
- **Better maintainability** - Focus on active code and official documentation
|
||||||
|
- **Improved build performance** - Fewer files to process
|
||||||
|
|
||||||
|
### Potential Risks:
|
||||||
|
- **Lost debugging context** - Some debug files might contain useful troubleshooting information
|
||||||
|
- **Missing historical reference** - Implementation docs provide context for current architecture
|
||||||
|
- **Accidental dependency** - Some files might be referenced in scripts or documentation
|
||||||
|
|
||||||
|
### Mitigation:
|
||||||
|
- **Backup first** - Create a backup branch before deletion
|
||||||
|
- **Gradual approach** - Delete in phases with verification between each
|
||||||
|
- **Documentation preservation** - Keep essential docs, archive implementation details
|
||||||
|
|
||||||
|
## Commands to Execute Deletion
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Phase 1: Safe deletions
|
||||||
|
rm debug-dropdown.js
|
||||||
|
rm debug-task-insert.mjs
|
||||||
|
rm -rf debug-disabled/
|
||||||
|
rm test-*.mjs test-*.js test-*.html
|
||||||
|
rm check-*.mjs migrate-*.mjs migrate-*.js update-*.js update-*.ps1 verify-*.mjs fix-*.mjs init-db-temp.mjs
|
||||||
|
rm *_IMPLEMENTATION.md *_COMPLETE.md *_SUMMARY.md EDGE_RUNTIME_FIX*.md POLISH_LAYERS_IMPLEMENTATION.md
|
||||||
|
|
||||||
|
# Phase 2: Database backups (after archiving)
|
||||||
|
# rm data/database_old.sqlite data/database_old2.sqlite
|
||||||
|
```
|
||||||
|
|
||||||
|
## Post-Deletion Checklist
|
||||||
|
- [ ] Run `npm run build` successfully
|
||||||
|
- [ ] Run `npm test` to ensure test suite passes
|
||||||
|
- [ ] Check for any broken imports or references
|
||||||
|
- [ ] Verify all functionality still works
|
||||||
|
- [ ] Update any documentation that referenced deleted files
|
||||||
|
- [ ] Commit changes with descriptive message
|
||||||
|
|
||||||
|
---
|
||||||
|
*Generated on: December 19, 2025*
|
||||||
|
*Total files identified for deletion: ~57+ files*
|
||||||
|
*Estimated space savings: ~5-10MB*</content>
|
||||||
|
<parameter name="filePath">d:\panel\CLEANUP_PLAN.md
|
||||||
87
migrate-project-status.mjs
Normal file
87
migrate-project-status.mjs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
import db from './src/lib/db.js';
|
||||||
|
|
||||||
|
console.log('Starting migration to add cancelled status to project_status constraint...');
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Disable foreign key constraints temporarily
|
||||||
|
db.pragma('foreign_keys = OFF');
|
||||||
|
console.log('Disabled foreign key constraints');
|
||||||
|
|
||||||
|
// Since SQLite doesn't support modifying CHECK constraints directly,
|
||||||
|
// we need to recreate the table with the new constraint
|
||||||
|
|
||||||
|
// First, create a backup table with current data
|
||||||
|
db.exec('CREATE TABLE projects_backup AS SELECT * FROM projects');
|
||||||
|
console.log('Created backup table');
|
||||||
|
|
||||||
|
// Drop the original table
|
||||||
|
db.exec('DROP TABLE projects');
|
||||||
|
console.log('Dropped original table');
|
||||||
|
|
||||||
|
// Recreate the table with the updated constraint
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE projects (
|
||||||
|
project_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
contract_id INTEGER,
|
||||||
|
project_name TEXT NOT NULL,
|
||||||
|
project_number TEXT NOT NULL,
|
||||||
|
address TEXT,
|
||||||
|
plot TEXT,
|
||||||
|
district TEXT,
|
||||||
|
unit TEXT,
|
||||||
|
city TEXT,
|
||||||
|
investment_number TEXT,
|
||||||
|
finish_date TEXT,
|
||||||
|
wp TEXT,
|
||||||
|
contact TEXT,
|
||||||
|
notes TEXT,
|
||||||
|
project_type TEXT CHECK(project_type IN ('design', 'construction', 'design+construction')) DEFAULT 'design',
|
||||||
|
project_status TEXT CHECK(project_status IN ('registered', 'in_progress_design', 'in_progress_construction', 'fulfilled', 'cancelled')) DEFAULT 'registered',
|
||||||
|
coordinates TEXT,
|
||||||
|
created_by TEXT,
|
||||||
|
assigned_to TEXT,
|
||||||
|
created_at TEXT,
|
||||||
|
updated_at TEXT,
|
||||||
|
FOREIGN KEY (contract_id) REFERENCES contracts(contract_id)
|
||||||
|
)
|
||||||
|
`);
|
||||||
|
console.log('Created new table with updated constraint');
|
||||||
|
|
||||||
|
// Copy data back
|
||||||
|
db.exec('INSERT INTO projects SELECT * FROM projects_backup');
|
||||||
|
console.log('Restored data from backup');
|
||||||
|
|
||||||
|
// Drop backup table
|
||||||
|
db.exec('DROP TABLE projects_backup');
|
||||||
|
console.log('Cleaned up backup table');
|
||||||
|
|
||||||
|
// Re-enable foreign key constraints
|
||||||
|
db.pragma('foreign_keys = ON');
|
||||||
|
console.log('Re-enabled foreign key constraints');
|
||||||
|
|
||||||
|
// Verify the new constraint
|
||||||
|
const schema = db.prepare('SELECT sql FROM sqlite_master WHERE type=\'table\' AND name=\'projects\'').get();
|
||||||
|
console.log('New table definition:');
|
||||||
|
console.log(schema.sql);
|
||||||
|
|
||||||
|
console.log('Migration completed successfully!');
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Migration failed:', error);
|
||||||
|
|
||||||
|
// Re-enable foreign keys in case of error
|
||||||
|
try {
|
||||||
|
db.pragma('foreign_keys = ON');
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Failed to re-enable foreign keys:', e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to restore from backup if it exists
|
||||||
|
try {
|
||||||
|
db.exec('DROP TABLE IF EXISTS projects');
|
||||||
|
db.exec('ALTER TABLE projects_backup RENAME TO projects');
|
||||||
|
console.log('Restored from backup due to error');
|
||||||
|
} catch (restoreError) {
|
||||||
|
console.error('Failed to restore from backup:', restoreError);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user