# EcomDrive v4 Multi Business — generated database starter

Source: `EcomDrive_Bootstrap_Design_v4_SOURCE(1).zip` and `SCHEMA_BLUEPRINT.md`.
This is an **implementation starter** based on the design blueprint, not the original EcomDrive backend schema.

## Contents
- `database/sql/ecomdrive_mysql8.sql`: 150 tables, indexed columns, FK constraints, business scoped keys.
- `database/migrations/2026_11_18_000001_create_ecomdrive_schema.php`: Laravel migration executes the included SQL.
- `app/Models/EcomDrive/*.php`: 150 Eloquent models with belongsTo / hasMany relations and casts.
- `database/seeders/EcomDriveSeeder.php`: global status catalog, modules, initial permissions.
- `app/Services/EcomDrive/StatusService.php`: transaction-safe status history and allowed transition enforcement.
- `SCHEMA_BLUEPRINT.md`: original design specification.

## Install (Laravel 11 or 12, MySQL 8)
1. **Use a new empty database.** This migration creates `users` and other tables; do not run on an existing Laravel schema without reconciliation.
2. Copy the directories into your Laravel app; retain `database/sql/ecomdrive_mysql8.sql`.
3. Set `.env` DB_CONNECTION=mysql and your DB_* credentials.
4. Run `php artisan migrate` then `php artisan db:seed --class=EcomDriveSeeder`.
5. Implement business membership middleware and business-scoped policies before exposing routes.

## Important limitations
- Generated schema is nullable-first to permit flexible UI fields; add NOT NULL, CHECK and composite tenant FK constraints after validating actual workflows.
- This package **does not implement** order posting, inventory reservation, balanced double-entry posting, webhook consumers, APIs, frontend integration or comprehensive authorization middleware. Those are application services, not satisfied by schema alone.
- Status transition rows are intentionally not seeded: define and approve business-specific workflows before changing a status from a non-null previous status.
- Models use `$guarded=['id']` for starter convenience; enforce authorization and validated input (or strict `$fillable`) before production.
- SQL migration runs DDL and is not atomic in MySQL. Take backups and use a fresh database.
- A global `statuses` uniqueness key with nullable business_id permits duplicate NULL rows under MySQL semantics; seeder uses updateOrInsert for repeatable execution.
- Models and FKs express basic relationships; cross-business FK integrity requires additional compound keys or app-level enforcement.
