Skip to content

Commit

Permalink
Merge pull request #173 from Hexastack/120-issue-upgrade-ts-migrate-m…
Browse files Browse the repository at this point in the history
…ongoose-and-update-patch-if-necessary

Fix: Database Migrations through CLI
  • Loading branch information
marrouchi authored Oct 9, 2024
2 parents 4a1d52c + 395d160 commit c638e29
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 202 deletions.
28 changes: 15 additions & 13 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
[Hexabot](https://hexabot.ai/)'s API is a RESTful API built with NestJS, designed to handle requests from both the UI admin panel and various communication channels. The API powers core functionalities such as chatbot management, message flow, NLU (Natural Language Understanding), and plugin integrations.

## Key Features

- **RESTful Architecture:** Simple, standardized API architecture following REST principles.
- **Multi-Channel Support:** Handles requests from different communication channels (e.g., web, mobile).
- **Modular Design:** Organized into multiple modules for better scalability and maintainability.
- **Real-Time Communication:** Integrates WebSocket support for real-time features.

## API Modules

The API is divided into several key modules, each responsible for specific functionalities:

### Core Modules

- **Analytics:** Tracks and serves analytics data such as the number of messages exchanged and end-user retention statistics.
- **Attachment:** Manages file uploads and downloads, enabling attachment handling across the chatbot.
- **Channel:** Manages different communication channels through which the chatbot operates (e.g., web, mobile apps, etc.).
Expand All @@ -24,6 +27,7 @@ The API is divided into several key modules, each responsible for specific funct
- **Settings:** A module for management all types of settings that can be adjusted to customize the chatbot.

### Utility Modules

- **WebSocket:** Adds support for Websicket with Socket.IO, enabling real-time communication for events like live chat and user interactions.
- **Logger:** Provides logging functionality to track and debug API requests and events.

Expand Down Expand Up @@ -60,25 +64,24 @@ $ npm run test:cov
```

## Migrations
The API includes a migrations feature to help manage database schema and data changes over time. Migrations allow you to apply or revert changes to the database in a consistent and controlled manner.

Hexabot includes a migrations feature to help manage database schema and data changes over time. Migrations allow you to apply or revert changes to the database in a consistent and controlled manner.

### Creating a Migration

You need to navigate to the `api` folder to run the following commands.
To create a new migration, use the following command:
To create a new migration, use the following command from the root directory of Hexabot:

```bash
$ npm run create-migration <migration-name>
$ npx hexabot migrate create <migration-name>
```

Example:

```bash
$ npm run create-migration all-users-language-fr
$ npx hexabot migrate create all-users-language-fr
```

This command generates a new migration file in the `./migrations` folder. The file will look like this:
This command generates a new migration file in the `/api/migrations` folder. The file will look like this:

```typescript
import getModels from '@/models/index';
Expand Down Expand Up @@ -107,20 +110,18 @@ export async function down(): Promise<void> {}

### Running Migrations Up

All migrations are run automatically when the app starts.

Alternatively, you can run the following command in the `root` directory to run all pending migrations:
You can run the following command to run all pending migrations:

```bash
$ make migrate-up
$ npx hexabot migrate up
```

### Running Migrations Manually

If you want to run specific actions manually, you need to gain access to the `api` container and use the following command to run what you specifically want:
If you want to run specific actions manually, you can get help by running the following command:

```bash
$ npm run migrate -h
$ npx hexabot migrate help
```

## Documentation
Expand All @@ -131,13 +132,14 @@ It's also possible to access the API reference documentation by running `npm run

For detailed information about the API routes and usage, refer to the API documentation or visit [https://docs.hexabot.ai](https://docs.hexabot.ai).

## Contributing

## Contributing
We welcome contributions from the community! Whether you want to report a bug, suggest new features, or submit a pull request, your input is valuable to us.

Feel free to join us on [Discord](https://discord.gg/rNb9t2MFkG)

## License

This software is licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:

1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand Down
63 changes: 0 additions & 63 deletions api/migrations/config/create.ts

This file was deleted.

Loading

0 comments on commit c638e29

Please sign in to comment.