@aceitadev/adatabase 0.5.8 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -45,7 +45,7 @@ class SchemaManager {
45
45
  if (this.changes.size === 0) {
46
46
  return;
47
47
  }
48
- console.log("Database updated:");
48
+ console.log("Database Updated:");
49
49
  const tableEntries = Array.from(this.changes.entries());
50
50
  tableEntries.forEach(([table, changes], tableIndex) => {
51
51
  const isLastTable = tableIndex === tableEntries.length - 1;
@@ -56,7 +56,7 @@ class SchemaManager {
56
56
  console.log(`${tablePrefix} ${table}`);
57
57
  changes.forEach((change, changeIndex) => {
58
58
  const isLastChange = changeIndex === changes.length - 1;
59
- const changeLinePrefix = isLastTable ? " " : "│ ";
59
+ const changeLinePrefix = isLastTable ? " " : "│ ";
60
60
  const changeConnector = isLastChange ? "└─" : "├─";
61
61
  console.log(`${changeLinePrefix} ${changeConnector} ${change}`);
62
62
  });
@@ -101,7 +101,6 @@ class SchemaManager {
101
101
  const conn = yield (0, Database_1.getConnection)();
102
102
  try {
103
103
  for (const [col, type] of Object.entries(desired)) {
104
- // Se a coluna for a chave primária, pule a verificação para evitar o erro.
105
104
  if (col === primaryKey) {
106
105
  continue;
107
106
  }
@@ -111,9 +110,14 @@ class SchemaManager {
111
110
  tableChanges.push(`+ ${col} (adicionado)`);
112
111
  }
113
112
  else {
114
- const normalize = (t) => t.toLowerCase().replace(/\s/g, '').replace('character varying', 'varchar');
113
+ // Função de normalização aprimorada para ignorar diferenças irrelevantes
114
+ const normalize = (t) => {
115
+ let normalized = t.toLowerCase().replace(/\s/g, '').replace('character varying', 'varchar');
116
+ // Remove o comprimento de exibição de tipos inteiros, ex: int(11) -> int
117
+ normalized = normalized.replace(/^(int|integer|tinyint|smallint|mediumint|bigint)\(\d+\)/, '$1');
118
+ return normalized;
119
+ };
115
120
  const existingType = normalize(existing[col]);
116
- // Compara apenas o tipo base, ignorando extras como NOT NULL
117
121
  const desiredType = normalize(type.split(' ')[0]);
118
122
  if (existingType !== desiredType) {
119
123
  const sql = `ALTER TABLE \`${table}\` MODIFY COLUMN \`${col}\` ${type};`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aceitadev/adatabase",
3
- "version": "0.5.8",
3
+ "version": "0.6.0",
4
4
  "description": "Uma biblioteca para facilitar a interação com bancos de dados MySQL e PostgreSQL em projetos TypeScript/Node.js.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",