title,body,link,tags,view_count,is_answered,score,answer_count
Cypress SQL database testing - How to setup cypress.config file?,"<p>I would like to test using a database in SQL. I have SqlWorkbench and I have added mysql in my package file.</p>
<p>I get this error when trying to run Cypress SyntaxError: Unexpected token 'export'</p>
<p>Code in cypress.config.ts. (My local files have data in the defineConfig)</p>
<pre><code>import { defineConfig } from &quot;cypress&quot;;
import mysql from 'mysql';

function queryTestDB(query,config) {
  const connection = mysql.createConnection(config.env.db)

  connection.connect()
  return new Promise((resolve, reject) =&gt; {
    connection.query(query, (error, results) =&gt; {
      if (error) {
        return reject(error)
      }
      connection.end()
      return resolve(results)
    })
  })
}

export default defineConfig({
  projectId: '...',
  env: {
    db: {
      host: '...',
      user: '...',
      password: '...',
      database: '...',
    }
  },
  e2e: {
    baseUrl: 'http://localhost...',
    setupNodeEvents(on, config) {
      on('task', {
        queryDB(query) {
          return queryTestDB(query,config)
        }
      })
    }
  },
});
</code></pre>
",https://stackoverflow.com/questions/75675600/cypress-sql-database-testing-how-to-setup-cypress-config-file,"['typescript', 'cypress']",149,True,1,1
Docker Docs&#39; Get Started Guide: Got mysql:3306 Timeout Using Docker Compose,"<p>I've just started learning docker through the official Docker docs. I got an error that I can't solve at Part 8: Use Docker Compose (<a href=""https://docs.docker.com/get-started/08_using_compose/"" rel=""nofollow noreferrer"">https://docs.docker.com/get-started/08_using_compose/</a>). The error is as follows.</p>
<p><strong>docker-compose.yml</strong></p>
<pre><code>services:
    app:
        image: node:18-alpine
        command: sh -c &quot;yarn install &amp;&amp; yarn run dev&quot;
        ports:
            - 3000:3000
        working_dir: /app
        volumes:
            - ./:/app
        environment:
            MYSQL_HOST: mysql
            MYSQL_USER: root
            MYSQL_PASSWORD: secret
            MYSQL_DB: todos

    mysql:
        image: mysql:8.0
        volumes:
            - todo-mysql-data:/var/lib/mysql
        environment:
            MYSQL_ROOT_PASSWORD: secret
            MYSQL_DATABASE: todos

volumes:
    todo-mysql-data:

