How to create a get-graphql-schema enum from Hasura? - enums

I am working on a project which is backed by Hasura. I am having difficulty creating an enum and getting it to auto-generate the values.
I've successfully created a migration according to the enum spec, and verified it is loading values into the database. Next I ran yarn hasura console, and from the console started tracking both tables I created & set BaseColor to be an enum type. I added a permission for public to SELECT from BaseColor.
Next I ran yarn hasura metadata export. That generated a tables.yml with BaseColor's table definition having is_enum true.
Then I ran, yarn update-schema (i.e. get-graphql-schema http://localhost:8080/v1/graphql > schema.graphql). The generated file is missing the BaseColor_enum I would expect to be present for an enum.

get-graphql-schema only generates an _enum for a table if that table is referenced by another.
So, if I add a foreign key that references BaseColor, it will generate BaseColor_enum, otherwise it won't.

Related

Entity Framework 6 and Oracle: The table/view does not have a primary key defined. The Entity is read-only

I have an ASP.NET Core application that uses EF6 for dealing with a third-party application's database.
Everything is working as expected, but I'm unable to insert rows into a joining table.
I have two tables, Users and Groups, and a joining table GroupUser that identifies which users are members of which groups. Users has a PK of UserId, and Groups has a PK of GroupId.
GroupUser has only 3 columns: GroupId, UserId and another column (which is irrelevant for this post). The two foreign keys in this table identify a unique record.
Every time I try to insert into GroupUser, I get the inner exception
The table/view does not have a primary key defined. The entity is read-only
The error is correct. There is no PK, but both of the FKs are marked as keys in the model. Shouldn't VS be able to use those as a PK somehow?
The inserts used to work as some point, but required some manual modification of the .edmx file as XML in order to work. Unfortunately, our version control records containing this modification have been lost (and I wasn't the one originally working on this).
I've looked at and tried about a dozen articles around this, but they generally have to do with views instead of tables, so don't seem applicable to my case. The ones that did seem applicable didn't solve the issue.
The only other clue I have for a solution is this comment I found in the code:
// Important note: If you have updated the edmx file in the [redacted]
// project and suddenly start having problems, the edmx file may need to be
// edited as an xml file so that you can make changes necessary to make
// VS believe that the GroupUser table has a primary key. See revision #[redacted]
I'm able to insert into User and Group tables just fine, and as I've said, I don't have access to the revision log mentioned.
Edit: The database is for a third-party application, and unfortunately, it's not as simple as just modifying the table to add a PK. I wish it was. Problem would be solved. But I've been advised by the vendor not to make this change, as it may have unexpected consequences, and would void our support.
How can I 'trick' EF into thinking the table has a key? I'm also open to other workarounds. Modifying the DB structure is currently out of the question.

sequel migration error ,relation already exists?

I just created a new migration file for my ruby project (e.g. 003_foo3.rb)
I use sequel 3.48.
Test in local first
$sequel -m ~/myproject/db/migration postgres://postgres#localhost/myproject_db
Error: Sequel::DatabaseError: PG::Error: ERROR: relation "bank" already exists
that 'bank' table is already in first migration file (001_foo1.rb)
I thought sequel tracks migration that already run?
What am I missing?
I feel your pain, as I get similar error messages from Sequel here and then.
Sequel creates a table called schema_info in your app database to track migrations you ran.
create_table(:schema_info) do
column :version, "int(11)", :default=>0, :null=>false
end
Either using timestamps or integer versions.
Your error message might be due to Sequel not creating that table or because you recreated your application database from scratch, in which case the schema version has been lost, thus creating your error message.
It's not possible to say what exactly happened given the information you have given.
I occasionally get similar errors, and I comment out all the migration code in the migration file, run the migrations, and then uncomment the code again.
If you are sure that you have already run a certain migration you can change the value of version field in the schema_info table.
Supposing you have the following migrations:
001_some_migration.rb
002_some_other_migration.rb
...and you already ran 001, and you get an "already exists" error, then you can set schema_info.version = 1 and run your migrations, again. Migration #1 will not be executed, but #2 will be executed directly.

Model changed during database created

I have uploaded my MVC3 project , it's s simple blog , at first it works well but after couple hours! following error appears (I've made custom error to Off to see the error)
The model backing the 'SiteContext' context has changed since the database was created. Either manually delete/update the database, or call Database.SetInitializer with an IDatabaseInitializer instance. For example, the DropCreateDatabaseIfModelChanges strategy will automatically delete and recreate the database, and optionally seed it with new data.
to solve this I have to manually delete my database and create again and then restore to the backup that I have created. but after after 2 hours again I get the error!
I really don't have any idea , what caused that ??
When you create a model and ask EF to create a database from it, EF would hash the model and store the hash value with the database. Whenever the context is created, EF recomputes the hash and matches it against what is stored at the database. If the model changes in any way, the resulting hash will be different and EF will throw the exception you have just seen. This is done in order to keep the model in sync with the database.
Is there any way the model could have changed during runtime?
One thing you could do to figure out the difference is to
1.Re-create the database from the model as you are doing now and get it scripted (script1.sql).
2.Wait till the error happens and delete the db and re-create it again and script it (script2.sql)
3.Try to compare the two and see whether you can spot a difference in the schemas.
This should give you an idea of what has changed in the model.
Goodluck

Adding columns to DB after publishing using EF CodeF and mvc nugget Scaffold

I have created a web site using mvc 3 and Ef code first , now after publishing the site and it's DB I have found out that I need to add a new columns to one of my DB table,
(the DB already has a lot of data in it )
should I add the columns direct to the DB or should I add to the class?
(just a simple string with get and set)
And how can I do it without losing my data in the DB ?
thanks
Adding the columns to the class should be enough. Evidence you can find here.
Here is the full list of changes that migrations can take care of automatically:
Adding a property or class
Nullable columns will be assigned a value of null for any existing rows of data
Non-Nullable columns will be assigned the CLR default for the given data type for any existing rows of data
Renaming a property or class
See ‘Renaming Properties & Classes’ for the additional steps required here
Renaming an underlying column/table without renaming the property/class
(Using data annotations or the fluent API)
Migrations can automatically detect these renames without additional input
Removing a property
See ‘Automatic Migrations with Data Loss’ section for more information
I suggest you to add the columns direct to the DB and to the class, and test it on the local machine.

Visual Studio 2010 Database Project - Unresolved Reference to a Synonym

We have a couple of synonyms that are being used to reference tables in a separate database (that's on the same server).
The actual synonyms are fine, but the stored procs/user defined functions that reference said synonyms show the following error:
Error 13 SQL03006: Column: [dbo].[GetCocosIndexSearched].[User ID] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [dbo].[AuditType].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[e]::[LOGIN_ID], [dbo].[EMPLOYEES].[LOGIN_ID] or [dbo].[SearchCIBirthsRequest].[e]::[LOGIN_ID]. C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Programmability\Functions\GetCocosIndexSearched_1.function.sql 21 5 RBDM.Audit.Database
[dbo].[GetCocosIndexSearched] is a function and [dbo].[EMPLOYEES] is the synonym.
These all work fine in the actual database itself - the problem lies solely with the database project. I've tried adding a reference to the separate database (either through a new database project or a database project schema), but then have conflict issues with the synonym and reference table:
Error 7 SQL04105: The model already has an element that has the same name dbo.EMPLOYEES. C:\VSTS\Corporate\WARS Audit\MAIN\Source\RBDM.Audit.Database\Schema Objects\Schemas\dbo\Synonyms\EMPLOYEES.synonym.sql 2 1 RBDM.Audit.Database
Any ideas? There's a workaround mentioned in another stackoverflow post that talks about placing the creation scripts in Script.PostDeployment.sql - sounds a bit too hacky to me.
This happens because in the caller database you must add a reference to the dependent database and specify also a value for the database name.
Look below:
Then you can create your synonym using the following code:
CREATE SYNONYM [dbo].[mytable] FOR [$(MasterDatabase)].[dbo].[mytable]

Resources