# Add migrations

At this point, you could add the Resource Types, Actions and Policies by hand, but we'll do it migrations for two reasons:

* It's easier for this tutorial, and
* For real apps, that change over time, this is best practice anyway.

Add these two files to a folder called 'cerberusmigrations' under 'backend/go':

{% embed url="<https://gist.github.com/superkruger/488a33014c4ed89cb745db589e33f33e>" %}

Don't worry too much about the details of these files for now. Suffice it to say they act like normal database migrations, creating or deleting data for each migration version.

It's accomplished with a DSL (domain specific language) detailed in [Migrations](/migrations/scripting-language.md)

We always need four things:

* Resource Types
* Actions
* Policies
* Actions linked to Policies

The precise details of these four elements will depend on your domain and how you want to set up permissions in your product.

Add the following line to the top of the 'go.mod' file:

<pre class="language-go"><code class="lang-go">module cerberus-examples

go 1.18

replace github.com/golang-migrate/migrate/v4 => github.com/a11n-io/migrate/v4 v4.15.13
<strong>
</strong>require (
	github.com/a11n-io/go-cerberus v0.3.39
	.
	.
	.
</code></pre>

Next, add the following imports to 'cmd/api/api.go':

```go
// Add imports here
cerberus "github.com/a11n-io/go-cerberus"
cerberusmigrate "github.com/golang-migrate/migrate/v4/database/cerberus"
```

And the following code to the main function in the same file:

```go

// Add cerberus client and migration code here
cerberusClient := cerberus.NewClient(_env.CERBERUS_HOST, _env.CERBERUS_API_KEY, _env.CERBERUS_API_SECRET)

cdriver, err := cerberusmigrate.WithInstance(cerberusClient, &cerberusmigrate.Config{})
if err != nil {
	log.Fatalf("could not get cerberus driver: %v", err.Error())
}
cm, err := migrate.NewWithDatabaseInstance(
	"file://cerberusmigrations", "cerberus", cdriver)
if err != nil {
	log.Fatalf("could not get cerberus migrate: %v", err.Error())
} else {
	if err := cm.Up(); err != nil {
		log.Println(err)
	}
	log.Println("cerberus migration done")
}
```

Run the app again:

```
docker-compose build
docker-compose up
```

The console should report that the migration has run, and on the dashboard you should see one migration, and all the created Resource Types, Actions and Policies:

<div><figure><img src="/files/q8shv5Uk2BpMgrPqX0Gp" alt=""><figcaption></figcaption></figure> <figure><img src="/files/K4k9snTRvdhzPfAkIdlz" alt=""><figcaption></figcaption></figure> <figure><img src="/files/WwJdBIAaPIPTRzkcTAze" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.a11n.io/tutorial/creating-static-rules/add-migrations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
