This update was a very frustrating yet informing one. After writing my initial post several days ago, my next step was to get it up and hosted. Here's how that went:
Netlify
A few months ago I had been following a tutorial for some frontend stuff out of curiosity, and at the end of that course it showed how to deploy a super basic html+css site on Netlify. While going to deploy HIBTB, I figured I'd use the site I had at least seen before, not considering how a rails app would be very different when it comes to actually getting it up and running. After struggling through several failed attempts at launching - with no real feedback from Netlify about what I did wrong - I decided it was probably not the best place to do it. I was hesitant to move away from it initially as I had already purchased the domain through them, but at the suggestion of another on the work dev team W, I decided to try fly.io.
Fly
Armed only with the knowledge that Netlify didn't like me and a link to their docs sent by W, I eagerly signed up for Fly. After messing with some config settings, I reached a point where I got it to launch. In my head, I was on top of the world. I deployed my first (albeit basic) website! I quickly went to look at it and discovered a problem: The static html was showing, but the post I had put in the database wasn't. Seeing that instantly made me realize the database was the issue, so I felt pretty good about my odds. Around this time it was time to go to a trunk-or-treat thing near our house with the kids. After completing the nights activities, I returned to my silly, beloved little app and set to work on fixing the database.
Fixing the Database -> Breaking Everything
Between Google and Perplexity, I thought I knew how to solve the problem, so I set to work. I changed some things in my fly.toml and database.yml files, pushed them up, and anxiously watched my new build try to start up. 'Deployment failed.' Okay, well, obviously I did something wrong. I dug back through all the files, adjusted something, merged another commit, 'Deployment failed.' At this point, my excitement started to turn into worry. 'Deployment failed.' 'Deployment failed.' 'Deployment failed.' 'Deployment failed.' 'Deployment failed.' My heart began to sink.
One of the hardest parts about ADHD is emotional regulation. I was tired, my messed up knee was killing me, parenting had worn me out, life was stressing me. All I wanted at this point was to get back to having something up that I could see. 'Deployment failed.' 'Deployment failed.' 'Deployment failed.' At this point I was full on frustrated. Why did all these little tweaks to address what the logs said were wrong keep failing? 'Deployment failed.' 'Deployment failed.' That's when I decided I would just revert back to the previous version that had passed. 'Deployment failed.' Fine, I'll just scrap all the config files and start over, doing what I did the first time and delete the app in Fly and just start over. 'Deployment failed.' 'Deployment failed.'
Another of the hardest parts of ADHD is letting things go, thought that's probably tied in with the above point. At this point I had gone from feeling like I climbed Mount Everest to feeling like I fell down the Mariana Trench. I felt dumb because I had messed with it so much I took a thing I had JUST built and broke it, then failed over twenty times to fix it. I had deleted both the Github repo and the app on Fly, and decided I needed to put it down for the night and come back to it as I was too frustrated to think logically about the problems I was facing. I went to bed more than a little confused and let down, but tried to put it out of my mind so I could start fresh.
Recollection with fresh eyes
When I woke up the next morning, I immediately started thinking about it again. I had a working site at some point, but the database wasn't showing so lets start there. I got the kids settled, wife had left for work, and I sat down to start looking into the problem. My first thought was to look up how to connect a sqlite database to Fly, where I quickly discovered that Fly really doesn't like sqlite and prefers you use postgres. I had intended to shift to postgres anyways but wanted to start the most basic way possible as the spirit of this project is for it to grow as I learned. I made the decision to go ahead and make this change, as I'd rather 'skip' a step and have a working page to put it on rather than fret over forcing Fly to do it. So I started from the beginning
`rails new hibtb -d=postgresql`
I got to work on redoing the work I had done, which to be fair wasn't much. After I got that going and had dev and test databases working, I decided I would put it down and take a break for a day before coming back to the deployment troubles. I had everything back to where I could see things on the dev server, so that was good enough to feel like I 'caught up' to where I was before. Then there comes the whole 'not being able to let things go' thing I mentioned before. While I stayed true to not opening the terminal or writing any more code the rest of the day, I got to thinking about how databases really work. 'Alright, there's a dev db for me to use while building, a test db for if I decided to put it up on a staging site, and there's production db for actual live informa-' Then it hit me. You see, when you add something to your database via the terminal then rails s it to pull it up on localhost:3000, that's the dev db. So nothing I put in here would show when the site is live anyways. Cool, that answers one thing. Then I think some more and realize - if the production database had to do with the code living on my computer, it would break as soon as I turned my computer off. That's why Fly offers postgres servers you can use to store data
Then it really clicked. I had a feeling I knew what I needed to do. I needed to get the site back up, but during deployment attach it to a pg database provided by Fly. Then I needed to go into the production console once it was live and insert the post so that it would show on the page.
'Deployment successful.'
After anxiously checking on a few things, I finally attempted this today. I tested that I could still see my test entries on localhost and saw they were fine so I signed in to Fly. I made sure it was wiped clean, no machines running, no dbs sitting there, nothing. Slowly, I pulled up the terminal. fly launch. I'm asked if I want to change the default configuration, so I go in and set the postgres server to the smallest I could get (it is basic after all), and stared at the 'Done' button for far longer than I should have. Finally I clicked it. Instantly, my terminal starts running through the process. It spins up the database - success. It spins up the app - success. It attaches the database to the app - success. It tries to push the app and database up to deployed - a bunch of text starts flying through. 'Waiting for machine status: new'. My heart starts pounding, though I'm cautious not to get too excited. There's no way this works on my first fresh attempt, right?
Wrong.
'Successfully deployed, check out your app here!' I click over into my browser and load the page. What pulls up almost stops my racing heart completely - the HTML elements. I have officially returned to the state I was at two agonizingly frustrating days ago. I return to the terminal, and after several failed attempts at figuring out the command I manage to get to the production console and put my post into the live database. Success. I reload the page, holding my breath so I don't breathe 'broken' back into it. Suddenly, there's much more than just the HTML elements - there's my post. My first ever HIBTB post, on the live website, and I did that. No one told me how to fix it, W and R only gave me some basic information about how databases work. But I couldn't think about any of that at the moment, because I. Did. It. Before running to tell those in the know, I waited for a few hours to make sure nothing broke. When I refreshed the page and it was still there right at lunch time, I knew I had won. A short bit of learning about how to do DNS settings (which I still need to fix something on, hence the absence of www. in the address) and some more insight from W later, I had attached my domain I purchased to the site. After an hour, the DNS change took effect and I was golden.
Conclusion
So, what did I learn? Deploying a website and database (well, really mostly the database) isn't as easy as clicking a button. I also was reminded that when I get frustrated, I'm only going to break it more and I won't always be able to start from scratch quickly - so putting it down for a day is okay. There's no pressure or time limit to this, only the goal to learn so I can take my time. There were highs and there were lows, but all in all it is part of the process. There WILL be bugs, there WILL be things that take a while to figure out, there WILL be times that I'm doing more harm than good by bashing my head against it. But I also learned that I CAN do it. I think that's the real lesson here. I may not know much in the grand scheme of things, but I CAN deploy a website and I CAN attach it to a postgres database.
Here's the part where I tell you I honestly have no idea what's coming in the next update. I do know that my eventual success has me in the mood to write more code, so I don't think it'll be very long before you hear from me again. As always, thank you for joining me on this journey, and you can head over to github.com/myrolorin/HIBTB to open an issue if you have any suggestions or challenges for me. I'll see you soon.