Ading comments and cleaning up
This commit is contained in:
@@ -12,7 +12,8 @@ Usage:
|
||||
m4g add db [options]
|
||||
|
||||
Options:
|
||||
--database-host-port, --dbh-port <database-host-port> The database host port
|
||||
--database-ui-port, --dbu-port <database-ui-port> The database UI port
|
||||
-?, -h, --help Show help and usage information
|
||||
--database-host-port, --dbh-port <database-host-port> The database host port
|
||||
--database-ui-port, --dbu-port <database-ui-port> The database UI port
|
||||
--database-ui-platform, --dbu-platform <linux_amd64|linux_arm32v5|linux_arm32v6|linux_arm32v7|linux_arm64v8> The docker platform for the PhpMyAdmin image
|
||||
-?, -h, --help Show help and usage information
|
||||
```
|
||||
@@ -15,9 +15,10 @@ Arguments:
|
||||
<name> The name of your project
|
||||
|
||||
Options:
|
||||
--without <api|db|git|gitignore> Features to exclude
|
||||
--api-port <api-port> The API port
|
||||
--database-host-port, --dbh-port <database-host-port> The database host port
|
||||
--database-ui-port, --dbu-port <database-ui-port> The database UI port
|
||||
-?, -h, --help Show help and usage information
|
||||
--without <api|db|git|gitignore> Features to exclude
|
||||
--api-port <api-port> The API port
|
||||
--database-host-port, --dbh-port <database-host-port> The database host port
|
||||
--database-ui-port, --dbu-port <database-ui-port> The database UI port
|
||||
--database-ui-platform, --dbu-platform <linux_amd64|linux_arm32v5|linux_arm32v6|linux_arm32v7|linux_arm64v8> The docker platform for the PhpMyAdmin image
|
||||
-?, -h, --help Show help and usage information
|
||||
```
|
||||
|
||||
@@ -13,10 +13,7 @@ To use MycroForge, ensure you have the following dependencies installed:
|
||||
- **Python 3.10**
|
||||
- **Docker**
|
||||
- **.NET 8**
|
||||
|
||||
### Windows
|
||||
|
||||
For Windows users, MycroForge is designed to run in a POSIX compliant environment. It has been tested on Windows using WSL2 with Ubuntu 22.04.03. Therefore, it is recommended to run MycroForge within the same or a similar WSL2 distribution for optimal performance.
|
||||
- **XCode Command Line Tools (MacOS only)**
|
||||
|
||||
### Adding the Package Registry
|
||||
|
||||
@@ -37,3 +34,35 @@ dotnet tool install -g MycroForge.CLI
|
||||
```
|
||||
dotnet tool install -g MycroForge.CLI
|
||||
```
|
||||
|
||||
### Windows
|
||||
|
||||
MycroForge is designed to run in a POSIX compliant environment. It has been tested on Windows using WSL2 with Ubuntu 22.04.03. So it is recommended to run MycroForge within the same or a similar WSL2 distribution for optimal performance.
|
||||
|
||||
### MacOS
|
||||
|
||||
#### Post install steps
|
||||
After installing MycroForge, the dotnet CLI will show a message with some instructions to make the `m4g` command available in `zsh`.
|
||||
It should look similar to the example below.
|
||||
|
||||
```sh
|
||||
Tools directory '/Users/username/.dotnet/tools' is not currently on the PATH environment variable.
|
||||
If you are using zsh, you can add it to your profile by running the following command:
|
||||
|
||||
cat << \EOF >> ~/.zprofile
|
||||
# Add .NET Core SDK tools
|
||||
export PATH="$PATH:/Users/username/.dotnet/tools"
|
||||
EOF
|
||||
|
||||
And run zsh -l to make it available for current session.
|
||||
|
||||
You can only add it to the current session by running the following command:
|
||||
|
||||
export PATH="$PATH:/Users/username/.dotnet/tools"
|
||||
```
|
||||
|
||||
#### Known issues
|
||||
|
||||
##### FastAPI swagger blank screen
|
||||
|
||||
If you see a blank screen when opening the FastAPI Swagger documentation, then make sure you've activated the Safari developer tools.
|
||||
@@ -5,7 +5,7 @@ sidebar_position: 1
|
||||
|
||||
# Intro
|
||||
|
||||
Welcome to **MycroForge** – an opinionated CLI tool designed to streamline the development of FastAPI and SQLAlchemy-based backends. With MycroForge, you can effortlessly create and manage your backend projects through a powerful command line interface.
|
||||
Welcome to **MycroForge** – an opinionated CLI tool designed to streamline the development of FastAPI and SQLAlchemy-based backends. With MycroForge, you can effortlessly create backend projects through a convenient command line interface.
|
||||
|
||||
## Key Features
|
||||
|
||||
@@ -14,9 +14,3 @@ Welcome to **MycroForge** – an opinionated CLI tool designed to streamline the
|
||||
- **Migrations:** Handle database migrations seamlessly, allowing for smooth transitions and updates.
|
||||
- **Routers:** Generate and manage routers to keep your application modular and organized.
|
||||
- **CRUD Functionality:** Automatically generate basic CRUD (Create, Read, Update, Delete) operations to accelerate your development process.
|
||||
|
||||
## Purpose
|
||||
|
||||
The primary goal of MycroForge is to reduce the boilerplate code and provide a unified interface for common development tasks. By leveraging this tool, developers can focus more on writing business logic rather than repetitive setup and configuration.
|
||||
|
||||
Get started with MycroForge and enhance your backend development efficiency today!
|
||||
|
||||
@@ -28,7 +28,9 @@ locally.
|
||||
|
||||
The first step is to start the database, you can do this by running the following command in a terminal.
|
||||
|
||||
`m4g db run`
|
||||
```bash
|
||||
m4g db run
|
||||
```
|
||||
|
||||
This command starts the services defined in the `db.docker-compose.yml` file.
|
||||
You can verify that the services are up by running `docker container ls`. If everything went well, then the previous
|
||||
@@ -47,9 +49,13 @@ When you're done developing, you can shut down the local database by running `m4
|
||||
Now that the database is running, we can start to create our entities. Run the commands below to create the `Todo` &
|
||||
`Tag` entities.
|
||||
|
||||
`m4g db generate entity Tag --column "description:str:String(255)"`
|
||||
```bash
|
||||
m4g db generate entity Tag --column "description:str:String(255)"
|
||||
```
|
||||
|
||||
`m4g db generate entity Todo --column "description:str:String(255)" -c "is_done:bool:Boolean()"`
|
||||
```bash
|
||||
m4g db generate entity Todo --column "description:str:String(255)" -c "is_done:bool:Boolean()"
|
||||
```
|
||||
|
||||
After running these commands, you should find the generated entities in the `db/entities` folder of your project.
|
||||
You should also see that the `main.py` & `db/env.py` files have been modified to include the newly generated entity.
|
||||
@@ -65,7 +71,9 @@ Creating a one-to-many relation would also make sense, but for the purpose of de
|
||||
the many-to-many relation, because this one is the most complex, since it requires an additional mapping to be included
|
||||
in the database schema.
|
||||
|
||||
`m4g db link many Todo --to-many Tag`
|
||||
```bash
|
||||
m4g db link many Todo --to-many Tag
|
||||
```
|
||||
|
||||
After running this command you should see that both the `Todo` and `Tag` entities now have a new field referencing the
|
||||
a `List` containing instances of the other entity.
|
||||
@@ -79,7 +87,9 @@ examine the command. The same is true for all the other commands as well.
|
||||
Now that we've generated our entities, it's time to generate a migration that will apply these changes in the database.
|
||||
Generate the initial migration by running the following command.
|
||||
|
||||
`m4g db generate migration initial_migration`
|
||||
```bash
|
||||
m4g db generate migration initial_migration
|
||||
```
|
||||
|
||||
After running this command, you should see the new migration in the `db/version` directory.
|
||||
|
||||
@@ -88,7 +98,9 @@ After running this command, you should see the new migration in the `db/version`
|
||||
The last step for the database setup is to actually apply the new migration to the database. This can be done by running
|
||||
the following command.
|
||||
|
||||
`m4g db migrate`
|
||||
```bash
|
||||
m4g db migrate
|
||||
```
|
||||
|
||||
After running this command, you should now see a populated schema when visiting [PhpMyAdmin](http://localhost:5051).
|
||||
If for whatever reason you want to undo the last migration, you can simply run `m4g db rollback`.
|
||||
@@ -102,9 +114,13 @@ Writing this code can be boring, since it's pretty much boilerplate with some cu
|
||||
Fortunately, MycroForge can generate a good chunk of this boring code on your behalf. Run the following commands to
|
||||
generate CRUD functionality for the `Todo` & `Tag` classes.
|
||||
|
||||
`m4g api generate crud Tag`
|
||||
```bash
|
||||
m4g api generate crud Tag
|
||||
```
|
||||
|
||||
`m4g api generate crud Todo`
|
||||
```bash
|
||||
m4g api generate crud Todo
|
||||
```
|
||||
|
||||
After running this command you should see that the `api/requests`,`api/routers` & `api/services` now contain the
|
||||
relevant classes need to support the generated CRUD functionality. This could should be relatively straightforward, so
|
||||
@@ -118,15 +134,22 @@ yet. We need to be able to specify which `Tags` to add to a `Todo` when creating
|
||||
To do this, we will allow for a `tag_ids` field in both the `CreateTodoRequest` & the `UpdateTodoRequest`.
|
||||
This field will contain the ids of the `Tags` that are associated with a `Todo`.
|
||||
|
||||
Modify `CreateTodoRequest` in `api/requests/create_todo_request.py`, you might need to import `List` from `typing`.
|
||||
Modify `CreateTodoRequest` in `api/requests/create_todo_request.py`.
|
||||
|
||||
```python
|
||||
# Before
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CreateTodoRequest(BaseModel):
|
||||
description: str = None
|
||||
is_done: bool = None
|
||||
|
||||
description: str = None
|
||||
is_done: bool = None
|
||||
|
||||
# After
|
||||
from typing import List, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class CreateTodoRequest(BaseModel):
|
||||
description: str = None
|
||||
is_done: bool = None
|
||||
@@ -137,12 +160,19 @@ Modify `UpdateTodoRequest` in `api/requests/update_todo_request.py`, you might n
|
||||
|
||||
```python
|
||||
# Before
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class UpdateTodoRequest(BaseModel):
|
||||
description: Optional[str] = None
|
||||
is_done: Optional[bool] = None
|
||||
tag_ids: Optional[List[int]] = []
|
||||
description: Optional[str] = None
|
||||
is_done: Optional[bool] = None
|
||||
|
||||
# After
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
class UpdateTodoRequest(BaseModel):
|
||||
description: Optional[str] = None
|
||||
is_done: Optional[bool] = None
|
||||
@@ -280,4 +310,9 @@ Modify `TodoService.update`
|
||||
|
||||
## Test the API!
|
||||
|
||||
Run the following command.
|
||||
```bash
|
||||
m4g api run
|
||||
```
|
||||
|
||||
Go to http://localhost:5000/docs and test your Todo API!
|
||||
Reference in New Issue
Block a user