# Database Development

Source: https://bealinawaz.com/services/database-development/
By Ali Nawaz, freelance WordPress and Shopify developer in Lahore, Pakistan (https://bealinawaz.com/about-me/).

Database development with MySQL, PostgreSQL, and MongoDB, including schema design, queries, migrations, application integration, and optimization.

I design, build and fix databases for web applications and business systems, in MySQL, PostgreSQL and MongoDB. That covers new schemas, the queries and indexes an app depends on, migrations that change the structure safely, data imports from spreadsheets or old systems, and reviews of databases that have become slow or messy.

A database should protect the facts your business can't afford to get wrong, like who paid, what was ordered and who can see what, while keeping everyday screens fast. I put rules into the schema with constraints and foreign keys wherever possible, then check the design against the real queries the app runs, not against a diagram.

## Database development services I offer.
- Relational schema and constraint design: Tables, keys, foreign keys and constraints designed from your business rules, so bad data is rejected by the database instead of cleaned up later.
- MongoDB document modeling: Document structures, references and validation rules for MongoDB, with indexes planned around the queries the app will run.
- Query and index optimization: Slow queries found from the logs and query plans, then fixed with the right index, a rewritten query or a change in how the app fetches data.
- Migrations and application data access: Versioned migrations that change the structure without losing data, and application code that reads and writes through a clear data layer.

## What a sound database gives you.
- More reliable business data
- Queries aligned to product use
- Safer application changes
- Clearer reporting foundations

## Database problems I'm asked to fix, and what usually causes them.

These come up again and again in existing applications.

| Symptom | Usual cause |
| --- | --- |
| A page that gets slower every month | A query scanning a growing table without a suitable index |
| Dozens of queries for one page | The app fetching related records one by one instead of in a single query |
| Duplicate customers or orders | No unique constraint, so retries and double clicks create copies |
| Reports that don't add up | The same fact stored in two places and updated in only one |
| Records pointing at nothing | Missing foreign keys, so deletes leave orphaned rows behind |
| Fear of changing anything | No migrations, so the live schema differs from what the code expects |
| No idea whether backups work | Backups taken but never restored to test them |

## MySQL, PostgreSQL or MongoDB.

For most business applications I pick a relational database. MySQL fits straightforward transactional apps and anything that sits close to WordPress, which runs on it. PostgreSQL suits products with richer relationships, heavier reporting, or a need for features like row-level security and indexed JSON columns. MongoDB fits data that is naturally a self-contained document, such as content with varying fields or activity records.

What matters more than the brand is whether the data has relationships that must stay consistent. Orders, payments, stock and permissions almost always do, and that points to SQL.

## What a database review covers.

When an existing app is slow or the data has drifted, I start with a review. I read the schema, run the slowest queries through the query planner, check which indexes are used and which are dead weight, look for missing constraints and duplicated data, and confirm backups exist and can actually be restored.

You get findings ranked by risk and impact, with the fix for each. Often the quickest wins are a handful of indexes and two or three rewritten queries, not a new database.

## Changing a live database without breaking it.

Structure changes on a live database are where data gets lost. I write each change as a versioned migration, test it against a recent copy of production data on staging, and split risky changes into steps: add the new column, backfill it, switch the code, then remove the old column. A backup is taken before every production run.

## Frequently asked questions

**How do you choose between SQL and MongoDB?**
I look at how the records relate, whether transactions are needed, the queries the app will run, the shape of each record and where it will be hosted, rather than picking by trend.

**Can you improve an existing database?**
Yes. I review the schema, slow queries, indexes, migration practice and how the app accesses data, then fix issues in order of risk and impact.

**How much does database work cost?**
The cost depends on the number of tables and relationships, the data you need moved in, and the queries the app runs most; a focused fix, such as a slow query or a broken import, is far smaller than a new design. I quote a fixed price in US dollars after seeing the schema or the requirements.

**Can you migrate data from spreadsheets or another system?**
Yes. I map the old fields to the new schema, clean out duplicates and inconsistent values, run test imports on staging, and only then import into production.

**Can you move us from MySQL to PostgreSQL, or the reverse?**
Yes, though it's rarely the first fix for a slow app. When a move is justified, I convert the schema, migrate the data with checks on row counts and totals, update the queries that behave differently, and test before switching over.

**Do you set up backups?**
Yes: automated backups stored away from the database server, a retention period that suits you, and a test restore so you know they work.

**How do payments work?**
50% to start and 50% when the work is delivered and you've checked it on staging, followed by 15 days of free support.
