spacedeck / spacedeck-open

Spacedeck, a web based, real time, collaborative whiteboard application with rich media support
GNU Affero General Public License v3.0
1.01k stars 243 forks source link

Wrong data type used for artifact.shape_svg #113

Closed ratulSharker closed 3 years ago

ratulSharker commented 3 years ago

What i was doing ?

Recently i was working on porting spacedeck-open from sqlite to Mysql.

I changed the models > db.js

const sequelize = new Sequelize('opendeck', 'root', 'secret', {
  host: 'localhost',
  dialect: 'mysql',

  pool: {
    max: 10,
    min: 0,
    acquire: 30000,
    idle: 10000
  },

  // http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
  operatorsAliases: false
});

Doing this i can successfully connect to database and signup and login into the Spacedeck-open.

Problem i was facing:

But in the artifact sequelize model i found follwing

Artifact: sequelize.define('artifact', {
    // removed other fields for simplicity
    shape_svg: Sequelize.STRING, // <-- which generates VARCHAR(255)
  }),

this shape_svg property type generated into VARCHAR(255) in Mysql. It generates svg xml which can be greater than 255 character.

Solution:

Changing the datatype to following solved my issue.

Artifact: sequelize.define('artifact', {
    // removed other fields for simplicity
    shape_svg: Sequelize.TEXT,
  }),

Further investigation:

I was wondering what data type SQLite was generating for Sequelize.STRING. It was generating VARCHAR(255) for shape_svg. Even the following svg xml was stored inside the shape_svg column.

<svg xmlns='http://www.w3.org/2000/svg' width='400' height='200' style='margin-left:0px;margin-top:0px;stroke-width:0;stroke:#ffffff;fill:rgba(241,196,15,255);'><path d='M69.47424,195.46884 c0,0,-69.47424,13.58084,-69.47424,-71.93003999999999 c0,-36.64808,76.42008,-54.97212,76.42008,-18.326 c0,0,-13.89168,-106.7416,104.21136,-105.19712 C284.8428,1.37984,270.94716,68.56667999999999,270.94716,68.56667999999999 S396,50.24264,396,141.86284 c0,54.97212,-83.36988000000001,53.60796,-83.36988000000001,53.60796 z '/></svg>

It's length was 519. How it is possible that VARCHAR(255) storing a 519 length string ?

From SQLite FAQ i came to know that

(9) What is the maximum size of a VARCHAR in SQLite?

SQLite does not enforce the length of a VARCHAR. You can declare a VARCHAR(10) and SQLite will be happy to store a 500-million character string there. And it will keep all 500-million characters intact. Your content is never truncated. SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT", regardless of the value of N.

That is why spacedeck-open running on SQLite facing no such issue.

I will be pleased to put a pull request resolving this issue.

mntmn commented 3 years ago

Thanks, well spotted. Please make a PR.

mntmn commented 3 years ago

Thanks, this is fixed now.