{"title":"Database","description":"","section":"cli","version":"v1.5","path":"cli/database","canonical_url":"https://amberframework.org/docs/v1.5/cli/database","markdown_url":"https://amberframework.org/docs/v1.5/cli/database.md","inherited":true,"content_markdown":"# Database\n\n## `amber db`\n\nThe `database` or `db` command is one of the most common command that you will be operating. This command allows you to work with the database engine of choice when the Amber application was generated.\n\nHere is a list of the commands available:\n\n* **create** Creates the database for the environment specified in your configuration file.\n* **drop**   Drops the database for the environment specified in your configuration file.\n* **migrate** or **m** Migrates `up` or `down` the database version\n* **rollback** Rolls back your database to a specific version or to previous version\n* **redo** Repeats the database version specified or lasted version\n* **status** Prints the current database migration status\n* **seed** Adds initial data after a database is created\n* **version** Prints the database current version.\n\n```text\namber database [COMMANDS1 COMMANDS2...]\n\nArguments:\n  COMMANDS (Accepts multiple)  drop create migrate rollback redo status version seed\n```\n\n## Example Usages\n\n### **Create**\n\n```text\n$ amber db create\nCreated database blog_development\n```\n\n{% hint style=\"warning\" %}\nStarting with version 0.3.5 - Amber made two changes regarding databases:\n\n* Amber will substitute hyphens `-` for underscores `_` in database names  to keep it PostgreSQL friendly.\n* The default user for `pg` databases is `postgres` rather than `root`in your configuration file.\n\n`postgres://postgres:@localhost:5432/microsecond_blog_development`\n{% endhint %}\n\n```text\n$ amber new microsecond-blog\n$ cd microsecond-blog\n$ amber db create\nCreated database microsecond_blog_development\n```\n\n### **Drop**\n\n```text\n$ amber db drop\nDropped database blog_development\n```\n\n### **Migrate**\n\n```text\n$ amber db migrate\nMigrating db, current version: 0, target: 20170928204246\nOK   20170928204246_create_post.sql\n```\n\n### **Rollback**\n\n```text\n$ amber db rollback\nMigrating db, current version: 20170928204246, target: 0\nOK   20170928204246_create_post.sql\n```\n\n### **Redo**\n\n```text\n$ amber db redo\nMigrating db, current version: 20170928204246, target: 0\nOK   20170928204246_create_post.sql\nMigrating db, current version: 0, target: 20170928204246\nOK   20170928204246_create_post.sql\n```\n\n### **Status**\n\n```text\n$ amber db status\nApplied At                  Migration\n=======================================\n2017-09-28 20:44:22 UTC  -- 20170928204246_create_post.sql\n```\n\n### **Seed**\n\n```text\n$ amber db seed\nSeeded database\n```\n\n### **Version**\n\n```text\n$ amber db version\n20170928204246\n```"}