</code></pre>
<p><code>docker compose logs -f</code></p>
<pre><code>app-mysql-1  | 2023-05-08 08:54:16+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
app-mysql-1  | 2023-05-08 08:54:17+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
app-app-1    | yarn install v1.22.19
app-mysql-1  | 2023-05-08 08:54:17+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.33-1.el8 started.
app-mysql-1  | 2023-05-08 08:54:18+00:00 [Note] [Entrypoint]: Initializing database files
app-mysql-1  | 2023-05-08T08:54:18.067167Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
app-mysql-1  | 2023-05-08T08:54:18.069607Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.33) initializing of server in progress as process 80
app-mysql-1  | 2023-05-08T08:54:18.131879Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
app-app-1    | [1/4] Resolving packages...
app-app-1    | success Already up-to-date.
app-app-1    | Done in 1.46s.
app-app-1    | yarn run v1.22.19
app-app-1    | $ nodemon src/index.js
app-app-1    | [nodemon] 2.0.20
app-app-1    | [nodemon] to restart at any time, enter `rs`
app-app-1    | [nodemon] watching path(s): *.*
app-app-1    | [nodemon] watching extensions: js,mjs,json
app-app-1    | [nodemon] starting `node src/index.js`
app-mysql-1  | 2023-05-08T08:54:42.445343Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
app-app-1    | Waiting for mysql:3306............
app-app-1    | Timeout
app-app-1    | Error: connect ECONNREFUSED 172.18.0.2:3306
app-app-1    |     at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1494:16) {
app-app-1    |   errno: -111,
app-app-1    |   code: 'ECONNREFUSED',
app-app-1    |   syscall: 'connect',
app-app-1    |   address: '172.18.0.2',
app-app-1    |   port: 3306,
app-app-1    |   fatal: true
app-app-1    | }
app-app-1    | [nodemon] app crashed - waiting for file changes before starting...
</code></pre>
<p>I've let the logs run for a while after the nodemon crashed line and the db seems to start after about 4 mins, since more logs containing &quot;temporary server started&quot; appeared. At this point, I could connect to the db successfully as well, tested through VSCode Database testing extension. This made me think the issue was the app trying to run before db is fully initialized so I looked up the internet and tried many solutions for that such as <code>wait-for-it.sh</code>, <code>restarts: always</code>, <code>healthcheck</code> and <code>depends_on</code>. But the error kept happening. More weird is that, my friend who tried the same thing by following the docs without any extra solution on his machine could run everything fine. Please help.</p>
",https://stackoverflow.com/questions/76199144/docker-docs-get-started-guide-got-mysql3306-timeout-using-docker-compose,"['mysql', 'node.js', 'docker', 'docker-compose']",32,False,0,1
Laravel 10 Unit Test does not see DB change from Artisan Command,"<p>I have an artisan command (Laravel 10) that makes a change to the user table in the database. I can confirm that the change is happening with output from the command itself, and it looks like it's actually working.</p>
<p>However, when I run the unit test, it does not see the updated database change.</p>
<h4>Unit Test</h4>
<pre><code>public function test_promote_user_command_sets_user_as_super_admin()
{
    $user = $this-&gt;createUser('guest');

    $response = $this-&gt;artisan(&quot;user:promote {$user-&gt;email}&quot;)-&gt;assertSuccessful();

    $role = Role::where('name', '=', 'Super Admin')-&gt;first();
    $this-&gt;assertDatabaseHas('users', [
        'id' =&gt; $user-&gt;id,
        'role_id' =&gt; $role-&gt;id
    ]);
}
</code></pre>
<h4>Artisan Command</h4>
<pre><code>class PromoteUserCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'user:promote {email}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Promote a user to super admin.';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $role = Role::where('name', '=', 'Super Admin')-&gt;first();        
        $user = User::where('email', '=', $this-&gt;argument('email'))-&gt;first();

        $user-&gt;role_id = $role-&gt;id;
        $user-&gt;save();
    }
}
</code></pre>
<p>When I run the test I get this output:</p>
<pre><code>  Failed asserting that a row in the table [users] matches the attributes {
    &quot;id&quot;: 1,
    &quot;role_id&quot;: 1
}.

Found similar results: [
    {
        &quot;id&quot;: 1,
        &quot;role_id&quot;: null
    }
].
</code></pre>
<p>However, if in the artisan command I run <code>dd($user)</code> after the <code>$user-&gt;save()</code> and then I run the test, I get this:</p>
<pre><code>...
  #attributes: array:9 [
    &quot;id&quot; =&gt; 1
    &quot;name&quot; =&gt; &quot;Karelle Schamberger&quot;
    &quot;email&quot; =&gt; &quot;urice@example.org&quot;
    &quot;email_verified_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;password&quot; =&gt; &quot;$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi&quot;
    &quot;remember_token&quot; =&gt; &quot;Br992xsWw9&quot;
    &quot;created_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;updated_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;role_id&quot; =&gt; 1
  ]
  #original: array:9 [
    &quot;id&quot; =&gt; 1
    &quot;name&quot; =&gt; &quot;Karelle Schamberger&quot;
    &quot;email&quot; =&gt; &quot;urice@example.org&quot;
    &quot;email_verified_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;password&quot; =&gt; &quot;$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi&quot;
    &quot;remember_token&quot; =&gt; &quot;Br992xsWw9&quot;
    &quot;created_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;updated_at&quot; =&gt; &quot;2023-03-04 18:22:36&quot;
    &quot;role_id&quot; =&gt; 1
  ]
  #changes: array:1 [
    &quot;role_id&quot; =&gt; 1
  ]
