Liquibase Data Type Mapping documentation - database

Sorry, this question seems stupid, but I tried 1 hour searching and didn't find anything.
So I'm using liquibase for multiple databases(e.g. MSSQL, Oracle and MySQL), when I say:
addColumn(tableName: "ABC_TEST") {
column(name: "IS_ACTIVE", type: "boolean")
}
How do I know if the type "boolean" will be converted to proper types for each database?
And is there any documentation I can find for the data type mapping? If I want to add one more column which is foreign key, which type should I use?

Checkout this question (and answers) to see the available types that liquibase offers.
In my answer to that question there is a link to the relevant liquibase classes that do the translation to the db specific types.
When you created the table that has the primary key with a "liquibase type" then liquibase will have translated this to the db specific type.
Then your foreign key should just use the same type and liquibase will translate this likewise.
E.g. check out the class BigIntType.
With liquibase you would just use the "liquibase type": BIGINT.
On Oracle DBs it will translate to ("NUMBER", 38,0).
On MSSQL it will translate to ("BIGINT").

Liquibase has a concept of database dialects, much like Hibernate's. It uses these to know how to generate the correct DDL statements to add/change/delete columns, foreign keys, etc. When it connects to the database it uses the JDBC metadata to determine which database type you're using, and uses that to determine the correct dialect.

Related

GUI to create and fill database with data and export it to sqlite

So, I have a relatively common task, and hope to get some suggestions here.
Idea is that I have a small database in mind, database will have at least 2 types of tables:
dictionary-table - it will have just the id and few columns of text
aggregation-table - it should combine different dictionary entries into some aggregation, so it will be basically mapping id's of different dictionary entries all together.
So, what I hoped to do is to have some software that will help me to fill database easily. I will add data to dictionary-tables, and will say that 'this particular column of my aggregation table can have values only from this dictionary-table', so I would type words, and it will just add id's from dictionary-table instead. You know, like a relationships in database.
Except that in the end I want it to be a plain sqlite database, and sqlite doesn't support relationships.
So what I want is some cool high-level GUI tool that will simplify the way I input data to database, and will help me to maintain the data when DB grows in future, but also be able to export to a simple SQLite.
I tried: SQliteBrowser, SqliteAdmin, Libreoffice Base + Sqlite ODBC. Neither supports what I want.
Anything else worth checking out?
How about PhpLiteAdmin? - https://code.google.com/p/phpliteadmin/
It allows you to directly add/modify the structure and data of an sqlite database but also allows import and export of tables, structure, indexes, and data (SQL, CSV). If you're dealing with thousands of entries then this may be the important feature for whatever tool you use.
There's no installation and it's open-source
you said
...be a plain sqlite database, and sqlite doesn't support relationships.
But sqlite supports relationships. By default it is disabled. you can enable it with
sqlite> PRAGMA foreign_keys = ON;
now you can code your requirement by having proper foreign key.
you said
I will add data to dictionary-tables,
Instead of multiple dictionary tables, just have one dictionary table and add one more column in it as dictionary_name
your aggregate table can simply have foreign key referring the dictionary table

ADO.net to Lightswitch issue

