edgedb / edgedb-docker

Official Docker Image packaging for EdgeDB
83 stars 16 forks source link

Docker init script does not create any type #29

Open Methrat0n opened 3 years ago

Methrat0n commented 3 years ago

While starting a new project I decide to use this database as I quiet like the idea and the features you added on top of postgreSQL. I try using your provided docker as I prefer my team to be able to start our whole stack by a simple docker-compose up but I cant get it to work.

Here is the relevant part of the docker-compose :

  gateway-db:
    build:
      dockerfile: dockers/gatewayDB-Dockerfile
      context: .
    restart: unless-stopped
    container_name: gateway-db
    ports:
      - "5656:5656"
    environment:
      EDGEDB_AUTH_METHOD: "trust"
      EDGEDB_GENERATE_SELF_SIGNED_CERT: 1

The dockerfile :

FROM edgedb/edgedb

COPY ./dockers/gatewayDB-default.esdl /edgedb-bootstrap.d/default.esdl

And finally the esdl :

module default {
  type Subscription {
    required property libraryUrl -> str;
  }
};

using extension graphql;
using extension edgeql_http;

The container do start and everything seams ok but I cant get a request to work. I use the official edgeDb cli to connect to my container and can execute requests. For example I can list all tables :

edgedb> SELECT name := schema::ObjectType.name;
{
  'std::BaseObject',
  'std::Object',
  'std::FreeObject',
  'schema::Object',
  'schema::SubclassableObject',
  'schema::Type',
  'schema::PseudoType',
  'schema::Module',
  'schema::CollectionType',
  'schema::Array',
  'schema::TupleElement',
  'schema::Tuple',
  'schema::Delta',
  'schema::Annotation',
  'schema::AnnotationSubject',
  'schema::InheritingObject',
  'schema::Parameter',
  'schema::CallableObject',
  'schema::VolatilitySubject',
  'schema::Constraint',
  'schema::ConsistencySubject',
  'schema::Index',
  'schema::Source',
  'schema::Pointer',
  'schema::Alias',
  'schema::ScalarType',
  'schema::ObjectType',
  'schema::Link',
  'schema::Property',
  'schema::Function',
  'schema::Operator',
  'schema::Cast',
  'schema::Migration',
  'schema::Extension',
  'sys::SystemObject',
  'sys::Database',
  'sys::ExtensionPackage',
  'sys::Role',
  'cfg::ConfigObject',
  'cfg::AuthMethod',
  'cfg::Trust',
  'cfg::SCRAM',
  'cfg::Auth',
  'cfg::AbstractConfig',
  'cfg::Config',
  'cfg::InstanceConfig',
  'cfg::DatabaseConfig',
}

But, as you see, the Subscription type does not seams to have been created and I cant do any request on it :

edgedb> SELECT Subscription;
error: object type or alias 'default::Subscription' does not exist
  ┌─ query:1:8
  │
1 │ SELECT Subscription;
  │        ^^^^^^^^^^^^ error

Therefore I think there is a problem in your docker or maybe further inside, I dunno :(

tailhook commented 3 years ago

You need to apply migrations to have the schema pushed into the database. This should provide some guidance. Although, you should replace -I chatapp to your own way to specify configuration parameters (perhaps just environment variables).

Methrat0n commented 3 years ago

I did not had the time to try your migration guide, will do later today. But I feels like I misunderstood something : isn't any esdl file copied into edgedb-bootstrap.d suppose to be executed ? this is where I've gotten this idea

tailhook commented 3 years ago

The *.esdl files are schema files. While they can be used to create initial schema, we can't easily update the database schema using just the schema definition (for example, it's impossible to determine whether the column was renamed or a new column was created).

So to migrate to the new schema while retaining the old data you have to create a dbschema/migrations/*.edgeql file that contains instructions on how to do the migration. This includes the first time the schema is applied.

As long as you run edgedb create-migration and put generated dbschema/migrations/* files into the container migrations will applied. And then every time you restart that container it will apply new migrations too (or you can run edgedb migrate instead of restarting). But you have to learn edgedb create-migration workflow anyway.

That said /edgedb-bootstrap.d/*.edgeql (note: not *.esdl) files should not be used to migrate schema or data. They are there to setup authentication schemes, authorization rules, user roles, instance configuration options, and similar things. Please, use migration workflow for schema and data migrations.

Methrat0n commented 3 years ago

I completely agree wit the idea of using migrations and I even like the migration flow, in production. In early dev phase the database is trash often and being able to rebuild it in one command seams necessary to me. If I cannot use the edgedb-bootstrap.d with esdl file, as it does not seams to work, how should I go about that ?

tailhook commented 3 years ago

Just do rm dbschema/migrations/*.esdl; edgedb create-migration --non-interactive. And you're good to go (as long as database is clean).

You can even keep dbschema/migrations in the docker container, so every time you restart the container migrations are cleared, and I think you can add edgedb create-migration --non-interactive command into a /edgedb-bootstrap.d/migration.sh. Just make sure that data dir is also new every time you restart container (i.e. by not putting it into a volume)

Methrat0n commented 3 years ago

I just tried the migration creation. Here is my new Dockerfile :

FROM edgedb/edgedb

COPY ./dockers/gatewayDB-default.esdl /dbschema/migrations/default.esdl

ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["edgedb-server"]

Then I enter  edgedb -I docker migration create as edgedb -I docker create-migration isn't recognized but it answers with

edgedb error: could not read schema in ./dbschema: could not read directory `./dbschema`: No such file or directory (os error 2)

Which seams like I've put the esdl file in the wrong place but I can't find the right one anywhere in the documentation.