Repository: getredash/redash

Issue:
Queries search is not working on release/7.0.x
### Issue Summary

I try building docker image with the redash dockerfile and start by docker-compose. But queries search is not working

### Steps to Reproduce

![Untitled](https://user-images.githubusercontent.com/6704470/54521288-93d2ad80-49a5-11e9-9794-94572b6698d0.gif)

Check out the queries table and find that search_vector is null.
![1](https://user-images.githubusercontent.com/6704470/54521423-de542a00-49a5-11e9-9f37-5b5923042973.png)

### Technical details:

* Redash Version: release/7.0.x
* Browser/OS: Chrome Mac
* How did you install Redash: redash setup



Discussion:
How did you build the database?
> How did you build the database?

use redash/setup/docker-compose.yml

```
postgres:
  image: postgres:9.5.6-alpine
  env_file: /opt/redash/env
  volumes:
    - /opt/redash/postgres-data:/var/lib/postgresql/data
  restart: always
```
Yes, but how did you create the database tables? 
> Yes, but how did you create the database tables?

Replace the original image with the built image in redash/setup/docker-compose.yml,
and run in redash/setup
```
docker-compose -f docker-compose.yml -p redash run --rm server create_db
```
Just to make sure: this is a new install not an upgrade, correct?
> Just to make sure: this is a new install not an upgrade, correct?

Yes, just to test the new version
Thanks. I managed to confirm this :-(

@jezdez maybe we need to setup something for the trigger to be created when creating DB from scratch (using the `create_db` command)?
Ah, right, we simply have to run the migrations in the `create_tables` command so this gets picked up. I don't think there is a better way to cover ongoing schema changes than the migration system, it's built for that exact purpose. I don't recall why `create_tables` was written like this to be honest.
Because from my experience migrations don't age well. Usually over time they tend to break. 

When creating a database from scratch the ORM usually does a better job by creating the tables from their definitions than trying to mutate the DB over all the different versions we ever had.
Yeah, I've had that experience as well, especially when migrations are leaky and codify subtle data model structure or use specific code paths. I don't have enough experience with it to say if that's the case for Alembic though.

One thing we could consider is resetting the migrations to reduce the risk of decay, basically squash them to just a few migration files. Alternatively we could create a command to hook up the search update trigger manually if needed.

Resolving patch:
diff --git a/redash/cli/database.py b/redash/cli/database.py
--- a/redash/cli/database.py
+++ b/redash/cli/database.py
@@ -1,5 +1,6 @@
 import time
 
+import sqlalchemy
 from flask.cli import AppGroup
 from flask_migrate import stamp
 from sqlalchemy.exc import DatabaseError
@@ -25,6 +26,8 @@ def create_tables():
     from redash.models import db
 
     _wait_for_db_connection(db)
+    # To create triggers for searchable models, we need to call configure_mappers().
+    sqlalchemy.orm.configure_mappers()
     db.create_all()
 
     # Need to mark current DB as up to date


Test patch: