Add column to table with Liquibase - spring-boot

I'm new to back-end development and currently trying to add a column to my app_user table. like below.
- changeSet:
id: 300520202335
author: Malindu De Alwis
changes:
- addColumn:
tableName: app_user
columns:
-column:
name: address
type: VARCHAR(255)
It gives this error
Caused by: org.yaml.snakeyaml.scanner.ScannerException: mapping values are not allowed here
in 'reader', line 23, column 22:
columns:
^
I use Spring boot and postgre sql. Please try to figureout the issue

I had the same issue, and I found there were 2 things wrong with the example code given on liquibase.com:
"columns" should be at the same indent as "tableName"
The whitespace between "-" and "column" mentioned by others
The example should be
changeSet:
id: addColumn-example
author: liquibase-docs
changes:
- addColumn:
tableName: person
columns:
- column:
name: middlename
type: varchar(50)
Somewhat disappointing that the official examples don't compile.

If you look at an example yaml test changelog like the one included here : https://github.com/liquibase/liquibase/blob/master/liquibase-core/src/test/resources/liquibase/parser/core/yaml/testCasesChangeLog.yaml -- you will be able to replicate an addColumn change type in yaml format that works. For example:
- changeSet:
id: using after column attribute
author: cmouttet
changes:
- addColumn:
columns:
- column:
afterColumn: firstname
name: middlename
type: varchar(50)
tableName: person
I believe #tobhai is correct though -- there is missing whitespace in - column.

I think the error results from missing whitespace between -column. Have you tried it with - column?

Related

Formatting ActiveRecord results for parsing?

I have a database with entries which I can fetch using ActiveRecord. Currently, using something like post.to_yaml yields:
!ruby/object:Post
concise_attributes:
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: id
value_before_type_cast: 1
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: user
value_before_type_cast: efy5qC5YmJNml23JowOUrlmfN0D2
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: content
value_before_type_cast: bol4
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: location
value_before_type_cast: '123'
- !ruby/object:ActiveModel::Attribute::FromDatabase
name: timestamp
value_before_type_cast: '12:00'
new_record: false
The exact collection i'm returning is as follow: record = Post.order(:timestamp).offset(15 * 0).first(15)
This returned result contains several fields which will be returned to a Flutter application. The data will populate a widget with several fields such as content, date and location, all of which is returned by the above query.
I could use a Dart library to parse the YAML, but is there a better way to condense the returned values so that only the necessary fields are shown?
As per the description shared it seems like you have data from the database and you now need to select only particular fields that needs to be shown.
As per current scenario you could use something like:
post.as_json(only: [:content, :name, :location])
Else you could modify the query you are using by using select statement for selecting specific attributes from database.
Post.select(:name, :content, :location)
Hope it helps!!

rails find_by_name getting wrong result

I'm working on a rails 2 project. I'm trying to fetch a record from tags table by using find_by_* . Its giving different result.
May I know why is this working like this?
In my model:
existing = user.tags.find_by_name(tag)
in Log:
SELECT * FROM `tags` WHERE (`tags`.`name` = 'Ror') AND (`tags`.user_id = 1) LIMIT 1
RuntimeError (#<Tag id: 980191043, user_id: 1, name: "rOr", created_at: "2014-09-09 12:18:55", updated_at: "2014-09-09 12:18:55">):
Are you using MySQL?
If so it is likely it is doing a case insensitive comparison. Whether MySQL is case sensitive is based around the field collation of the column: http://dev.mysql.com/doc/refman/5.0/en/charset-column.html

Doctrine2 + CodeIgniter and database table creation issue

I'm using Doctrine2 with codeIgniter, I've created some models in yml format. Using command line I've created the Proxies and Entities. When I'm trying to create the database tables, I'm getting the following error:
[Doctrine\ORM\Mapping\MappingException]
Invalid mapping file 'Entities.category.dcm.yml' for class
'Entities\category'.
Here's Entities.category.dcm.yml:
Entities\Category:
type: entity
table: categories
fields:
id:
type: integer
id: true
generator:
strategy: AUTO
name:
type: string
length: 50
nullable: false
description:
type: string
length: 255
First of all, check the paths configured for your entities and for the YML mapping driver.
Also, your Entities.category.dcm.yml contains mappings for Entities\Category, and not Entities\category.
As you can see in the base FileDriver Doctrine ORM does direct matching for mapped classes, and applies no normalization on the class names. Category and category are therefore different.

YAML syntax for unique columns in Propel

As far as I know to make a column unique the structure below should be used:
database:
table_name:
column_name: { ..., index: unique }
I want to make multiple columns unique at once. How am I going to do this?
Thanks in advance.
AFAIK you cannot do that. Oh, and you should use the XML format instead of the YAML one.
EDIT: actually, there is a possibility to handle that in YAML:
Article:
indexes:
my_index: [title(10), user_id]
See this fixtures file from the plugin for more information.
If you're talking about a composite unique key (e.g., having a unique key based on the combination of multiple fields in the same table), here's how you'd do that :
<unique name="document-version-index">
<unique-column name="document_id" />
<unique-column name="version_id" />
</unique>
As for the yaml syntax, I know you can do it in doctrine (see below), but not sure exactly of the propel format.
Doctrine format (--> from stackoverflow thread: primary key + composite primary key causing problem ) :
Pet:
columns:
pet_name: {type: string(32)}
owner_id: {type: integer}
indexes:
owner_name:
fields: [pet_name, owner_id]
type: unique

In Symfony with the Doctrine ORM how do you default autoincrement columns to integer and not bigint?

It seems that in Symfony 1.4 with Doctrine that when generating auto-increment columns (id) it defaults to bigint. This seems like total overkill and I would just like to default it to an integer instead.
The following produces a primary key column named id that is a bigint
JobeetCategory:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true, unique: true }
Is there a configuration file I can change this in. I don't want to have to manually add the id column as an integer.
Not that I'm aware of, no.
If you do end up manually adding the id columns into your schema you can specify their type as integer(4) to create a MySQL int field: http://www.symfony-project.org/doctrine/1_2/en/04-Schema-Files#chapter_04_data_types.

Resources