Generate code¶
The make:* commands write the first files of a class. Each command puts a
file in the folder named after what the class is. A command never overwrites a
file that exists.
The commands are in the xtr-maker package. The package is a development
dependency, so a deployment has none of these commands.
This guide generates an entity, the revision of its table, and a message.
Before you start¶
- You have an application with the name
shop. If not, create an application. - The application has
xtr-makerin itsdevdependencies. Add a package shows the command. uv run shop debug:bundlesshowsmakerwith the stateactive.- The
ormbundle and themessengerbundle are active. - The database of the application runs, and it has each revision.
Procedure¶
- Open a terminal in the directory of the application.
- List the commands that the application has:
The list holds one command for each library whose bundle is active. 3. Write an entity with one field:
The command writes src/shop/entity/book.py and
src/shop/repository/book_repository.py.
4. Open src/shop/entity/book.py and add the other properties of the entity.
5. Write the revision of the new table:
The command writes a file under migrations/, and it names the revision.
6. Read the new revision.
7. Apply the revision to the database:
- Write a message and its handler:
The command writes src/shop/message/place_order.py and
src/shop/message_handler/place_order_handler.py.
9. Open the message and add its fields.
10. Open the handler and write what it does with the message.
Caution
Apply every revision before you run make:migration. The command compares
the database with the table definitions. A database that is behind reports
how many revisions wait, and it writes no revision.
The other commands¶
| Command | What it writes | It needs this bundle |
|---|---|---|
make:schedule |
the provider of a schedule, in scheduler/ |
scheduler |
make:webhook |
the request parser, the consumer of the events, and a route module in config/packages/ |
webhook |
make:command |
a console command class, in command/ |
the console bundle alone |
make:listener |
a class in event_listener/, or a class in event_subscriber/ |
event_dispatcher |
A command that has no -n option on its command line asks for each value. The
README of xtr-maker lists each argument, each option and each question.
Note
A run writes every file together. A target that exists ends the run, and no file reaches the disk.
Next step¶
- The application layout lists the folder of each type of class.
- Console commands lists the commands of the xtr packages.
- The README of xtr-maker describes each command in full.
- The API reference
documents
Generator,FileManagerandTemplateRenderer.