I've deploy my database through ADO.net Entity Data Model by executing its diagram output query against my pre-made online database.
My database contains Only Lightswitch supported relations, One-Many, ZeroOne-Many & One-ZeroOne.
Finally, Attaching my database to my Lightswitch application as an external database and I was shocked by its result.
Lightswitch converts ALL One-ZeroOne relations to One-Many relations!
I suspect everything, retry tens of times trying to figure this strange issue out with no good news!
Question:
Why Lightswitch converts ALL One-ZeroOne relations to One-Many relations? Inconsistency!
Unless this is a bug, it would depend on the nullablility of your PK/FK. LightSwitch will not allow 0-1 for any key property that is not nullable.
Finally, I've solved it by a brute-force-like trials :S
Solution : ( Please don't ask me a WHY question as IDK will be my answer )
After adding a One-to-ZeroOne Relation you might have one or two Navigation Properties added to associated tables, but
You MUST add a Foreign Key as Scalar Property to the ZeroOne Table with Same type & true Nullable properties.
You MUST adjust the Residential Constrain for the association by double clicking the association line itself and make the FK in the ZeroOne Table dependent on the One table Key.
Generate the database script, execute it and Don't Update LightSwitch data source, Delete data source & Attach it again instead as it won't update relations correctly!

What do each of the keys in the $_schema var in models do in CakePHP?

The CakePHP cookbook presents the following (http://book.cakephp.org/2.0/en/models/model-attributes.html#schema):
Contains metadata describing the model’s database table fields. Each field is described by:
name
type (integer, string, datetime, etc.)
null
default value
length
Some of these are self-explanatory, but here are my questions:
Name - what's the purpose of this? Is the cakebook just unclearly saying that the other values will be in an array stored under the name of the field, or is this a key that can give a different name, and what would it be for?
Type - I understand what type is, but could someone give me a full list of the options? Hard to say what it is if I don't know what my options are. Are they based on typical database types, or form types, or what?
Null - Is this the same as the not null option of a database? Basically just requiring a value or throwing an error?
I would like to write out each of my table's schemas for various reasons, but I'm a little stuck because of these questions.
Thank you for your help!
you can find most of the answers to your questions yourself.
either you debug the returned data from
$this->Model->schema();
which contains all the fields above.
Or you use the cake shell to create/dump a schema file in /Config/Schema:
cake schema generate
this way you can look at what cake creates.
So if you create a dummy table "foobars" with all kind of field types you will have a full schema reference out of the box for the current cake version you are using. Also you will see your database reflected as cake sees it. meaning: if you set one field to "default not null", the other as "default null" you will see what "null" means. And what type of the database matches what type in cake.
And yes, name is the fieldname. it should be the array key itself, though.

Single column/primary key only table for referential integrity?

Maybe i'm going about this wrong but my working on a database design for one of my projects.
I have an entity with a classification column which groups up entities into convenient categories for the user. These classifications are predefined and unchangeable by the user (at least thats the current design).
I'm trying to decide if I should have a 'EntityClassification' table which contains simply an 'Id' column as the primary key with no other information in order to have an enforced relationship between the Entity:Classification -> EntityClassification:Id.
I don't plan to have a name/description column in EntityClassification since my current thought is that I'll need to support localization of these pre-defined names which will be done with static string table like resource files downloaded to the client based on their country/language. There really isn't any other data which is associated with this EntityClassfication that I would want and a table seems like it might be an overkill?
Is this common/recommend practice for this type of problem? We're using SQL Server 2008 and don't have an enum datatype for the database which would seem to be really what i'm trying to achieve.
You should have the table with name and description not only for end user display, but internal documentation so when the users say 'my query based on this classification doesn't work!' someone hired in the future will know which ID they're talking about.
Do you just want to ensure that the values in Entity:Classification are restricted to your pre-determined list? If so a check constraint might be what you need.
Such constraints aren't as flexible as foreign keys: to alter the checked values we have to drop and recreate the constraint, but then you say there are no plans to change the values so that shouldn't matter.

Entity Framework Foreign Key Mapped to Same Table

This is not a duplicate of this post although the title is very similar. I am using EF4 with MSSQL Express 2008 R2 on VS2010.
A simplified version of my schema is as follows:
Table [Team]:
Id (PK)
Member1
Member2
Table [Person]:
Id (PK)
FirstName
[Team].Member1 and [Team].Member2 are foreign keys pointing to [Person].Id.
When generating the .edmx via VS2010, the navigation properties under [Team] become "Person" and "Person1" despite giving distinct names to the FKs inside SQLServer.
Is it possible to force the .edmx generator to recognize my FK names in SQL Server? I'd like these names to be Member1Person and Member2Person, for example, so I don't have to manually rename them by hand. If not, what is the preferred way to redesign the tables/FKs to bypass this altogether? Thank you.
I have had a similar issue but I believe the answer to the question is you simply have to rename the Navagation property to what you want. The Entity Framwork designer will always keep you changes to the property names on the Conceptual side of things.

Resources