Scoping problem across multiple files [message #1665922] |
Wed, 11 March 2015 13:03 |
Ian Warwick Messages: 44 Registered: April 2012 |
Member |
|
|
I am working on a second generation of a grammar that uses the sqlite syntax as well as extra constructs to define migrations, and this can be done across multiple files
for instance
first.mickey
database com.example.ExampleDB
migration 1 {
create table books (
id integer,
title text
);
}
second.mickey
database com.example.ExampleDB
migration 2 {
alter table books add column author text;
}
third.mickey
database com.example.ExampleDB
migration 3 {
alter table books rename to manuals;
}
fourth.mickey
database com.example.ExampleDB
migration 4 {
create view stuff as
select id, title, author from manuals;
}
This issue I am facing is at migration 4, we select from manuals, which was previously called books, in order to calculate the scope for select columns in migration 4 manuals I need to work back through the migrations to grab all columns from books and manuals, I hope this makes sense.
The problem is the global scope cannot see the migration blocks, so I can't think of how I can get hold of migrations in my scope provide in order to calculate what can be seen since migrations define changes, means that reference names could change.
Would be great if someone could point me in the right direction.
UPDATE
One way I thought of solving this is to modify the grammar to have named migrations rather than numbered, ie:_
MigrationBlock:
{MigrationBlock}
'migration' name=ID 'from' from=[MickeyBlock|QualifiedName] '{' (statements+=DDLStatement ';')* '}';
ie:-
migrate initial_migration {
create table books (
id integer,
title text
);
}
migrate authors_migration from initial_migration {
alter table books add column author text;
}
then that would link the migrations together and scope easily across files without having to manually scope migrations.
but a compromise on the syntax also means more typing.
If I can get my numbered migrations in every scope, then I could go with the first approach, but I fear that might mean force loading all models for every scope calculation?
Regards,
Ian
[Updated on: Tue, 17 March 2015 19:32] Report message to a moderator
|
|
|
Re: Scoping problem across multiple files [message #1681843 is a reply to message #1665922] |
Tue, 17 March 2015 13:38 |
Ian Warwick Messages: 44 Registered: April 2012 |
Member |
|
|
Hey xtext people.
I am still trying to get scope on the migration blocks in the grammar I described.
I tried this:
var dummy = MickeyLangFactory.eINSTANCE.createMigrationBlock();
var scope = delegateGetScope(dummy, MickeyLangPackage.Literals.MIGRATION_BLOCK__FROM);
val name = QualifiedName.create(model.databaseName)
scope.allElements.filter[e|e.name.startsWith(name)]
.map[e|e.EObjectOrProxy]
Which is basically a hack, because in my scope I do not have access to these specific blocks so I try to fake a migration block (which points to a previous migration by cross reference on unique name) but it crashes when doing delegateGetScope(...)
Please see the model files here https://github.com/justeat/mickeydb/tree/master/com.justeat.mickeydb.android.example/src
I my grammar files that do not declare migrations should cross reference to a snapshot of the database (all migrations calculated):
Specifically the file which defines zero migrations:
database com.example.mickeydbexample.TakeawaysDB
create temp view all_restaurants as
select
t._id as _id,
t.name as takeaway_name,
t.description as takeaway_description,
t.city as takeaway_city,
t.cuisines as takeaway_cuisines,
t.rating as takeaway_rating
from restaurants as t
See https://github.com/justeat/mickeydb/blob/master/com.justeat.mickeydb.android.example/src/takeaways.init.mickey
I want the statements to effectively be able to look into the migrations to calculate whats available at a certain database snapshot point.
There must be an easy way to get access or load all resources within a scope? does it mean loading all resources on every build?
I think if I can get hold of the migrations from every scope point I can calculate what is visible but without them, I have no idea of what the current state of the database is so unable to provide decent editor assistance and cross referencing
I hope my question makes sense, I did try a few things but still not come up with a good solution, any help would be massively appreciated
|
|
|
Powered by
FUDForum. Page generated in 0.02713 seconds