lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I'm having trouble figuring out a best way to write a configuration file with Lua.

The configuration file holds the connect string for our database accounts. Each entry has an "id" field and our load processes use that id to get the connect string. Something like
  Cn = dbConnect('batch@raw')
That shields them from having to know the host, etc. And makes it simple to migrate the processes from development through test to production.

The configuration file looks like:

database {
  entry { id = 'batch@raw'
    ,dev  = account { host = 'rawdev' , name = 'batch01', instance = 'raw' }
    ,test = account { host = 'rawtest', name = 'batch11', instance = 'raw' }
    ,prod = account { host = 'rawprod', name = 'batch21', instance = 'raw' }
  },
  entry { id = 'batch@staging'
    ,dev  = account { host = 'stgdev' , name = 'batch02', instance = 'staging' }
    ,test = account { host = 'stgtest', name = 'batch12', instance = 'staging' }
    ,prod = account { host = 'stgprod', name = 'batch22', instance = 'staging' }
  },
}

I have functions database, entry and account that create their tables. This works but it doesn't look as pretty as I think that it should with Lua. That makes me worry about how easy it will be for our operations team to manage. None of them are programmers and they'll be making the updates if the account information changes.

Is there a different approach that would be easier to understand?

I think that something like

batch@raw
    dev  = account { host = 'rawdev' , name = 'batch01', instance = 'raw' }
    test = account { host = 'rawtest', name = 'batch11', instance = 'raw' }
    prod = account { host = 'rawprod', name = 'batch21', instance = 'raw' }
batch@staging
    dev  = account { host = 'stgdev' , name = 'batch02', instance = 'staging' }
    test = account { host = 'stgtest', name = 'batch12', instance = 'staging' }
    prod = account { host = 'stgprod', name = 'batch22', instance = 'staging' }

would work but that's no longer a configuration file written in Lua.