...
</code></pre>
<p>So I know that the command is being run and that it is working properly. Why does it seem that this change is reverted before the test assertion happens?</p>
<hr />
<h3>Edited to add:</h3>
<p>I also changed the command to do a DB lookup on the table after the <code>$user-&gt;save()</code> and the DB result also shows the change is in the database...</p>
<p>So the DB changes is taking place within the artisan command, but either that change is reverted or some how the unit test is not seeing the latest DB status.</p>
<p>All of my other 94+ tests that do not involve the artisan command work just fine with database testing. It is only the artisan command that is having this issue.</p>
",https://stackoverflow.com/questions/75637762/laravel-10-unit-test-does-not-see-db-change-from-artisan-command,"['php', 'laravel', 'testing', 'tdd', 'laravel-artisan']",158,True,2,3
Problem for changing UID &amp; GID on two datafiles on Unix,"<p>I wanna open two datafiles (test.mdf and testlog.ldf) on Azure Data Studio but I can't. I expose the steps that I have followed until the problem which I'm writing here.
I've moved both of files from local to docker's container for working with them on Azure Data Studio.</p>
<p>I've followed the next steps on terminal:</p>
<pre><code>&gt; docker stop NameContainer
&gt; docker cp /Users/user/Downloads/NameFile/test.mdf NameContainer:/var/opt/mssql/data/
&gt; docker cp /Users/user/Downloads/NameFile/testlog.ldf NameContainer:/var/opt/mssql/data/
&gt; docker start NameContainer
</code></pre>
<p>Now with that command lines, I have on my container both of datafiles with I wanna working on Azure Data Studio but I have the next problem. I execute my CREATE DATABASE:</p>
<pre><code>CREATE DATABASE Testing
    ON 
    (FILENAME = '/var/opt/mssql/data/test.mdf'),
    (FILENAME = '/var/opt/mssql/data/testlog.ldf')
    FOR ATTACH;
</code></pre>
<p>And Azure reports the next error message:</p>
<blockquote>
<p>Msg 3415, Level 16, State 2, Line 1<br />
Database 'Testing' cannot be upgraded because it is read-only, has read-only files or the user does not have permissions to modify some of the files. Make the database or files writeable, and rerun recovery.</p>
</blockquote>
<p>So, I open Terminal, execute <strong>ls -l</strong> and both of files have <strong>-rwxr-xr-x</strong> permissions but a different UID and GID that the rest of files in the directory:</p>
<pre class=""lang-none prettyprint-override""><code>&gt; -rwxr-xr-x 1   501 dialout  4194304 Nov  2  2008 test.mdf
&gt; -rwxr-xr-x 1   501 dialout  1048576 Nov  2  2008 testlog.ldf
&gt; -rw-r----- 1 mssql root     4653056 Feb 24 10:56 master.mdf
&gt; -rw-r----- 1 mssql root     2097152 Feb 24 11:19 mastlog.ldf
</code></pre>
<p>So I try to change that using the next:</p>
<pre><code>&gt; docker exec  -i -t NameContainer /bin/bash
&gt; cd /var/opt/mssql/data/
&gt; ls -l
&gt; chown -f mssql:root /var/opt/var/opt/mssql/data/test.mdf
&gt; chown -f mssql:root /var/opt/var/opt/mssql/data/testlog.ldf
</code></pre>
<p>But the UID and GID still are the same (501 dialout), what is the problem or what steps am I having a mistake?</p>
",https://stackoverflow.com/questions/75556070/problem-for-changing-uid-gid-on-two-datafiles-on-unix,"['sql-server', 'azure', 'docker', 'unix', 'data-files']",23,False,0,0
