0
# Database Commands
1
2
MikroORM CLI database management commands for core database operations including creation and SQL import functionality.
3
4
## Capabilities
5
6
### Create Database
7
8
Creates the database if it doesn't exist. Useful for initial setup and CI/CD pipelines.
9
10
```typescript { .api }
11
/**
12
* Create database command
13
*/
14
command: "database:create"
15
16
// No additional options beyond global options
17
```
18
19
**Usage Examples:**
20
21
```bash
22
# Create database with default configuration
23
mikro-orm database:create
24
25
# Create database with specific config file
26
mikro-orm database:create --config ./orm.config.js
27
28
# Create database for specific context
29
mikro-orm database:create --context production
30
```
31
32
### Import SQL File
33
34
Imports SQL file contents directly into the database. Supports multiple SQL statements and database-specific SQL syntax.
35
36
```typescript { .api }
37
/**
38
* Import SQL file command
39
*/
40
command: "database:import <file>"
41
42
interface ImportOptions extends BaseArgs {
43
file: string; // Path to SQL file to import (required positional argument)
44
}
45
```
46
47
**Usage Examples:**
48
49
```bash
50
# Import SQL file
51
mikro-orm database:import ./schema.sql
52
53
# Import with specific configuration
54
mikro-orm database:import ./data.sql --config ./orm.config.js
55
56
# Import for specific context
57
mikro-orm database:import ./init.sql --context development
58
```
59
60
## Command Arguments
61
62
### database:create
63
64
No additional arguments required beyond global options.
65
66
### database:import
67
68
- `<file>`: Required positional argument specifying the path to the SQL file to import
69
70
## Global Options
71
72
All database commands support:
73
- `--config`: Path to ORM configuration file(s)
74
- `--contextName` / `--context`: Configuration context name
75
76
## Error Handling
77
78
### database:create Errors
79
80
- **Database already exists**: Command will succeed if database already exists
81
- **Insufficient permissions**: Database user must have CREATE DATABASE privileges
82
- **Connection errors**: Network or authentication issues will prevent database creation
83
- **Driver limitations**: Only available for SQL-based drivers (not MongoDB)
84
85
### database:import Errors
86
87
- **File not found**: SQL file path must exist and be readable
88
- **SQL syntax errors**: Invalid SQL will cause import to fail
89
- **Permission errors**: Database user must have appropriate INSERT/CREATE privileges
90
- **Large file handling**: Very large SQL files may require connection timeout adjustments
91
- **Multiple statement support**: Driver must support multiple SQL statements
92
93
## Supported Database Systems
94
95
These commands work with:
96
- **PostgreSQL**: Full support for database creation and SQL import
97
- **MySQL/MariaDB**: Full support for database creation and SQL import
98
- **SQLite**: Database creation creates file, SQL import supported
99
- **MongoDB**: Not applicable (NoSQL database)
100
101
## Related Configuration
102
103
Database commands work with these MikroORM configuration options:
104
105
```typescript { .api }
106
interface DatabaseConfiguration {
107
driver: string; // Database driver type
108
clientUrl?: string; // Connection string
109
host?: string; // Database host
110
port?: number; // Database port
111
user?: string; // Database user
112
password?: string; // Database password
113
dbName: string; // Database name
114
multipleStatements?: boolean; // Enable multiple SQL statements (for import)
115
}
116
```