# Attemping to generate a schema

**URL:** <https://discourse.rom-rb.org/t/attemping-to-generate-a-schema/588>\
**Category:** Issues\
**Created:** [January 20, 2023, 1:37am UTC](https://discourse.rom-rb.org/t/attemping-to-generate-a-schema/588 "2023-01-20T01:37:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rfb](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/rfb/32/286_2.png) [@rfb](https://discourse.rom-rb.org/u/rfb)\
**Post date:** [January 20, 2023, 1:37am UTC](https://discourse.rom-rb.org/t/attemping-to-generate-a-schema/588/1 "2023-01-20T01:37:38Z")

</div>

Hi there,

I’m attempting to add attributes to a schema using an external configuration, but it appears the blocks passed into the DSL are stripped of their execution context.

Are there any other options for creating a schema? Is it possible to define a schema using a hash rather then using the DSL?

Here is simplified example:

```auto
require "rom"

attrs = [:one, :two, :three]

rom = ROM.container(:sql, 'sqlite::memory') do |config|
  class Tasks < ROM::Relation[:sql]
    schema(:tasks) do
      attrs.each do |attr|
        attribute attr, Types::String
      end
    end
  end

  config.register_relation(Tasks)
end

```

```plaintext
rfb@simple:~/Projects/gpe$ ruby test.rb 
test.rb:9:in `block in <class:Tasks>': undefined local variable or method `attrs' for #<ROM::SQL::Schema::DSL:0x00007f53d8770c58> (NameError)

      attrs.each do |attr|
      ^^^^^
	from /home/rfb/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rom-core-5.3.0/lib/rom/schema/dsl.rb:184:in `instance_exec'
	from /home/rfb/.asdf/installs/ruby/3.1.0/lib/ruby/gems/3.1.0/gems/rom-core-5.3.0/lib/rom/schema/dsl.rb:184:in `call'

```

Also thank you to the creator and maintainers. This is an exceptional library!

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/alassek/32/260_2.png) [@alassek](https://discourse.rom-rb.org/u/alassek)\
**Post date:** [January 27, 2023, 8:04pm UTC](https://discourse.rom-rb.org/t/attemping-to-generate-a-schema/588/2 "2023-01-27T20:04:34Z")

</div>

Can you speak more about why you need to do this in the first place?

Generally, if you do not need to define the schema manually with the DSL, you ought to be able to just use `infer: true` to generate schema from the SQL information.
