ent/doc: migration, dialects and websire changes
Reviewed By: alexsn Differential Revision: D17155041 fbshipit-source-id: 378cd47cb8b6111b3daba2860ae2fa02b7f2b856
@@ -2,4 +2,17 @@
|
||||
id: dialects
|
||||
title: Supported Dialects
|
||||
---
|
||||
Lorem ipsum.
|
||||
|
||||
## MySQL
|
||||
|
||||
MySQL supports all the features that are mentioned in the [Migration](migrate.md) section,
|
||||
and it's being tested constantly on the following 3 versions: `5.6.35`, `5.7.26` and `8`.
|
||||
|
||||
## SQLite
|
||||
|
||||
SQLite was developed only for testing, and it does not support the incremental updates for tables.
|
||||
|
||||
|
||||
## Gremlin
|
||||
|
||||
Gremlin does not support migration nor indexes, and **<ins>it's considered experimental</ins>**.
|
||||
@@ -4,12 +4,16 @@ title: Quick Introduction
|
||||
sidebar_label: Quick Introduction
|
||||
---
|
||||
|
||||
`ent` is a simple, yet powerful entity framework for Go built with the following principles:
|
||||
`ent` is a simple, yet powerful entity framework for Go built on SQL/Gremlin with the following principles:
|
||||
- Easily modeling your data as a graph structure.
|
||||
- Defining your schema as code.
|
||||
- Static typing based on code generation.
|
||||
- Simplifying graph traversals.
|
||||
|
||||
<br/>
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
```console
|
||||
|
||||
@@ -2,4 +2,114 @@
|
||||
id: migrate
|
||||
title: Database Migration
|
||||
---
|
||||
Lorem ipsum.
|
||||
|
||||
The migration support for `ent` provides the option for keeping the database schema
|
||||
aligned with the schema objects defined in `ent/migrate/schema.go` under the root of your project.
|
||||
|
||||
## Auto Migration
|
||||
|
||||
Run the auto-migration logic in the initialization of the application:
|
||||
|
||||
```go
|
||||
if err := client.Schema.Create(ctx); err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
```
|
||||
|
||||
`Create` creates all database resources needed for your `ent` project. By default, `Create` works
|
||||
in an *"append-only"* mode; which means, it only creates new tables and indexes, appends columns to tables or
|
||||
extends column types. For example, changing `int` to `bigint`.
|
||||
|
||||
What about dropping columns or indexes?
|
||||
|
||||
## Drop Resources
|
||||
|
||||
`WithDropIndex` and `WithDropColumn` are 2 options for dropping table columns and indexes.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"<project>/ent"
|
||||
"<project>/ent/migrate"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := sql.Open("mysql", "root:pass@tcp(localhost:3306)/test")
|
||||
if err != nil {
|
||||
log.Fatalf("failed connecting to mysql: %v", err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
client := ent.NewClient(ent.Driver(db))
|
||||
// Run migration.
|
||||
err = client.Schema.Create(
|
||||
ctx,
|
||||
migrate.WithDropIndex(true),
|
||||
migrate.WithDropColumn(true),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
In order to run the migration in debug mode (printing all SQL queries), run:
|
||||
|
||||
```go
|
||||
err := client.Debug().Schema.Create(
|
||||
ctx,
|
||||
migrate.WithDropIndex(true),
|
||||
migrate.WithDropColumn(true),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
```
|
||||
|
||||
## Universal IDs
|
||||
|
||||
By default, SQL primary-keys start from 1 for each table; which means that multiple entities of different types
|
||||
can share the same id. Unlike AWS Neptune, where vertex ids are UUIDs.
|
||||
|
||||
This does not work well if you work with [GraphQL](https://graphql.org/learn/schema/#scalar-types) which requires
|
||||
the object identifier to be unique.
|
||||
|
||||
To enable the universal-ids for your project, pass the `WithGlobalUniqueID` option to the migration.
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
|
||||
"<project>/ent"
|
||||
"<project>/ent/migrate"
|
||||
|
||||
"github.com/facebookincubator/ent/dialect/sql"
|
||||
)
|
||||
|
||||
func main() {
|
||||
db, err := sql.Open("mysql", "root:pass@tcp(localhost:3306)/test")
|
||||
if err != nil {
|
||||
log.Fatalf("failed connecting to mysql: %v", err)
|
||||
}
|
||||
ctx := context.Background()
|
||||
client := ent.NewClient(ent.Driver(db))
|
||||
// Run migration.
|
||||
if err := client.Schema.Create(ctx, migrate.WithGlobalUniqueID(true)); err != nil {
|
||||
log.Fatalf("failed creating schema resources: %v", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**How does it work?** `ent` migration allocates a 1<<32 range for the ids of each entity (table),
|
||||
and store this information in a table named `ent_types`. For example, type `A` will have the range
|
||||
of `[1,4294967296)` for its ids, and type `B` will have the range of `[4294967296,8589934592)`, etc.
|
||||
|
||||
Note that if this option is enabled, the maximum number of possible tables are **65535**.
|
||||
@@ -57,6 +57,10 @@ class Footer extends React.Component {
|
||||
</a>{' '}
|
||||
for more details.
|
||||
</span>
|
||||
<br/><br/>
|
||||
<span className="copyright">
|
||||
The homepage was designed by Moriah Rich.
|
||||
</span>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class HomeSplash extends React.Component {
|
||||
</div>
|
||||
</div>
|
||||
<p className="projectDesc">
|
||||
A simple API for modeling any graph using schema as Go objects
|
||||
Simple, yet powerful ORM for modeling and querying data.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -105,6 +105,7 @@ in the LICENSE file in the root directory of this source tree.
|
||||
@media only screen and (max-width: 800px) {
|
||||
.gopherGraph {
|
||||
margin-top: 25px;
|
||||
display: block!important;
|
||||
}
|
||||
.features {
|
||||
margin: 60px auto 0 !important;
|
||||
@@ -181,7 +182,6 @@ body {
|
||||
color: white;
|
||||
text-align: left;
|
||||
margin-left: 5px;
|
||||
max-width: 520px;
|
||||
margin-bottom: 19px;
|
||||
}
|
||||
|
||||
@@ -327,6 +327,10 @@ a {
|
||||
height: 230px;
|
||||
}
|
||||
|
||||
#gopher-schema-as-code {
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 1500px) {
|
||||
.gridBlock .twoByGridBlock img,
|
||||
.gridBlock .threeByGridBlock img,
|
||||
|
||||
|
Before Width: | Height: | Size: 17 KiB |
|
Before Width: | Height: | Size: 32 KiB |
|
Before Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 26 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 28 KiB |