Меню ▼

Design ⚡️ Life

Alex Buznik Logbook

Strange case with prisma foreign key error constraint failed on applicationId P2003

Hi.

Thought I should share this.
I’ve done some development on a pet project using prisma and MySQL.

I added a new model with a relation and was getting an error prisma foreign key error constraint failed on applicationId P2003 when trying to create this new model even though the code and schema looked ok.

The fix was to rename the reference field to a lower case, so it’s different from the actual model name. Probably trivial for someone, but I haven’t any explicit notes against it in the docs.

model Invoices {
  id            Int             @id @default(autoincrement())
  ...
  // works:
  application   Application     @relation(fields: [applicationId], references: [id], onDelete: NoAction, onUpdate: Cascade) 

  // does not wrk:
  Application   Application     @relation(fields: [applicationId], references: [id], onDelete: NoAction, onUpdate: Cascade) 

  applicationId Int
}

Procrastination

Sometimes, as a wood-maker, it’s hard to find time to make things for yourself.

Year of full-scale war

One year since Ukraine stands off the full-scale invasion from russia.

Some pictures that I have saved during these days. Sorry, I do not have the authors for the pics, ping me if you know who should be mentioned.

Photos:

Posters:

Reality strikes

A couple of years ago everybody was freaking out over the sick, irrational and needless violence in the fictional story of the Game of Thrones, but reality has proved to be much more harsh and much more irrational.

Pictures are not mine, collected from different sources over time.

Cool stuff of the week

Hey.

It’s been a while since the last time I’ve posted anything here.

Full-scale war was launched by russia in Ukraine. The life was kind of quirky these months.

Anyway, the company I work for, managed to continue the business, almost without changes. Some part of the team has moved out of Ukraine, but otherwise our work rhythm is back to what it was before.


Found some interesting things I wanted to share:

Simple JSON to TypeScript Converter
We are in the process of migrating to TypeScript, so this is quite handy.

You put in a bunch of JSON of your data, and get a typed interface(s) as a result: http://json2ts.com/

Simple notification system / bot for github/gitlab
(and some other services) – https://danger.systems/

I made a small demo for my team https://gitlab.com/beshur/danger/-/merge_requests/5


Help Ukraine win this war by donating to charity https://www.comebackalive.in.ua/donate

Smoke and Temperature Sensor for my 3D-printer

Sometime ago I bought an IKEA smoke sensor. It lived some time in the kitchen as expected, but then I put next to my 3D-printer that was located in the garage.

But then, it doesn’t make a lot of sense if it only fires an alarm in case of smoke, since I maybe away, so I decided to hack it into something IoT.

There are a couple of useful blog (this and that) posts that I started from.

It took quite a while to just follow the advice given there and to solder properly ground connection to the CS2105G0-S12 chip (that people suggest is actually MC145012). Anyway my project is a bit simpler in a way – the wi-fi module (Wemos D1 mini) is constantly powered with USB and feeds data every second to Blynk.

One other issue I had was that smoke sensor IC is using 9V for power and signals, so it had to be stepped down. With invaluable help from my former colleague Mich, I did it using an NPN transistor and it works pretty smoothly.

Printed a special case for it to fit all the components.

In case of smoke the Blynk app will send me a notification. Later on, it will also turn off the smart socket that the printer is powered with.

Arduino source is on Github. I will try to put some more details and the scheme later.

I have no illusions that this thingy is pretty weak in terms of safety and reliability – there are too many things to break in case of a real fire – but it was an important learning project for me.

Bought a 3D printer!

Finally I bought a 3D printer – an almost complete kit for popular Creality Ender 3.

It happened to be a decent printer that produces fairly quality prints.

Some test prints:

Some things I tried to model:

Created a new instagram account and post stuff related to 3d-printing and general DIY: @shu.makes

The journey continues!

TicTacToe as a coding test task

One of my most fun interviews was with DI.FM in 2018.

On the coding lab I was asked to make a tic-tac-toe game in one hour.
I was later given some time to refine it afterwards, but the core thing was done in time and it was interesting.

Play with someone.

Uploaded source to github.

Repurposed an old iPad as a home status screen

Here is my new small project – TableStatus/StenGazeta (Daybook.buznik.family as of November 2020).

I have been thinking about creating some kind of a status screen for my home and family for a long time.

Our friends have recently donated an old iPad 2 to us. It runs iOS 9.3.5, so I can barely install a handful of apps from Appstore. That’s where this idea started.

I could never gather all the details until this Christmas, when I got some time and slapped together a preact web app.

Demo

Features

It’s a web page that displays widgets:

  • daily weather – temperature, conditions and humidity, and lunar phase
  • agenda – events from our shared calendar for the day (events are also togglable, so you can use it as wishlist)
  • photoslider with pictures from selected google photos albums
  • simple notes

Nothing particularly interesting about those – mostly leveraging a couple of APIs.
I used openweathermap.org for weather, and Google APIs to retrieve the calendar and photos.

The notes are just a text area that stores value in localStorage, not synced across sessions.

Usage

You can just visit Daybook page on your iPad and it will work.

In order for Calendars and Photos to work, you need to login with your Google account.

Source and Setting Up

Right now, I’m happy with the result, though I’m adding some ideas as enchancements on Github.

Source code on Github

It has a readme which has some notes on the API keys that you need to get and some other vars to set up.

The project is build with webpack and can be hosted on any kind of hosting. I use Netlify for it.

You can set up one for youself, too.

Anyway, let me know if you’d like to use it, but it lacks something via this form.

A note to React gurus and beginners

The project is definitely not to show off my React skills, rather the opposite – I wanted to slap some stuff together in a very limited timeframe and also to try preact.

Also if you are a beginner and want to learn by its code – it’s not the best specimen.

preact

I wanted to go really minimal and was lured by preact’s promise of 3kb gzipped size.

However I ended using the preact CLI to create the project boilerplate together will the webpack and compilers and other stuff, and 260Mb node_modules.

Also tried to start with React Native, but its toolchain is still not clear to me. Ran into a couple of issues with the suggested solutions as “reinstall all your node_modules and cocoa pods”, not cool.

diPlayer – Raspberry Pi-based player for DI.FM

This is a desktop player for DI.FM that I made for the 20-year anniversary.

I gathered a lof of experience during this proejct:

  • learned how to solder (again)
  • familliarised myself with Python
  • wrote and debugged firmware for an Arduino Nano
  • learned to model in Fusion 360
  • found out that 3-d printing don’t happen right on the first time

Details

Desktop player based on Raspberry Pi, that can play DI.FM channels (IceCast streams to be exact).

It is controlled with photoslides frames that have NFC-stickers on them, the stickers point to certain channels.

The player can also play other sources like Spotify, Google Play Music, Soma.fm thanks to MusicBox software.

It has a physical Play/Pause button, volume knob and a small screen that displays current track. Sound output is through audiojack or HDMI (Raspberry Pi standard).

(more…)

Spelling error report

The following text will be sent to our editors: